Discussions
Addon API request method
over 1 year ago by Ant Archer
Been following the documentation and sample addon 'showcase-addon'. This returns error message:
Invalid Response Received
No Response Received
Have done lots of debuggingg to see whats up but seems that calling this just fails:
request(options, function (error, response, body) {...
I can embed vanilla API calls in the Addon frame source using Basic and Oauth Bearer methods (below) which are successful. Ideally API calls should be made serverside so would like to know why the SDK method 'request' is not working?
const Basic = async () => {
const response = await fetch('https://api.servicem8.com/api_1.0/job/xxx-fd18-4f8e-8ca5-20169bf518cb.json', {
method: 'GET',
headers: {
'authorization': 'Basic xxxx',
'accept': 'application/json'
}
});
const myJson = await response.json();
console.log("Basic: " + JSON.stringify(myJson, null, "\t"));
}
Basic();
const Bearer = async () => {
const response = await fetch('https://api.servicem8.com/api_1.0/job/xxxx-fd18-4f8e-8ca5-20169bf518cb.json', {
method: 'GET',
headers: {
'authorization': 'Bearer 75803-apse2-xxxxxxxxxx',
'accept': 'application/json'
}
});
const myJson = await response.json();
console.log("Basic: " + JSON.stringify(myJson, null, "\t"));
}
Bearer();