About the REST API
The SensaAI REST API provides powerful capabilities, and understanding how to interact with it is essential for users. In this guide, we'll focus on the fundamentals of using the SensaAI API, covering requests, headers, path and query parameters, and handling responses.
Making a Request
To work with the SensaAI API, you need to make HTTP requests. A typical request consists of four key components:
HTTP Method: You use standard HTTP methods like GET, POST, PUT, and DELETE to specify the type of operation you want to perform.
API Endpoint: The API endpoint is the URL that defines the resource you want to interact with. It's formed by combining the base API URL with specific path components.
Headers: Headers in your request provide metadata to the server, including information like content type and authentication credentials.
Body (for POST and PUT requests): When creating or updating data, you include a request body with information in JSON or XML format.
Leveraging Headers
Headers play a crucial role in API communication. Key headers include:
Authorization: This header provides authentication information, ensuring only authorized users can access specific SensaAI resources.
Content-Type: The "Content-Type" header informs the server about the format of the data in the request body, typically in JSON or XML.
Accept: The "Accept" header specifies the desired response format, such as JSON or XML.
User-Agent: This header informs the server about the client's identity and version.
Working with Path Parameters
Path parameters are dynamic parts of the URL prepended by colons. They enable you to specify resources or data subsets. For example, in the URL https://sensaai.com/data/v1/portfolios/:id, id
is a path parameter that can be replaced with a specific portfolio ID.
Utilizing Query Parameters
Query parameters help filter and customize the data you receive in a request. They are included in the URL after a question mark and are separated by ampersands. For instance, in the URL https://sensaai.com/data/v1/stock_ratings?limit=100&order_by=-total_rating, "limit" and "order_by" are query parameters used to limit and order the response objects.
Understanding the Response
SensaAI responds to your requests with an HTTP status code, headers, and a response body. The status code indicates the outcome of the request, such as success (200 OK) or errors (e.g., 404 Not Found, 500 Internal Server Error). The response body contains the data you requested, typically in JSON or XML format.
This guide introduces the basics of working with the SensaAI API. As you progress, you'll encounter advanced concepts like authentication, error handling, rate limiting, and pagination. Mastering these fundamentals is key to becoming proficient in using the SensaAI API for service integration, or data exploration.