Hi ,
I try call a external api(third party) in mi workflow using custom code, but its not working.
I get this message:
“ERROR Unhandled Promise Rejection”
Would it be possible to make an external call for this functionality?
Thanks
Hi ,
I try call a external api(third party) in mi workflow using custom code, but its not working.
I get this message:
“ERROR Unhandled Promise Rejection”
Would it be possible to make an external call for this functionality?
Thanks
Hello @Wakira could you please provide us with more details on your custom code without any private information? This way we will be able to investigate more about it and provide you with the next steps.
I would also like to invite our top experts @LMartinez7 @bryce-corey @stefen any recommendations to @Wakira?
Thank you,
Pam
HI @PamCotton , thanks for yout attention.
The process is basically, we use a ticket as a control to monitor the delivery of one of our products, in this ticket there is a property that is the tracking code that needs to be consulted constantly in the carrier’s api and update the ticket status property.
I tried something similar to this (with changed values):
const axios = require('axios')
exports.main = (event, callback) => {
const headers = {
'Authorization': 'Token 1234',
'Content-Type': 'application/json'
};
const requestBody = {
"data": {
"df":
{ "nf" : "11222",
"tpDocumento":1
}
}
}
axios
.post(
'www.APICarrier.com/api/tracking',
requestBody,
{ headers: headers }
)
.then(response => {
console.log('Response from API: ${response.body}');
});
};
@LMartinez @bryce-corey @stefen @Pam Do you have any guidance or help on how I can resolve this?
thanks
@Wakira sounds like you need to see what the actual error is. Typically a “unhandled promise rejection” means you aren’t handling a failed response. To do that you should be able to update your axios function to something like this:
axios
.post(
'www.APICarrier.com/api/tracking',
requestBody,
{ headers: headers }
)
.then(response => {
console.log('Response from API: ${response.body}');
}).catch(function (error) {
if (error.response) {
// Request made and server responded
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
});