© Adviser Technologies Limited t/as Adviser.ai – Privacy Policy
Using cURL
To interact with the Adviser.ai API using cURL, it’s essential to understand the basic structure of cURL commands and how to format them properly for different types of requests. Below, is an example of a cURL command, including the use of the <company_id> parameter, along with general guidance on using cURL.
Understanding cURL Syntax
A typical cURL command follows this structure:
curl [options] [URL]
- [options]: These are flags and arguments used to define the request method, headers, data, etc.
- [URL]: The endpoint URL you are making the request to.
Example cURL Command with <company_id>
Here’s an example of a cURL command that might be used to interact with the Adviser.ai API, incorporating the <company_id>
curl -X POST \
-H "Authorisation: Bearer <authentication_token>" \
-H "Content-Type: application/json" \
-d '{"company_id": "<company_id>"}' \
https://adviser.ai/api/v3/companies
Explanation
- -X POST: Specifies the HTTP method as POST.
- -H “Authorisation: Bearer <authentication_token>”: Sets the Authorisation header with the JWT token. Replace <authentication_token> with your actual token.
- -H “Content-Type: application/json”: Sets the content type to JSON, indicating that the request body is in JSON format.
- -d ‘{…}’: Sends the data in the request body. The data is a JSON string in this case, including:
- “company_id”: “<company_id>”: Specifies the company ID. Replace <company_id> with the actual ID obtained from the API.
Translating cURL to Other Tools
While cURL is a command-line tool, you can translate the examples into other environments, such as:
- Postman: Use the interface to set request methods, headers, and body.
- JavaScript (Fetch API): Use ‘fetch’ with similar parameters for method, headers, and body.
- Python (Requests library): Use the ‘requests’ module to set method, headers, and data.
General Tips
- Ensure Proper JSON Formatting: When including data in the request body (-d option), ensure that the JSON is properly formatted.
- Secure Your Token: Keep the authentication token secure and avoid exposing it publicly.
- Handling Responses: Implement proper error handling to manage various response statuses (e.g., 200 OK, 401 Unauthorized).