API Connector
Overviewโ
The API Connector is a flexible and user-friendly utility designed to facilitate the integration of APIs within our products ACE Search and Chat. It abstracts the complexities of HTTP requests, authentication, and error handling, allowing users to fetch data from APIs and convert the responses into knowledge objects seamlessly.
Table of Contentsโ
- Overview
- Table of Contents
- Key Features
- User Guide
- Working with API Responses
- Setting Up Recurring API Calls
- Best Practices
- Conclusion
Key Featuresโ
- Automatic Handling of Authentication: Supports Bearer tokens and Basic Authentication based on provided inputs
- Flexible Input Handling: Safely parses JSON strings for headers and body
- Error Handling: Captures and raises detailed exceptions for common HTTP errors
- Integration: Converts API responses into knowledge objects with relevant metadata
User Guideโ
Initializationโ
To create an instance of the API Connector, you need to provide various parameters that define how the API request should be made. Below is a guide on how to fill out these details.
Parametersโ
Endpoint (str, required):
- The URL of the API endpoint you want to access
Authentication Token (str, optional):
- The authentication token (e.g., Bearer token or custom token). If provided, it will be included in the Authorization header of the request
Username (str, optional):
- The username for Basic Authentication. Must be provided together with the password
Password (str, optional):
- The password for Basic Authentication. Must be provided together with the username
Headers (str, optional):
- HTTP headers to be included in the request. This can be provided as a JSON string or as a dictionary. If you use a JSON string, it will be automatically parsed into a dictionary
Params (str, optional):
- Query parameters for the request. This can be provided as a JSON string or as a dictionary
Body (str, optional):
- The body of the request, typically used for POST requests. This can be provided as a JSON string or as a dictionary
Method (drop-down selection, required):
- The HTTP method to use for the request (e.g., GET, POST). The default is GET
Timeout (int, optional):
- The timeout duration for the request in seconds. If not provided, the request will use the default timeout
Proxies (str, optional):
- Proxy servers to route the request through. This can be provided as a JSON string
Verify (str, optional):
- Whether to verify SSL certificates. This can be provided as a string (
True
orFalse
)
- Whether to verify SSL certificates. This can be provided as a string (
Cookies (str, optional):
- Cookies to include in the request. This can be provided as a JSON string or as a dictionary
Example Usageโ
Note:
- Please use double quotes inside a dictionary format, see Headers, Body etc below.
- Please fill up only necessary API parameters and leave other parameters blank.
Here's an example of how you might fill in the parameters:
Endpoint:
https://api.example.com/data
Authentication Token:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Username:
john_doe
Password:
sk-12dts23
Headers:
{"Content-Type": "application/json"}
Parameters:
{"q": "search_term", "limit": 10}
Body:
{"data": "What is AI?"}
Method:
POST
Timeout:
30
Proxies:
{"http": "http://10.10.1.10:3128", "https": "http://10.10.1.10:1080"}
SSL Verification/Verify:
False
Cookies:
{"session_id": "abc123"}
Working with API Responsesโ
The API Connector processes the responses automatically and converts them into knowledge objects that can be searched and queried through the ACE Search and Chat interfaces. Here's how different API response formats are handled:
JSON Responsesโ
JSON responses are parsed automatically and their structure is preserved in the knowledge objects.
Text Responsesโ
Plain text responses are stored as-is in the knowledge objects.
Error Handlingโ
The connector includes comprehensive error handling:
Error Type | Description |
---|---|
Connection Errors | Issues connecting to the API endpoint |
Timeout Errors | Request exceeded the specified timeout |
Authentication Errors | Issues with credentials or tokens |
Status Code Errors | Non-200 status codes from the API |
Setting Up Recurring API Callsโ
To keep your API data up-to-date, you can configure recurring API calls:
- Enable the recurring option when setting up the connector
- Set the frequency (hourly, daily, weekly)
- Specify the interval value
This ensures that your knowledge base always contains the most recent data from the API source.
Best Practicesโ
- Test First: Always test your API configuration with a simple request before setting up recurring calls
- Minimize Payload: Only request the data you need to improve performance
- Handle Rate Limits: Be aware of API rate limits and schedule accordingly
- Secure Credentials: Use secure methods to store API credentials
- Review Response Structure: Understand the API response structure for effective querying
Conclusionโ
The API Connector is designed to streamline the process of making API requests and integrating their responses within the platform products ACE Search and Chat. By following this user guide, you can easily configure and use the connector to interact with various APIs, regardless of the authentication method or request details.