|
| [WB 22] Get a JSON response in API rest call |
| Iniciado por guest, 15,abr. 2018 18:26 - 2 respuestas |
| |
| | | |
|
| |
| Publicado el 15,abril 2018 - 18:26 |
Hi everybody, I need some help from some API rest gurus.
I cannot figure out yet how to get a Response in JSON format. This is my code now:
oRequest is httpRequest oResponse is httpResponse
oRequest..URL = "https://sandbox.api.payulatam.com/payments-api/4.0/service.cgi" oRequest..Method = httpPost oRequest..ContentType = "application/json"
// Request content oRequest..Content = [ { "test": false, "language": "en", "command": "GET_PAYMENT_METHODS", "merchant": { "apiLogin": "pRRXKOl8ikMmt9u", "apiKey": "4Vj8eK4rloUd272L48hsrarnUA" } } ]
// Runs the request and retrieves the response oResponse = HTTPSend(oRequest)
So "oResponse" has a property "ContentType" but this one it is ReadOnly... cannot be changed.
The result I get looks like this: https://www.screencast.com/t/tGWpVfUTF.
So I have tried this: vResultVar is Variant = JSONToVariant(oResponse..Content)
but I get the error message: JSONToVariant function called. Invalid JSON format
So it seems the result it is not in JSON format . I do not know how to indicate in my code that the result should be in JSON format. Should be something like "Accept: application/json" but I do not know where can I place this in my code if possible.
TIA.
Regards |
| |
| |
| | | |
|
| | |
| |
| Publicado el 15,abril 2018 - 00:11 |
I answer myself... I have read the help again and I figure out I could use this in the Header property :
oRequest..Header["Accept"] = "application/json"
and it works!! |
| |
| |
| | | |
|
| | |
| |
| Publicado el 15,abril 2018 - 19:42 |
Hi,
Looks to me that the result is XML
Json ==> Javascript Object Notation
It has the curly brackeds and stuff not the < > Tag structure
regards Allard |
| |
| |
| | | |
|
| | | | |
| | |
|