Implementing API Failure Alerting Mechanism
- Getting Started
- Bot Building
- Smart Agent Chat
- Conversation Design
-
Developer Guides
Code Step Integration Static Step Integration Shopify Integration SETU Integration Exotel Integration CIBIL integration Freshdesk KMS Integration PayU Integration Zendesk Guide Integration Twilio Integration Razorpay Integration LeadSquared Integration USU(Unymira) Integration Helo(VivaConnect) Integration Salesforce KMS Integration Stripe Integration PayPal Integration CleverTap Integration Fynd Integration HubSpot Integration Magento Integration WooCommerce Integration Microsoft Dynamics 365 Integration
- Deployment
- External Agent Tool Setup
- Analytics & Reporting
- Notifications
- Commerce Plus
- Troubleshooting Guides
- Release Notes
Follow the below steps to integrate the custom haptik_requests library in Code Nodes to capture API metadata.
Import class inside custom package at top the of file as:
from haptik_code_library.haptik_requests import HaptikRequests
Create object of class HaptikRequests as haptik_requests.
haptik_requests = HaptikRequests()
Replace all occurrences of requests-library with haptik_requests.
I. Existing Implementation:
response = requests.get("https://mock.codes/200")
II. New Implementation:
response = haptik_requests.get("https://mock.codes/200")
To track timeout errors, pass timeout parameters with value in seconds.
response = haptik_requests.get(url_1, timeout=0.001)
Add decorator add_api_metadata_to_response() on top of main()function. Here, the main() function gets called automatically when code-node loads. When the response is returned from the main() function, the decorator appends API-metadata with the key to response. For example, main() contains the following:
@haptik_requests.add_api_metadata_to_response() def main(event, context): # main method body and business logic u1 = "https://mock.codes/200" u2 = "https://mock.codes/300" u3 = "https://mock.codes/400" u4 = "https://mock.codes/500" response = haptik_requests.get(u1) response = haptik_requests.get(u2) response = haptik_requests.get(u3) response = haptik_requests.get(u4) response = haptik_requests.get(u1, timeout=0.001) final_response = {} response = { 'statusCode': 200, 'body': json.dumps(final_response), 'headers': {'Content-Type': 'application/json'} } return response
As we have made 5 API-calls to 5 different URLs, metadata of each API-call will be appended as a dictionary and final api_metadata will be a list of multiple dictionaries, added in response and returned by decorator. Thus, lambda-response returned to haptik_api service without decorator on main() is:
response = { "statusCode": 200, "body": {}, "headers": { "Content-Type": "application/json" } }
This feature is supported for the below mentioned integration types:
- External API Integration
- Enterprise service level API Integration
However, this feature is not supported for internal API Integration.
Once the above mentioned changes are done, the feature needs to be enabled from the feature toggle dashboard using the business via name.