JSONata bindings in Truto Unified APIs
Bindings are the building blocks you use in Truto Unified APIs to access and work with different parts of an API request and response. They're especially useful when writing JSONata expressions to transform data. When a JSONata expression runs, it uses these bindings to get the input data it needs. For example, query
gives you access to all query parameters in a request. In this section, we will go through the JSONata Bindings
available in Truto Unified APIs by each Mapping Type.
You can refer to Truto JSONata to know more about the JSONata methods supported.
Query Mapping
Available Bindings
query
- Description: Contains the
query
parameters sent as part of the Unified API call
- Description: Contains the
body
- Description: The request body associated with the Unified API call.
context
- Description: Contains all the variables stored in your Integrated Account.
before
- Description: Contains the result of the
before steps
call.
- Description: Contains the result of the
id
- Description: Can be used for cases when
id
is present in Query Params, for example in/crm/accounts/:id
- Description: Can be used for cases when
Example
Scenario: User inputs contact.id
which is mapped to person_id
that the underying Salesforce
API accepts. Here, contact
is the Unified API resource that maps to Persons in Salesforce. To filter Accounts with a particular contact, we use the following query mapping
Query Mapping Configuration:
{
"person_id": query.contact.id
}
Explanation:
query.contact.id
accesses thecontact.id
parameter from the user's request.person_id
is the internal parameter used by Salesforce.
Example Unified Request:
GET /unified/crm/accounts?contact[id]=12345
Mapped Query Parameters:
{
"person_id": "12345"
}
Body Mappings
Available Bindings
body
- Description: The request body associated with the Unified API call.
query
- Description: Mapped query parameters.
rawQuery
- Description: The query parameters from the user's request before
query
mapping.
- Description: The query parameters from the user's request before
context
- Description: Contains all the variables stored in your Integrated Account.
before
- Description: Contains the result of the
before steps
call.
- Description: Contains the result of the
id
- Description: Can be used for cases when
id
is present in Query Params, for example in/crm/accounts/:id
- Description: Can be used for cases when
Example
Body Mapping Configuration:
{
"fullName": body.name
}
Explanation:
body.name
accesses thename
field from the request body.fullName
is the field used by the underlying API.
Header Bindings
Available Bindings
headers
- Description: The HTTP headers from the Unified API call.
query
- Description: Mapped query parameters.
rawQuery
- Description: The query parameters from the user's request before
query
mapping.
- Description: The query parameters from the user's request before
body
- Description: The request body associated with the Unified API call.
context
- Description: Contains all the variables stored in your Integrated Account.
Example
Header Mapping Configuration:
{
"Authorization": context.authToken
}
Explanation:
context.authToken
accesses the authentication token from the API call context.Authorization
header is set with the token for Salesforce authentication.
Request Path Bindings
Available Bindings
headers
- Description: The HTTP headers from the Unified API call.
body
- Description: The request body associated with the Unified API call.
query
- Description: Mapped query parameters.
rawQuery
- Description: The query parameters from the user's request before
query
mapping.
- Description: The query parameters from the user's request before
context
- Description: Contains all the variables stored in your Integrated Account.
before
- Description: Contains the result of the
before steps
call.
- Description: Contains the result of the
id
- Description: Can be used for cases when
id
is present in Query Params, for example in/crm/accounts/:id
- Description: Can be used for cases when
Example
Request Path Mapping Configuration:
{
"userId": query.user_id
}
Explanation:
query.user_id
accesses the mappeduser_id
parameter.userId
is used to construct or modify the request path.
Error Bindings
Available Bindings
error
- Description: The error object containing error details returned by the underlying API.
headers
- Description: The HTTP headers from the Unified API call.
body
- Description: The request body associated with the Unified API call.
query
- Description: Mapped query parameters.
rawQuery
- Description: The query parameters from the user's request before
query
mapping.
- Description: The query parameters from the user's request before
context
- Description: Contains all the variables stored in your Integrated Account.
before
- Description: Contains the result of the
before steps
call.
- Description: Contains the result of the
id
- Description: Can be used for cases when
id
is present in Query Params, for example in/crm/accounts/:id
- Description: Can be used for cases when
Response Bindings
Used in: Response Mapping
Purpose: Transform the API response into a user-friendly format.
Available Bindings
response
- Description: The raw API response returned by the API call.
query
- Description: Mapped query parameters.
rawQuery
- Description: The raw query parameters from the user's request.
context
- Description: Contains all the variables stored in your Integrated Account.
headers
- Description: HTTP headers in the API response.
body
- Description: The request body associated with the Unified API call.
Example
Response Mapping Configuration:
{
"id": Id,
"owner": { "id": OwnerId },
"name": Name
}
Explanation:
Id
maps Salesforce'sId
to the API'sid
.OwnerId
maps to a nestedowner.id
.Name
maps directly toname
in the response.
Final API Response:
{
"id": "0012w000024KwDeAAK",
"owner": {
"id": "0052w00000CkYXHAA3"
},
"name": "Truto-Archith-Test"
}
Response Header Bindings
Used in: Response Header Mapping
Purpose: Manage HTTP headers in the API response.
Available Bindings
headers
- Description: HTTP headers in the API response.
query
- Description: Mapped query parameters related to the response headers.
rawQuery
- Description: The raw query parameters from the user's request.
body
- Description: The request body associated with the Unified API call.
context
- Description: Contains all the variables stored in your Integrated Account.
Is Partial Response?
Sometimes, the APIs you call may not return all the data you need in a single response. In such situations, you might need to make an additional API call to another endpoint to fetch the remaining data. To handle this, you can enable the Is partial response? option in the Advanced Settings of the Response Mapping configuration.
By default, this value is set to true when you enable this option. You can also define a JSONata expression that returns a boolean to validate whether the response is partial.
Available Bindings
query
- Description: Mapped query parameters.
rawQuery
- Description: The raw query parameters from the user's request.
before
- Description: Contains the result of the
before steps
call.
- Description: Contains the result of the
id
- Description: Can be used for cases when
id
is present in Query Params, for example in/crm/accounts/:id
- Description: Can be used for cases when
rawBody
- Description: Contains an
Array Buffer
of thebody
. Useful if the underlying API accepts data in a different formats likebase64
.
- Description: Contains an
Before/After Steps
Available Bindings
id
- Description: Can be used for cases when
id
is present in Query Params, for example in/crm/accounts/:id
- Description: Can be used for cases when
query
- Description: Mapped query parameters.
step
Description: The step in before after/steps
The step object has the following attributes -
type
- The type of the stepname
- The name of the steprun_if
- If thestep
runs on certain conditions
context
- Description: Contains all the variables stored in your Integrated Account.
body
- Description: The request body associated with the Unified API call.
Practical Example
Scenario: Mapping Contact Resource
Map contact.id
to the internal person_id
used by Salesforce and then map it back in the response.
Step 1: Define Query Mapping
Query Mapping Configuration:
{
"person_id": query.contact.id
}
Explanation:
query.contact.id
accesses thecontact.id
parameter from the user's request.person_id
is the internal parameter used by Salesforce.
Example Request:
GET /unified/crm/accounts?contact[id]=12345
Mapped Query Parameters:
{
"person_id": "12345"
}
Step 2: Define Response Mapping
Option 1: Using query
Binding
Response Mapping Configuration:
{
"contact": {
"id": query.person_id
}
}
Resulting API Response:
{
"contact": {
"id": "12345"
}
}
Option 2: Using rawQuery
Binding
Response Mapping Configuration:
{
"contact": {
"id": rawQuery.contact.id
}
}
Resulting API Response:
{
"contact": {
"id": "12345"
}
}