Retrieve variables from JSON response and store them on ASP page

Hi Guys - newbie here. Hope you can help me pls.

I have the Postman working and i am getting a JSON response. I now want to copy the code across to our website and use the response data there. I am having trouble converting the JSON variables into ASP variables that i can display to the website user, and store in the database. I am trying with the code generated by Postman in javascript / jQuery.

How should i extract, for example, the “total_amount” variable here so i can display it on the website to the customer? It shows in the my browser console, so i know it is being returned, i just dont know how to then extract it and use it within ASP

Would be brillaint if someone could help me :smiley:

Here is the code i am using currently

< html>
< body>
< h1>Hello World!
< !-- jQuery library →
< script src=“https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js”>

< script>
var settings = {
“url”: “https://seller-transaction-api.sandbox.marketplace.taxamo.com/api/v3/seller/tax/calculate”,
“method”: “POST”,
“timeout”: 0,
“headers”: {
“x-marketplace-seller-token”: “seller_token_4_removed*”,
“Content-Type”: “application/json”
},
“data”: JSON.stringify({
“transaction”: {
“currency_code”: “GBP”,
“buyer_name”: “jason k”,
“ship_to_address”: {
“address_detail”: “498 Moo 1, Lakeside, Paris”,
“postal_code”: “77110”,
“country_code”: “FR”
},
“transaction_lines”: [
{
“product_class”: “P”,
“quantity”: 1,
“description”: “Video Games Consoles and Machines”,
“amount”: “59.99”,
“custom_id”: “51315A00-DC44-408E-A575-8CE42A32AE1B”,
“import_address”: {
“country_code”: “GB”
},
“ship_from_address”: {
“building_number”: “121”,
“street_name”: “Sandy Street”,
“city”: “Yarmouth”,
“postal_code”: “YM15 8YT”,
“country_code”: “GB”
},
“product_cn_code”: “9504500000”
}
]
}
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});
< /script>
< /body>
< /html>

I don’t have exact solution but found this video which looks promising

1 Like

Thanks Sahuvikramp - that video looks useful, but i am afraid it is a bit over my head.

All i basically want to know, is what javascript i should use to receive some of the variables, once the variables are available in the console? once i have them in javascript i will be able to use them as ASP variables, but at present i am having trouble parsing the variables, so that i can use them within my script. I know this is very basic stuff, but this is the first time i have used postman and json, and i am inexperienced with javascript.

So, at present the console receives back the json in the response - how do i now grab those variables so i can display them to the user / store them ?

Here i have simplified the code… If i just wanted to receive the buyer_name variable from the json, and show it to the user, how would i do that?

< script src=“https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js”></ script>

< script>
var settings = {
“url”: “https://seller-transaction-api”,
“method”: “POST”,
“timeout”: 0,
“headers”: {
“x-marketplace-seller-token”: “seller_token_4_removed*******”,
“Content-Type”: “application/json”
},
“data”: JSON.stringify({
“transaction”: {
“currency_code”: “GBP”,
“buyer_name”: “peter”,
}
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});
</ script>

ok i worked it out - sorry for such a newbie question. javascript is tricky to learn!!

below is the code to extract the json variables i require and display them to the user

I want to show the json here

< script>
document.getElementById(“demo”).innerHTML =
"Currency - " +
response.transaction.currency_code+ “,< BR>” +
response.transaction.tax_country_codes+ ",< BR> " +
response.transaction.transaction_lines[0].description+ ",< BR> " +
response.transaction.amount+ ",< BR> " +
response.transaction.tax_amount+ ",< BR> " +
response.transaction.total_amount;
</ script>