Skill level: Intermediate
Time required: 5 minutes
This article explains how to configure a journey in Quickwork to test the execution status of an API endpoint periodically using the Try-catch business logic. By leveraging this feature, you can monitor and handle potential issues in real time, ensuring smooth workflow operations.
Prerequistes
- A Quickwork account and and familiarity with the platform's GUI.
- An API endpoint and its associated API key, configured using the API Management tool in Quickwork.
Configuring the trigger
- In the Event section, select the Scheduler by Quickwork app from the drop-down.
- Choose the trigger event New scheduled event.
- Set the Interval (for example, every 15 seconds) to determine how often the API should be tested.
- Set the date and time of your choice in the Start At field and keep the Custom payload field empty.
No authorization is required as this is an app created by Quickwork.
Using the Try-catch business logic
The Try-catch functionality is used to test whether the API endpoint functions correctly. The Try block contains the HTTP request, while the Catch block handles any exceptions.
Configuring the HTTP action under Try block
- In the Steps section, click on the Business Logic button and choose Try Catch.
- In the Try block, select HTTP from the App drop-down menu.
- Select Send new request as an action.
- Enter the name of the API in the Request name field. For example, User Login API.
- Select application/json as Request content type.
- Select POST as the Request HTTP method.
- Enter the API endpoint in the Request URL field, which is obtained from the endpoint configured in API collections under Tools > API Management in Quickwork.
- Now, scroll down to the Request headers object.
- Enter apiKey as a name in the Header name field.
- Specify the actual API key in the Header Value field, which can be obtained from the access profile in Clients under Tools > API Management in Quickwork.
Configuring the Logger action under Catch block
- Select Logger from the App drop-down menu in the Catch block.
- Select Log a Message as an action.
- Drag and drop the Error data pill from the Catch action under Data Tree Output. This logs the error for debugging purposes.
Introducing the If Else condition
The If Else condition is used to validate the API status and send appropriate notifications.
Configuring the If condition
- Click the + icon, click the Business Logic option, and select If Else Condition.
- The If Else Condition block will appear with the pre-indented action bars.
- In the Left Value field, drag and drop the Status Code data pill from the HTTP | Send new request response under Data Tree Output.
- Select the Equals condition from the drop-down menu in the Condition field.
- In the Right Value field, enter 200, indicating success.
Configuring the Slack action under If block
- Click on the Please choose an action bar under the If block.
- Choose the Slack app from the drop-down menu in the App field.
- Select the action, Send message to a channel, from the drop-down menu in the Action field.
- Click the Link account button to connect Slack with Quickwork.
- In the Channel toggle field, choose the Select from list operation and then select the channel name in which you want the message to appear. For example, mypersonal.
- Enter the message in the Message field to be displayed on your Slack channel. For example, The User Login API is working fine.
- Leave all the other input fields empty.
Configuring the Slack action under Else block
- Click on the Please choose an action bar under the Else block.
- Choose the Slack app from the drop-down menu in the App field.
- Select the action, Send message to a channel, from the drop-down menu in the Action field.
- In the Channel toggle field, choose the Select from list operation and then select the channel name in which you want the message to appear. E.g., mypersonal.
- Enter the message in the Message field to be displayed on your Slack channel. For example,
The User Login API is malfunctioned. It might have stopped functioning due to following three reasons:
1. Incorrect API endpoint.
2. Incorrect API key.
3. Bad gateway. - Leave all the other input fields as empty.
The Try-catch journey is now successfully configured. It must look like this:
Executing the journey
1. Save the changes of the journey and click Save & Start.
2. Observe the Slack notifications every 15 seconds for updates on the API status.
3. If the API fails, the error is logged in the Catch block, and a notification is sent via Slack.
By using the Try-catch block, you can effectively monitor your API endpoints, handle errors proactively, and ensure seamless workflow execution.
Comments
0 comments
Please sign in to leave a comment.