Overriding Unified API mappings
To support use cases where some of your customers might be using a specific custom fields for a resource, you can override the Unified API mappings on an Integrated account level (applies to only that specified integrated account) or Environment level (applies to multiples integrated accounts in that environment). This will allow you to map the custom fields to the Unified API fields.
How overrides are applied
Overrides only need to specify the mappings that you need to change or add or remove.
- Truto applies the environment unified mapping overrides if available or base mapping from the Unified API to the raw API response (
remote_data
). - Overrides from the integrated account are applied to the same
remote_data
. - If there are any attributes returned from Step 2 which are also returned from Step 1, then they are overwritten. Any new attributes from Step 3 are added to the unified API response.
How to specify an override for an Integrated account
Let's take an example of HiBob, where we want to specify an override to get the date_of_birth
for an employee and adding a query_param name
.
To do this,
- Get the integrated account ID from the UI or the API where you want to apply the override.
- Make a PATCH request on the integrated account resource with the override details.
For the example mentioned before, you'll have to make the following API request,
curl --location --request PATCH 'https://api.truto.one/integrated-account/<integrated_account_id>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your_api_key>' \
--data '{
"unified_model_override": {
"hris": {
"employees": {
"list": {
"query_mapping": "{ \"fullName\": query.name }",
"response_mapping": "{ \"date_of_birth\": response.personal.shortBirthDate }"
}
}
}
}
}'
The request body contains the following,
unified_model_override
This is the object which specifies the overrideshris
This is the name of the Unified Model. You can find this on the Unified Model details page in the UI.employees
This is the resource you want to specify the override for.list
The overridden methodquery_mapping
Since we want to add query_paramname
to filter the results based on the name input, we specify thequery_mapping
which is a JSONata expression.name
is mapped to the query parameterfullName
which is accepted by the HiBob API.response_mapping
Since we want to change the response, we specify theresponse_mapping
which is a JSONata expression. Theremote_data
is present inresponse
object within the JSONata expression.
Now you can go ahead and make the LIST /unified/hris/employees API request for the integrated account and it should return you the data with date_of_birth
added to it.
How to specify an override for an Environment
Let's take an example of HiBob, where we want to specify an override to get the date_of_birth
for an employee.
To do this,
- Get the installed unified model ID by specifying the name of unified_model in the following API request
curl --location 'https://api.truto.one/environment-unified-model?unified_model.name=<unified_model_name>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your_api_key>'
- Make a PATCH request on the installed unified model resource with the override details.
For the example mentioned before, you'll have to make the following API request,
curl --location --request PATCH 'https://api.truto.one/environment-unified-model/<installed_unified_model_id>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your_api_key>' \
--data '{
"override": {
"resources": {
"employees": {
"integration_mapping": {
"hibob": {
"list": {
"query_mapping": "{ \"fullName\": query.name }",
"response_mapping": "{ \"date_of_birth\": response.personal.shortBirthDate }"
}
}
}
}
}
}
}'
The request body contains the following,
override
This is the object which specifies the overridesresources
This is the object which specifies the overrides for multiple resources.employees
This is the resource you want to specify the overrides for.integration_mapping
Since we want to add the overrides for integration, we specifyintegration_mapping
which is an object.hibob
This is the integration name you want to specify the overrides for.list
The overridden methodquery_mapping
Since we want to add query_paramname
to filter the results based on the name input, we specify thequery_mapping
which is a JSONata expression.name
is mapped to the query parameterfullName
which is accepted by the HiBob API.response_mapping
Since we want to change the response, we specify theresponse_mapping
which is a JSONata expression. Theremote_data
is present inresponse
object within the JSONata expression.
Now you can go ahead and make the LIST /unified/hris/employees API request for the integrated accounts in the environment and it should return you the data with date_of_birth
added to it for all of the integrated accounts in the specified environment.
Bindings available to use in response_mappings
Bindings are the data that are sent in the Unified API call, which can be used in response_mappings to apply overrides as per your needs.
response
This is the raw API response returned by the API call.
{
"response": {
"personal": {
"shortBirthDate": "1990-01-01"
}
}
}
rawQuery
This is the object that contains the raw query parameters sent in the Unified API request.
{
"fullName": rawQuery.name
}
query
This is the object which specified the query params after mapping is applied as needed by the integration.
{
"fullName": query.name
}
INFO
Consider an example of query_mapping where the contact resource is mapped to person_id
in the following way -
{
"person_id": rawQuery.contact.id
}
Now, if you need to map the contact resource in the response_mapping, you can do in the following ways -
{
"contact": {
"id": query.person_id
}
}
or
{
"contact": {
"id": rawQuery.contact.id
}
}
body
This is the object that contains the body sent in the Unified API request.
{
"fullName": body.name
}
context
This is the object that contains all the variables stored in your Integrated account.
{
"fullName": context.name
}
Read more about Bindings
Available JSONata bindings in mappings
JSONata methods are lifesavers while writing overrides for transforming the raw API response to the Unified API response schema. You can refer to Truto JSONata to know more about the methods supported.