This article demonstrates the functioning of HTTP as a custom action.
What you'll need:
Skill level: Intermediate
Time required: 15 minutes
- Rapid API account to access TOI APIs
- Scheduler by Quickwork as a trigger for testing purposes
- Referring to the JSONPlacceholder for open API endpoints
- Two HTTP adaptors as an action
How to mold HTTP adaptor in a working custom action
You can click the following preview to watch a video of this article or continue with the guided walk-through:
To quickly understand the functioning of HTTP w.r.t an action, let us consider a small example of fetching TOIs daily breaking news and create a post for the same. To achieve this, we will need:
- Scheduler by Quickwork
- Two HTTP adaptors
Prerequisites:
Create an account for TOIs Rapid API in order to achieve the API key for the connection. Visit here and do the same. The endpoint is GET as we need to fetch the breaking news.
HTTP Status Code | Response Operation |
200 |
OK |
201 |
CREATE |
200 , 204 |
DELETE /NO CONTENT |
404 |
NOT FOUND |
401 |
UNAUTHORIZED |
Click here to know more about the status codes.
Configuring a trigger:
- Under the Trigger section, choose the Scheduler by Quickwork app from the drop-down menu in the App field.
- Select the trigger event, New scheduled event, from the drop-down menu in the Trigger Event field.
- Set the Interval for One day as we need to fetch the breaking news on a daily basis.
- Set the date and time of your choice in the Start At field and keep the Custom Payload field empty:
Configuring the HTTP adaptor for the GET operation:
As there is no proper trail of events and actions for TOI, let's use HTTP adaptor and build a custom action that can do the operation for us:
- Under the Steps section, click on Please choose an action.
- Choose the HTTP app from the drop-down menu in the App field.
- Select the action, Send new request, from the drop-down menu in the Action field.
- In the Request name field, enter the name of the custom action to be created. E.g., Get Breaking News as per our use case.
- Select application/json as an input for the Request content type field.
- Set the Request HTTP method to
GET
: - Now go to TOIs RAPID API GET endpoint. In the Code Snippets section, look for the API URL and requested query parameter:
- Paste this URL and the parameter in the Requested URL and Requested query parameter field, respectively:
- Similarly, copy the API key from the Code Snippets section and paste it in the Request headers field:
- Copy the sample response from the Example Responses section of the TOI Rapid API:
- Paste the response in the Response body schema field.
- Select JSON in the Response content type field:
Note: The JSON schema accepts keys and values enclosed in double-quotes. - The
GET
custom action using HTTP is now successfully configured.
Configuring HTTP adaptor for the CREATE operation:
- Either copy the previously configured HTTP action or create a new one by clicking the Add a new action option.
- In the Request name field, enter the name of the custom action to be created. E.g., Add a new post as per our use case.
- Select application/json as an input for the Request content type field.
- Set the Request HTTP method to POST:
- Now go to JSONPlaceholder API, and search for Create a resource section. Copy the API URL and the sample request body as highlighted:
- Paste the URL and schema in the Request URL and Request body field, respectively:
- Now, replace the dummy data of
title
andbody
with theTest Link
data pill from the previous HTTP action output: - Scroll down the Create a resource API page and copy the sample output response:
- Paste this sample output in the Response body schema field.
- Set the Response content type to JSON:
- The
POST
custom action using HTTP is now successfully configured.
Testing the HTTP action:
Save the changes in the journey and click the Start Journey button. Check the History section. As Scheduler by Quickwork is the trigger, the first execution batch will be thrown immediately. The other execution batches will take place as per the time interval specified; i.e. after a day:
Click on the history to get the insights. Under the Steps section, click the first HTTP action bar. In the Output tab, you'll get the detailed response of the action:
Here the status code is 200
which means the action has been executed successfully and fetched the breaking news of TOI. Similarly, check the output of the second HTTP action:
Here the status code is 201
which means the action has been executed successfully and posted the breaking news of TOI.
In this way, HTTP adaptor can be used to perform theUPDATE
and DELETE
operation for the apps whose APIs are available but there is no provision to create an action or a trigger. This type of custom creations not only saves money to pay for the individual applications but also enhances the scalability of the operations getting performed.
Comments
0 comments
Please sign in to leave a comment.