im working on an API request where i GET an http.response that is an array with one json object in it. But when i try to parse it or stringify it i with this code:
var response = http.response;
try{
var json = JSON.stringify(response);
logInfo("status: " + json.status);
} catch(e) { logInfo(e); }
...I get this log anwser: status: undefined
How do I define the value? The Value is taken from a user on my webpage and can change.
This is the response i GET from the request:
[
{
"status": "DONE",
"plannedDeliveryDate": "2017-06-27",
"orderId": 2112312,
"userId": 123123
}
]
This is the rest of my GET code:
loadLibrary("cus:json3.js");
var query = xtk.queryDef.create(
<queryDef operation="select" schema={vars.targetSchema}>
<select>
<node expr="@userNumber"/>
</select>
</queryDef>
);
var res = query.ExecuteQuery();
//Buffer the auth key
var buffer = new MemoryBuffer();
buffer.fromString("username:password", "utf-8");
for each (var line in res) {
var http = new HttpClientRequest();
http.header["Authorization"] = "Basic " + buffer.toBase64(); //Basic Auth
this.baseURL = "https://url..../data?user_id=" + line.@userNumber;
http.url = this.baseURL;
http.method = "GET"; //The GET request
http.execute();
var response = http.response;
try{
var json = JSON.parse(response);
logInfo("status: " + json[0].status);
} catch(e) { logInfo(e); }
}