NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: ntnewbies on August 16, 2021, 02:09:42 AM

Title: json format in post data
Post by: ntnewbies on August 16, 2021, 02:09:42 AM
hi everyone

i am making an api call and i need to provide some json info inside the post data

postdata = st.getvalue()
posturl = 'api.testdata.payme'

net.post(posturl,postdata)


sample post data:

{
    "order" : {
        "amountOfMoney" : {
            "currencyCode" : "USD",
            "amount" : 2345
        },
        "customer" : {
            "merchantCustomerId" : "1234",
            "billingAddress" : {
                "countryCode" : "US"
            }
        }
    },
    "hostedCheckoutSpecificInput" : {
        "variant" : "testVariant",
        "locale" : "en_GB"
    }
}


usd, 234, 1234, US should be variables.
how do i put it inside string theory?

i have tried the following way but compiler gives error of misused of {{

st.setvalue('{order": {"amountOfMoney" : {"currencyCode" : "' & LOC:CurrencyCode & '","amount" : ' & LOC:Amount......&'}}'

regards,
Jason
nt11.53
c11



Title: Re: json format in post data
Post by: bshields on August 16, 2021, 04:00:10 AM
Hi Jason,

Use {{ to escape the single { in clarion code.

Don't do it for }

Regards
Bill
Title: Re: json format in post data
Post by: Bruce on August 16, 2021, 10:23:50 PM
also, there's no need to move the string from the stringtheory object, to a (possibly too small) string. ie

postdata = st.getvalue()
posturl = 'api.testdata.payme'
net.post(posturl,postdata)

can be replaced with

posturl = 'api.testdata.payme'
net.post(posturl,st)

Cheers
Bruce
Title: Re: json format in post data
Post by: ntnewbies on August 19, 2021, 10:17:25 PM
thanks bill and bruce for the tip.

will try again.


jason