I’m trying to create some functionality to retrieve data from an external API within Netcall’s code studio.
I am able to get data using rules to trigger api calls outside of the code studio, but this only works when a record has been created before triggering the api.
Is there a way in code studio to call an api without having to create a record within an object? I am also looking to populate my data object with the response payload.
There are plenty of options if you have a record, but if you don’t then you will have to use cs.curl. Syntax is a bit tricky if you have not used before, but for a GET it should just be cs.curl(url) - and the returned value contains all the status information, plus your response. For a POST, its a bit trickier, so let us know if that is the case and I will find an example.
I recommend you take a look at the Loqate Address Widget on the Appshare, that uses curl to make several api calls. Remember you will need to add the external domain to your firewall settings too.
Hi Luke,
As per Adams comment - see the example, but a quick sample:
const curl = mats.curl (url, “”,
{“verb”: “GET”, “headers” :{
“accept”: “application/json”,
“x-api-key”: widget.get_setting(“api_key”)}
}
);
if (curl.status != “success”) {
return {“status”:"Error - " + curl.status, “results”:[]};
}
The second parameter would be the body if you were doing a POST…(and changed the verb to POST)