The Processor gets triggered every time something changes on a user or linked account, hence it might be the ideal candidate to call an external API and either receive additional data or trigger some actions.
How to implement it?
Since HTTP requests are asynchronous you have to return a Promise that can be awaited by the Processor. So let's have a closer look how you wrap the request client in a Promise:
First we are going to specify the options for the HTTP request (line 1), so for example if we want to call the public API from OMDb to obtain the James Bond movies, we would specify the following:
This will execute a GET request to the URL which returns a JSON response containing all James Bond movies which we could indeed process in Hull.
Next we need to create a new Promise (line 3) which we return to the Processor's main function that will wait for the completion of it.
Inside of the Promise we do a regular request with a good old-fashioned callback function (line 4).
If the request yields an error we reject the Promise (line 5). If the request is a success we resolve the Promise (line 13). What happens in between is just some extra to prevent API calls returning a string being transformed into a JSON object. You might not need this part, but it won't hurt to leave it in there.
What are known limitations?
The following section lists limitations that apply when using the processor for external API calls.
No processing of past events
Events are exactly passed once to the processor when they happen, or in other words if your code relies on past events, nothing will happen. If the code in the processor is broken or wasn't present by the time the event was recorded, you missed out on this event.
No concurrency/rate-limit restrictions
When using the processor to make API calls there are no concurrency or rate-limit restrictions that can be applied.
No long running operations
If the overall duration to run your code exceeds 20 seconds, the Processor will automatically terminate code execution. Please make sure to optimize for performance and follow the best practice section in the Processor documentation.
Learn more about using APIs with one of our hands-on examples: