API
1. Overview
Mitra allows you to integrate your data with any other system via API. This API enables you to query, insert, update, and delete table data using REST calls. Authentication is handled using a Bearer token, and data interaction is simplified through the use of filters and operators in the query parameter allParams.
2. How to Create and Manage API Keys in Mitra
Navigate to the "General Settings" screen of your project.
Locate the "API" section and create a new key.
The URL and private key will be generated automatically and are used to integrate your data with other systems.
In the API settings, you can define which tables in your database to share.
Use this private key in your API calls, following the authentication instructions.
2.1. Base URL
2.2. Authentication
Include the authorization header to make API calls:
Example:
3. Endpoints
Endpoints act as "doors" to the API, allowing access to or modification of data. Each endpoint has a specific URL and is tied to a specific action, such as fetching, submitting, updating, or deleting data.
Examples of actions via endpoints:
GET: Retrieve data (fetch task details).
POST: Submit data (add a new task).
PUT: Update data (modify details of an existing task).
DELETE: Remove data (delete a task).
3.1. Fetch Data (GET)
Retrieve data from the specified table, allowing dynamic filters via query parameters.
Endpoint:
Example:
3.1.1. Query Parameters
allParams: Dynamic parameters used as filters (status, hours_gt, etc.).
page: Results page (default: 0).
size: Number of results per page (default: 10).
sort: Column for sorting.
order: Sorting direction (ASC/DESC, default: ASC).
Example with Filters and Pagination:
3.1.2. Supported Operators in allParams
gt: Greater than (field_gt=value)
lt: Less than (field_lt=value)
gte: Greater than or equal to (field_gte=value)
lte: Less than or equal to (field_lte=value)
eq: Equal to (field=value)
neq: Not equal to (field_neq=value)
like: Contains (field_like=value)
Examples of Filters:
status=Active: Filters records with status = 'Active'.
hours_gt=4: Filters records where hours > 4.
date_lte=2023-12-31: Filters records where the date is less than or equal to 31/12/2023.
3.2. Insert Data (POST)
Insert one or more records into a table.
Endpoint:
Example:
Request Body: Send data in JSON format, with each field and value corresponding to the record to be inserted.
3.3. Update Data (PUT)
Update one or more records in a table.
Endpoint:
Example:
Request Body: The body must be a JSON containing the updated data for the table records.
3.4. Delete Data (DELETE)
Remove a record from a table using its dimensionContentId.
Endpoint:
Example:
4. Advanced Filters
Filters are applied via query parameters directly in the URL, supporting a range of operators for streamlined searches.
Examples of Filters:
Filter by equality:
Filter by greater than (gt):
Filter by less than or equal to (lte):
Combine Filters:
Filters can be combined with pagination (page), page size (size), sorting (sort), and sort direction (order).