I am running a webhook to pull and process data from seller.tools api.
I am trying to call their api with a fetch using node-fetch. When I am testing it in the cloud9 ide, to transfer it to aws-lambda, anyway I try and grab the result it comes as undefined.
In fact, if I try to call console.log
in the .then
, it doesn't even show up. Also, it doesn't even throw an error except when I try and access the result further on.
...
var order, status;
let url='https://data.seller.tools/api/v1/orders/'+orderid;
let options={
headers:{
'Authorization':apikey
}
};
try{
fetch(url,options)
.then(res => {status=res.status;order=res.json();return res;})
.then(res => console.log(res))
.catch(err => console.error("Err"+err));
}catch(err){console.log(err)}
console.log("order: "+order);
console.log("status: "+status);
console.log(order.order_id);
...
Result:
order: undefined
status: undefined
{"errorType":"TypeError","errorMessage":"Cannot read property 'order_id' of undefined"}
I've used the same url and headers, in talend api tester extension, it works as it should. but in my code, running the test in cloud9 ide, it doesn't. What is going on?