Seach

Seach

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

https://api0.mitraecp.com:2409

2.2. Authentication

Include the authorization header to make API calls:

Authorization: Bearer {private_key}
  • Example:

--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJUYXNrcyIsIlgtVGVuYW50SUQiOiJ0ZW5hbnRfNzc2NSJ9.RxBv3P1Rz6B1AQTopqANqytgPhbInJKIHVUWWGlOcV3xv6L6QTajIoF_dBWXdRNspNGKjWGJ4F2PB7YB7_VV8g'

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:

GET /{tableName}

Example:

curl --location 'https://api0.mitraecp.com:2409/rest/v0/Task?status=Active&hours_gt=4' \
--header 'Authorization: Bearer your_token_here'

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:

curl --location 'https://api0.mitraecp.com:2409/rest/v0/Task?status=Active&hours_gt=4&page=1&size=20&sort=hours&order=DESC' \
--header 'Authorization: Bearer your_token_here'

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:

POST /{tableName}

Example:

curl --location 'https://api0.mitraecp.com:2409/rest/v0/Task' \
--header 'Authorization: Bearer your_token_here' \
--header 'Content-Type: application/json' \
--data-raw '[
  {
    "Description": "Develop new feature",
    "Requester ID": "12345",
    "Source ID": "54321",
    "Hours": "10",
    "Opening Date": "2023-09-01",
    "Notes": "Delivery by the end of the month"
  }
]

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:

PUT /{tableName}

Example:

curl --location 'https://api0.mitraecp.com:2409/rest/v0/Task' \
--header 'Authorization: Bearer your_token_here' \
--header 'Content-Type: application/json' \
--data-raw '[
  {
    "Description": "Update existing feature",
    "Requester ID": "12345",
    "Source ID": "54321",
    "Hours": "12",
    "Opening Date": "2023-09-01",
    "Notes": "Early delivery"
  }
]

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:

DELETE /{tableName}/{dimensionContentId}

Example:

curl --location --request DELETE 'https://api0.mitraecp.com:2409/rest/v0/Task/12345' \
--header 'Authorization: Bearer your_token_here'

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:

curl 'https://api0.mitraecp.com:2409/rest/v0/Task?status=Active'
  • Filter by greater than (gt):

curl 'https://api0.mitraecp.com:2409/rest/v0/Task?hours_gt=4'
  • Filter by less than or equal to (lte):

curl 'https://api0.mitraecp.com:2409/rest/v0/Task?date_lte=2023-12-31'
  • Combine Filters:

curl 'https://api0.mitraecp.com:2409/rest/v0/Task?status=Active&hours_gt=4'

Filters can be combined with pagination (page), page size (size), sorting (sort), and sort direction (order).