Skip to content

Build your own Unified API in the dashboard: define its resources and schema, map each method to an integration's API, then install it and call it. This guide builds a CRM Unified API with an accounts resource backed by Salesforce.

Skip the reading — fast path for coding agents
CLI
truto unified test-mapping --model my-crm --resource accounts --integration salesforce --input sample.json
Skill
View truto-unified-mappings skill on GitHub Cursor / Claude Code: /skill truto-unified-mappings

Step 1: Add a new Unified API

1.1. Go to the catalog

  1. Open the catalog:

    • At the top right of the dashboard, click Catalog, then the Unified APIs tab. Catalog Unified APIs
  2. Create a new Unified API:

    • Click Create Unified API.
    • Create Unified API

1.2. Fill in the details

Create Unified API asks for the basic information about your new API.

  • Name: Use lowercase letters with hyphens (kebab-case).
    Example: my-crm
    This sets the API path to /unified/my-crm.
    Calls find a Unified API by name, so pick a name no installed Unified API uses. Truto's own CRM Unified API is already called crm.

  • Label: A friendly name for your API.
    Example: My CRM API

  • Category: Helps organize your API.
    Example: CRM

Unified API Popup

1.3. Create the API

  1. After filling in all details, click Create.
  2. The dashboard opens the new Unified API's page.

Available Unified API

Creating a Unified API doesn't install it. You install it in Step 7.

Step 2: Add a resource

A resource represents a specific part of your API, like "accounts" in a CRM system.

2.1. Add a resource

  1. Go to Resources:

    • On the Unified API's page, click the Resources tab.
  2. Add a new resource:

    • Click Add resource.

    Add Resource Unified API

  3. Enter the resource details:

    • Resource name: Enter the name in kebab-case, for example accounts or phone-numbers. The dashboard converts what you type to kebab-case.
    • Select the Integration for this resource: Pick the integration the resource maps to, for example Salesforce. Add a resource modal
  4. Create the resource:

    • Click Add.

2.2. Configure the resource schema

The schema defines the structure of the response data your Unified API will handle. It drives the API reference for the resource, and Truto also uses its field types at runtime, for example to cast column types for truto_super_query reads. Unified API responses are not validated against it.

  1. Edit Schema:

    • In the Resources tab, select your newly added accounts resource.
    • Click on the Schema tab.
    • Click the edit (pencil) icon to modify the schema.

    Schema Edit

  2. Define the Schema:

    • Fields: Specify each piece of data your API will manage.
    • Types: Indicate the type of data (e.g., string, integer).
    • Descriptions: Provide a brief explanation for each field.

    You can add the schema using the Form or in JSON.

    Resource schema form

  3. Save the Schema:

    • After entering all fields, click the Save button.

    Add Schema Details

    Note: This is how the schema will look like in JSON

    {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "The account's unique identifier",
          "required": true
        },
        "owner": {
          "type": "object",
          "description": "The account's owner",
          "properties": {
            "id": {
              "type": "string",
              "description": "The owner's unique identifier"
            }
          }
        },
        "name": {
          "type": "string",
          "description": "The account's name"
        },
        "website": {
          "type": "string",
          "description": "The account's website"
        }
      }
    }

    Add the other fields your API returns the same way.

Step 3: Add methods and pick what they call

The next step is to add a method, which is how the interaction happens with Salesforce.

3.1. Add a method

  1. Add a method:

    • Within the accounts resource, click the Mapping tab.
    • Click Add method.
    • Method name: Enter list, get, create, update, delete, or a kebab-case name for a custom method.

    Add Method

  2. Save the method:

    • Click Add.
    • This opens the mapping modal.

3.2. Pick the integration resource and method

The mapping modal groups its tabs: Resource, Mapping (Query mapping, Request body mapping, Response mapping, Error mapping), Headers (Request header mapping, Response header mapping) and Advanced (Before/After Steps, Notes).

On the Resource tab, Resource and Method are the integration's resource and method this unified method calls, for example Salesforce accounts / list. They come from the integration (here, Salesforce), and they can differ from the unified method: Truto's own Salesforce crm/accounts list calls the search resource when the caller passes search_term. See Advanced mapping options.

  1. Select the resource and method:

    • Resource: Choose accounts.
    • Method: Choose list.

    Mapping Screen

Step 4: Define the query mapping

Translates query parameters in the Unified API call into the query supported by the underlying API.

Add a query mapping to every method that accepts filters. Truto sends the provider only what the query mapping returns, plus limit, next_cursor, truto_* parameters, the method's default query, and anything the caller passes in remote_query[...] (see Querying). A filter the mapping doesn't return never reaches the provider, and the call returns unfiltered results. Path placeholders such as {{query.customer_id}} are filled from the mapped query too. Request bodies work the other way: with no request body mapping, the body is sent as received.

  1. Go to the query mapping:

    • Open Mapping → Query mapping.

    Query Mapping

  2. Query Schema (YAML):

    The Query Schema specifies what should be in the Query Parameters. Since the schema is defined in Resource Schema, you can just specify the fields from the schema that will be used in the Query and required, type, description will be automatically used from the Resource Schema. The Query Schema is specified in YAML.

     name: {}
     owner: {}
     city: {}
     state: {}
     country: {}
     created_at: {}
     updated_at: {}
     last_activity_at: {}
     website: {}
     industry: {}
     number_of_employees: {}
     fields: {}
     custom_fields: {}
     search_term: {}
  3. Query Example:

    A sample input for the mapping. It is the expression's whole input, so the query parameters go under query.

    {
      "query": {
        "search_term": "Acme",
        "name": "Acme's",
        "website": "truto",
        "include_custom_fields": ["field_1"],
        "fields": ["fields"]
      }
    }
  4. Query mapping:

    Translates the Unified API's query parameters into a Salesforce-compatible SOQL query.

    (
      $whereClause := query
        ? $convertQueryToSql(
          $merge([
            query
              .{
                "created_at": created_at,
                "updated_at": updated_at,
                "last_activity_at": last_activity_at,
                "name": name ? { "LIKE": "%" & name & "%" },
                "owner": owner.id,
                "city": city ? { "LIKE": "%" & city & "%" },
                "state": state ? { "LIKE": "%" & state & "%" },
                "country": country ? { "LIKE": "%" & country & "%" },
                "website": website.eq
                  ? website.eq
                  : website
                    ? { "LIKE": "%" & website & "%" },
                "industry": industry ? { "LIKE": "%" & industry & "%" },
                "number_of_employees": number_of_employees
              },
            $sift(query.custom_fields, function($v, $k) { $k ~> /__c$/i })
          ]),
          [
            "created_at",
            "updated_at",
            "last_activity_at",
            "name",
            "owner",
            "city",
            "state",
            "country",
            "website",
            "industry",
            "number_of_employees",
            $keys(query.custom_fields)
          ],
          {
            "created_at": "CreatedDate",
            "updated_at": "LastModifiedDate",
            "last_activity_at": "LastActivityDate",
            "name": "Name",
            "owner": "OwnerId",
            "city": "BillingCity",
            "state": "BillingState",
            "country": "BillingCountry",
            "website": "Website",
            "industry": "Industry",
            "number_of_employees": "NumberOfEmployees"
          },
          $merge([
            {
              "created_at": "date",
              "updated_at": "date",
              "last_activity_at": "date|yyyy-LL-dd",
              "name": "string",
              "owner": "string",
              "city": "string",
              "state": "string",
              "country": "string",
              "website": "string",
              "industry": "string",
              "number_of_employees": "number"
            },
            $keys(query.custom_fields).{ $: "string" }
          ]),
          { "LIKE": "LIKE" },
          { "noQuotesForDate": true, "escapeSingleQuotes": true }
        );
      $searchTermWhereClause := $whereClause ? " WHERE " & $whereClause;
      $searchTermCustomFields := $firstNonEmpty(query.include_custom_fields, query.fields)
        ? ", " & $join($firstNonEmpty(query.include_custom_fields, query.fields), ",");
      {
        "q": query.search_term
          ? "FIND {" & query.search_term
            & "} RETURNING Account(Id, OwnerId, Name, Description, Industry, NumberOfEmployees, Website, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, Phone, Fax, LastActivityDate, CreatedDate, LastModifiedDate"
            & $searchTermCustomFields
            & $searchTermWhereClause
            & ")",
        "where": $whereClause ? "WHERE " & $whereClause,
        "include_custom_fields": $firstNonEmpty(query.include_custom_fields, query.fields)
          ? ", " & $join($firstNonEmpty(query.include_custom_fields, query.fields), ",")
      }
    )
  5. Mapped Query (Result):

    An example of how the above mapping logic transforms the input into a Salesforce-compatible query.

    {
      "q": "FIND {Acme} RETURNING Account(Id, OwnerId, Name, Description, Industry, NumberOfEmployees, Website, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, Phone, Fax, LastActivityDate, CreatedDate, LastModifiedDate, field_1 WHERE Name LIKE '%Acme\\'s%' AND Website LIKE '%truto%')",
      "where": "WHERE Name LIKE '%Acme\\'s%' AND Website LIKE '%truto%'",
      "include_custom_fields": ", field_1"
    }

Step 5: Map the request body

A create or update method needs a request body mapping to turn the caller's body into the body the provider accepts. Add a create method to accounts as in Step 3 (Salesforce accounts / create), then open Mapping → Request body mapping.

  1. Request Body Schema (YAML): list the body fields the method accepts, keyed by field name. Mark a field required: true to make it required:

    name:
      required: true
    website: {}
  2. Request Body Mapping: map the caller's body to Salesforce's fields:

    {
      "Name": body.name,
      "Website": body.website
    }

    With the Request Body Example { "body": { "name": "Truto", "website": "truto.one" } }, Mapped Body (Result) shows { "Name": "Truto", "Website": "truto.one" }.

How the body reaches the provider:

  • Callers who pass truto_enforce_write_schema=true get a 400 listing missing required fields in truto_error_insight.missing_required_body_fields before anything is sent, including before steps; see Querying. Without that parameter, required isn't enforced.
  • A remote_data object in the caller's body is merged over the mapped body, so a caller can send provider fields the mapping doesn't cover. A body with remote_data also skips the required-field check.
  • With no request body mapping, the caller's body is merged over the method's default body and sent.
  • Truto also evaluates the mapping once with the method's default body as its whole input, so an unguarded $error() in the mapping fails every call.

Step 6: Add the response mapping

After configuring how queries and bodies are handled, define how responses from the underlying API are transformed to fit your Unified API's structure.

6.1. Configure the response mapping

  1. Go to the response mapping:

    • Open Mapping → Response mapping for the list method.

    Response Mapping

  2. Response Schema (YAML):

    This defines the structure of the data your API will return to users. This is specified in YAML and autopopulated from the Resource Schema defined above.

     type: object
     properties:
       id:
         type: string
         description: The account's unique identifier
         required: true
       owner:
         type: object
         description: The account's owner
         properties:
           id:
             type: string
             description: The owner's unique identifier
       name:
         type: string
         description: The account's name
       description:
         type: string
         description: The account's description
       industry:
         type: string
         description: The account's industry
       website:
         type: string
         description: The account's website
       number_of_employees:
         type: integer
         description: The account's number of employees
       addresses:
         type: array
         items:
           type: object
           properties:
             id:
               type: string
               description: The unique identifier of the address
             street_1:
               type: string
               description: Line 1 of the street address
             street_2:
               type: string
               description: Line 2 of the street address
             city:
               type: string
               description: The city
             state:
               type: string
               description: The state
             postal_code:
               type: string
               description: The postal code
             country:
               type: string
               description: The country
             type:
               type: string
               description: The address type
       phone_numbers:
         type: array
         items:
           type: object
           properties:
             id:
               type: string
               description: The unique identifier of the phone number
             number:
               type: string
               description: The phone number
             extension:
               type: string
               description: The extension of the phone number
             type:
               type: string
               description: The phone number type
       urls:
         type: array
         items:
           type: object
           properties:
             url:
               type: string
               description: The account's URL
             type:
               type: string
               description: The account's URL type
         description: The account's urls
       tags:
         type: array
         items:
           type: object
           properties:
             id:
               type: string
               description: The tag's unique identifier
             name:
               type: string
               description: The tag's name
         description: The contact's tags
       custom_fields:
         type: object
         description: All the custom fields present on the account
         additionalProperties: true
       last_activity_at:
         type: string
         description: The date and time of the account's last activity
         format: date-time
       updated_at:
         type: string
         description: The date and time of the account's last update
         format: date-time
       created_at:
         type: string
         description: The date and time of the account's creation
         format: date-time
  3. Response Example:

    Provide an example raw API response from Salesforce so that you can verify your mapping. It is the expression's whole input, so the record goes under response.

    {
      "response": {
        "attributes": {
          "type": "Account",
          "url": "/services/data/v57.0/sobjects/Account/0012w000024KwDeAAK"
        },
        "truto__Custom_Alternate_Email__c": "jane@acme.example",
        "Id": "0012w000024KwDeAAK",
        "IsDeleted": false,
        "MasterRecordId": null,
        "Name": "Acme Corp",
        "Type": null,
        "ParentId": null,
        "BillingStreet": "5",
        "BillingCity": "BNGLR",
        "BillingState": "KA",
        "BillingPostalCode": "560066",
        "BillingCountry": "INDIA",
        "BillingLatitude": null,
        "BillingLongitude": null,
        "BillingGeocodeAccuracy": null,
        "BillingAddress": {
          "city": "BNGLR",
          "country": "INDIA",
          "geocodeAccuracy": null,
          "latitude": null,
          "longitude": null,
          "postalCode": "560066",
          "state": "KA",
          "street": "5"
        },
        "ShippingStreet": "sdf",
        "ShippingCity": "sf",
        "ShippingState": "fsfs",
        "ShippingPostalCode": "fsfssf",
        "ShippingCountry": "sffsnull",
        "ShippingLatitude": null,
        "ShippingLongitude": null,
        "ShippingGeocodeAccuracy": null,
        "ShippingAddress": {
          "city": "sf",
          "country": "sffsnull",
          "geocodeAccuracy": null,
          "latitude": null,
          "longitude": null,
          "postalCode": "fsfssf",
          "state": "fsfs",
          "street": "sdf"
        },
        "Phone": "89845552321",
        "Fax": "5754545585544",
        "AccountNumber": null,
        "Website": "hi-triuto.one",
        "PhotoUrl": "/services/images/photo/0012w000024KwDeAAK",
        "Sic": null,
        "Industry": "Automation",
        "AnnualRevenue": null,
        "NumberOfEmployees": 2,
        "Ownership": null,
        "TickerSymbol": null,
        "Description": "Test",
        "Rating": null,
        "Site": null,
        "OwnerId": "0052w00000CkYXHAA3",
        "CreatedDate": "2024-01-09T06:07:11.000+0000",
        "CreatedById": "0052w00000CkYXHAA3",
        "LastModifiedDate": "2024-08-29T06:53:52.000+0000",
        "LastModifiedById": "0052w00000CkYXHAA3",
        "SystemModstamp": "2024-08-29T06:53:52.000+0000",
        "LastActivityDate": "2024-05-01",
        "LastViewedDate": "2024-08-29T06:53:52.000+0000",
        "LastReferencedDate": "2024-08-29T06:53:52.000+0000",
        "Jigsaw": null,
        "JigsawCompanyId": null,
        "CleanStatus": "Pending",
        "AccountSource": null,
        "DunsNumber": null,
        "Tradestyle": null,
        "NaicsCode": null,
        "NaicsDesc": null,
        "YearStarted": null,
        "SicDesc": null,
        "DandbCompanyId": null,
        "OperatingHoursId": null
      }
    }
  4. Response Mapping:

    Transforms the raw Salesforce response into the structure defined by your Unified API's response schema. For a list, the mapping runs once per record and response is that record. Inside response.{ … }, reach other bindings from the root, for example $$.context.subdomain; see JSONata bindings.

    response
      .{
        "id": Id,
        "owner": { "id": OwnerId },
        "name": Name,
        "description": Description,
        "industry": Industry,
        "number_of_employees": NumberOfEmployees,
        "website": Website,
        "addresses": [
          {
            "street_1": BillingStreet,
            "city": BillingCity,
            "state": BillingState,
            "postal_code": BillingPostalCode,
            "country": BillingCountry,
            "type": "billing"
          },
          {
            "street_1": ShippingStreet,
            "city": ShippingCity,
            "state": ShippingState,
            "postal_code": ShippingPostalCode,
            "country": ShippingCountry,
            "type": "shipping"
          }
        ],
        "phone_numbers": [
          { "number": Phone, "type": "phone" },
          { "number": Fax, "type": "fax" }
        ],
        "last_activity_at": LastActivityDate,
        "created_at": CreatedDate,
        "updated_at": LastModifiedDate,
        "custom_fields": $sift($, function($v, $k) { $k ~> /__c$/i and $boolean($v) })
      }

    Explanation:

    • id: Maps Salesforce's Id to your API's id.
    • owner: Extracts OwnerId from Salesforce and nests it under owner.id.
    • addresses: Combines billing and shipping addresses into a single array, distinguishing them by type.
    • phone_numbers: Includes both Phone and Fax numbers with their respective types.
    • custom_fields: Filters and includes only custom fields from Salesforce that end with __c and have valid values.
  5. Check the Mapped Response (Result):

    This is the result of your Response Example above transformed through the Response Mapping. Use it to verify that the mapping is correct. At runtime, Truto also adds the raw record to each mapped record as remote_data.

    {
      "id": "0012w000024KwDeAAK",
      "owner": {
        "id": "0052w00000CkYXHAA3"
      },
      "name": "Acme Corp",
      "description": "Test",
      "industry": "Automation",
      "number_of_employees": 2,
      "website": "hi-triuto.one",
      "addresses": [
        {
          "street_1": "5",
          "city": "BNGLR",
          "state": "KA",
          "postal_code": "560066",
          "country": "INDIA",
          "type": "billing"
        },
        {
          "street_1": "sdf",
          "city": "sf",
          "state": "fsfs",
          "postal_code": "fsfssf",
          "country": "sffsnull",
          "type": "shipping"
        }
      ],
      "phone_numbers": [
        {
          "number": "89845552321",
          "type": "phone"
        },
        {
          "number": "5754545585544",
          "type": "fax"
        }
      ],
      "last_activity_at": "2024-05-01",
      "created_at": "2024-01-09T06:07:11.000+0000",
      "updated_at": "2024-08-29T06:53:52.000+0000",
      "custom_fields": {
        "truto__Custom_Alternate_Email__c": "jane@acme.example"
      }
    }
  6. Save the mapping:

    Click Save, review the changes, and confirm. This saves the Unified API mapping for the resource.

Info

A saved change to a mapping, an environment override or a Unified API's schema can take up to about 23 minutes to reach API calls, because each connection caches them. To apply it now, call POST /integrated-account/refresh-mapping-cache; pass integration_id when you changed one integration's mapping. It answers 202, and a region can keep serving the old mapping for up to about 6 more minutes. An integrated account's own unified_model_override applies on the next call.

curl -X POST https://api.truto.one/integrated-account/refresh-mapping-cache \
  -H 'Authorization: Bearer <API token>' \
  -H 'Content-Type: application/json' \
  -d '{"integration_id":"<integration_id>"}'
truto accounts refresh-mapping-cache -i <integration_id>

Step 7: Install it and call it

Creating a Unified API doesn't install it. Until it's installed in an integrated account's environment, every call to it returns 404.

  1. On the Unified API's page, click Install.
  2. In Install Unified API, pick the environments, then click Install.

To install with the API or the CLI, send the environment's ID and the Unified API's ID:

curl -X POST https://api.truto.one/environment-unified-model \
  -H 'Authorization: Bearer <API token>' \
  -H 'Content-Type: application/json' \
  -d '{ "environment_id": "<environment_id>", "unified_model_id": "<unified_model_id>" }'
truto env-unified-models create --environment-id <environment_id> --unified-model-id <unified_model_id>

Then call it for an integrated account in that environment:

curl "https://api.truto.one/unified/my-crm/accounts?integrated_account_id=<integrated_account_id>" \
  -H 'Authorization: Bearer <API token>'
truto unified my-crm accounts -a <integrated_account_id>

See Install a Unified API for uninstalling and the 404 message.

Test and debug a mapping

In the dashboard. Each mapping tab has an example and a result. The example is the expression's whole input, so it holds the bindings by name: response for a response mapping, query for a query mapping, error for an error mapping. Add query, context or before keys next to response to test a mapping that reads them:

{
  "response": { "Id": "0012w000024KwDeAAK", "Name": "Truto" },
  "query": { "status": "active" },
  "context": { "subdomain": "acme" }
}

On your machine. truto unified test-mapping evaluates a response mapping against a sample response without calling the integration, and --with-overrides adds an environment's overrides. truto jsonata eval evaluates any expression against a JSON input. See Test mapping locally and JSONata in the CLI docs.

On a live call. Add truto_response_format=debug to see the request Truto sent and the provider's raw response; see See the raw remote response. A Unified API call's log has step_results, one entry per before and after step with its type, name, duration and whether it succeeded, was skipped or failed. Add truto_debug=true to the call to also record each step's resolved config.

Static mapping

Sometimes an endpoint always returns the same data, such as a fixed list of options. Static mapping returns a response you configure in the Unified API, without calling the provider.

Static mapping applies to list and get only; create, update and delete always call the provider. Truto returns the value you enter as result, as is: no response mapping, remote_data or before and after steps.

How to enable static mapping

  1. Open the response mapping

    • Go to the resource and method you're working on.
    • Open Mapping → Response mapping.
  2. Enable static mapping

    • Turn on the Static mapping toggle.
  3. Define the static response

    • Enter the response to return every time this method is called. For list, enter an array of records.
    • Example:
      [
        { "id": "1", "name": "Option A" },
        { "id": "2", "name": "Option B" },
        { "id": "3", "name": "Option C" }
      ]

Once enabled, it should look like this:
Static Mapping

  1. Save your configuration
    • Save your changes, and the Unified API returns the static response whenever this method is called.

When to use static mapping

  • List or get endpoints: For endpoints that return predefined or rarely changing data, such as dropdown options or fixed settings.
  • No provider dependency: If you don't want the response to rely on an API call.
  • Faster responses: Reduces latency since no API request is made.

Error mapping

In case the underlying API returns an error, you can define a custom mapping to standardize the error structure for your Unified API consumers.

Configure error mapping

  1. Open Mapping → Error mapping.

  2. Error Example (JSON): the example is the expression's whole input, so the provider's error body goes under error:

    {
      "error": {
        "message": "Something went wrong",
        "errorCode": 4001
      }
    }

What the error mapping returns

The error mapping returns an object with these keys:

  • message: The error message the caller receives.
  • metadata: Optional additional details about the error, such as the provider's own error code.
  • status: Optional HTTP status code for the caller, for example 422. If you return a status below 400, the Unified API treats the call as a success and returns that status with response as the result.
  • response: Optional. The result to return when status is below 400.

Any other keys are ignored.

Error mapping:

{
  "status": error.errorCode = 4001 ? 422 : 502,
  "message": error.message,
  "metadata": { "provider_code": error.errorCode }
}

Error Mapping

Select View available bindings for the full list, or see Error bindings.

Mapped Error (Result)

Applied to the example error, the mapping returns:

{
  "status": 422,
  "message": "Something went wrong",
  "metadata": {
    "provider_code": 4001
  }
}

What the caller receives

Callers never see the mapping's object itself. The mapping's status becomes the HTTP status and statusCode, and the body has Truto's error shape. For the example, the caller receives HTTP 422 with a body like this (other fields from the Errors page left out):

{
  "statusCode": 422,
  "message": "Something went wrong",
  "metadata": {
    "provider_code": 4001
  },
  "truto_is_remote_error": true,
  "raw_response": {
    "message": "Something went wrong",
    "errorCode": 4001
  }
}
  • A status below 400 turns the call into a success that returns response. Related resources and the response mapping are skipped; after steps still run.
  • error is the provider's error body, as JSON or text. For integrations that declare an error expression, it is { "data": …, "headers": … } instead. The HTTP status code is not a binding.
  • The mapping doesn't run when the provider's error has an empty body, or when a before step fails.

Request header mapping

You can define how your Unified API injects or transforms headers before sending them to the underlying API. The headers binding holds the headers Truto has prepared for that request; of the headers sent to the Unified API, only content-type is carried over, and only on writes, so custom headers on the Unified API call are not available here. Use context, query or body to source values instead.

Configure request header mapping

  1. Open Headers → Request header mapping.

  2. Request Header Example: the example is the expression's whole input, so the prepared headers go under headers and the account's values under context:

    {
      "headers": {
        "content-type": "application/json"
      },
      "context": {
        "region": "eu"
      }
    }

Write the request header mapping

  • The mapping should return an object where the key-values contain the header name and the value.

    Example JSONata mapping:

    {
      "x-api-version": "2024-01",
      "x-account-region": context.region
    }
  • View available bindings: lists what the mapping can read. See Header bindings.

  • Beautify JSONata (optional): Prettifies the expression for easier readability.

Mapped Header (Result)

The preview shows what the mapping returns:

{
  "x-api-version": "2024-01",
  "x-account-region": "eu"
}

At runtime, Truto merges this object over the headers it prepared for the request.

Request Header Mapping

Response header mapping

You can define how headers returned by the underlying API are transformed or exposed back to the consumer of the Unified API.

Configure response header mapping

  1. Open Headers → Response header mapping.

  2. Response Header Example: the provider's headers go under headers:

    {
      "headers": {
        "some-internal-header": "some-value",
        "some-other-header": "sessionid=123456"
      }
    }

Write the response header mapping

  • The mapping should return an object where the key-values contain the header name and the value.

    Example JSONata mapping:

    {
      "x-truto-header": headers.`some-internal-header`
    }
  • The object you return is merged over the headers returned by the underlying API, and all header names are lowercased. Use it to add or overwrite headers; headers you leave out are still returned.

Mapped Header (Result)

The preview shows what the mapping returns:

{
  "x-truto-header": "some-value"
}

At runtime, the client receives the provider's headers with this object merged over them:

{
  "some-internal-header": "some-value",
  "some-other-header": "sessionid=123456",
  "x-truto-header": "some-value"
}

Response Header Mapping

Advanced mapping options

These options are set in the mapping modal's Code View (YAML) or on the Response mapping tab.

Pick the resource or method per call

resource and method can be a list of selectors instead of a single name. Each selector names a resource (for method, the value key is method) and an optional condition: query_param (with an optional query_param_value) or body_field (with an optional body_field_value). Without a value, the condition matches when the parameter or field has a non-empty value; an empty string, 0 or false doesn't match. The first selector that matches wins, a selector with no condition always matches, and when none matches the call fails before anything is sent.

Truto's Salesforce crm/accounts list uses a list like this (shortened):

resource:
  - resource: queryAll
    query_param: truto_deleted_since
  - resource: search
    query_param: search_term
  - resource: accounts
method: list

resource or method can also be an object with a JSONata expression and the allowed values in resources (or methods for method). The expression reads query, rawQuery, body and context, and must return one of the listed values.

related_resources calls other resources of the integration and attaches their results to the raw records before the response mapping runs. Use it when a resource needs data from a parent or child resource.

Response mapping method

Response mapping method, under the response mapping, decides how a list mapping runs. Item, the default, runs the expression once per record. Array runs it once over the whole list.

Same as

Turn on Same as on the Response mapping tab and pick a Method to reuse that method's response mapping instead of writing a new one.

Before steps

Before steps are actions that run before the main request is made by the Unified API. Use them to fetch extra data, fill in missing fields, or add logic for specific conditions. Open Advanced → Before/After Steps to add them.

How to set up before steps

  1. Choose the type of step
    There are three types of before steps you can configure:
    • Request: Fetch additional data. The response replaces the data passed along the before steps and is saved under the step's name.
    • State: Evaluate a JSONata expression. Its result replaces the data passed along the before steps and is saved under the step's name.
    • Replace data: Set the step data to the result of an earlier step, by name.

How request steps behave

  • In form mode, ID, Query parameters and Request Body accept {{…}} placeholders over data, query, id, body, context and step, for example {{query.interview_id}}. It is text substitution, not JSONata.
  • For Request type unified, the resource is a resource of the same Unified API. For proxy, it is a resource of the integration. The method can be any method, including custom ones.
  • A unified request starts with an empty query, and reuses the caller's body unless the step sets a body.
  • Delay (ms) waits that many milliseconds before the step runs.
  • A failing step fails the whole call with the step's error, and the method's error mapping doesn't run. A step skipped by Run If (JSONata) is recorded, not an error.
  • Step names become keys in step, so a name with spaces, such as Fetch Interview Details, needs backticks (step.`Fetch Interview Details` ). Use a short name such as interview.

For example, a form-mode request step with Resource to fetch interviews, Method to call get and ID {{query.interview_id}} fetches the interview the caller named.

Step types in detail

1. Request (fetch additional data)

Use this step to call another Unified API resource and fetch additional data before the Unified API call.

  • When to use it:
    If your request requires data from another resource, like fetching interview details before querying candidates.

  • Setup:

    • Name: Enter a name for the step.
      Example: interview

    • Run it conditionally: Enable this to only run the step when needed.

    • Run If (JSONata): Add a JSONata expression to decide whether the step should run.
      Example:

      $exists(query.interview_id)

      This step will run only if interview_id exists in the query.

    • Delay (ms): Optional. Wait this many milliseconds before the step runs.

    • JSONata expression: Enable this to specify a JSONata expression for the request. You should specify the following attributes in the JSONata expression :

      • resource - The name of the resource to call
      • method - The method to call: get, list, create, update, delete, or a custom method
      • type - The type of the request, unified or proxy. Defaults to unified.
      • config - An object with the id, query and body to send with the request.

      Return an array of these objects to make several requests in parallel. With two or more requests the step result is an array of their results, in the same order; an array with one request returns that request's result on its own.

      Example:

      {
        "resource": "interviews",
        "method": "get",
        "type": "unified",
        "config": { "id": query.interview_id }
      }

      You can also use the available Before/After JSONata Bindings to send, access, and modify body, query or id values.

    Alternatively, fill in the form:

    • Request type: Select Unified or Proxy.
    • Resource to fetch: Select the resource (e.g., interviews).
    • Method to call: Choose the method (e.g., get or list).
    • ID: The ID of the record to fetch, for get, update and delete. For example, {{query.interview_id}}.
    • Query parameters: Add any parameters needed in JSON format.
      Example:
      {
        "include_details": true
      }
    • Request Body: Specify the body in JSON format, if the method takes one.

2. State

Use this to compute new data with a JSONata expression. The result replaces the data passed to the next step.

  • Setup:
    • Name: Enter a name for the step.
      Example: default_priority
    • Run it conditionally: Enable this to only run the step when needed.
    • Run If (JSONata): Provide a JSONata expression that returns true or false to determine whether the step should run.
      Example:
      $not($exists(query.priority))
      This step will run only if the priority field is missing.
    • JSONata Expression: The expression whose result becomes the step's data. It receives data (the data so far; before steps start with an empty object), query, body and id from the request, context (the integrated account's context), and step (the result of each earlier step, by name). The result is passed to the next step and stored under this step's name, so a later Replace data step can use it. When the before steps finish, the mappings read the data as before.
      Example:
      { "priority": $exists(query.priority) ? query.priority : "normal" }

3. Replace data

Use this step to set the data passed along the before steps to the result of an earlier step.

  • Setup:
    • Name: Enter a name for the step.
    • Run it conditionally: Enable this to only run the step when needed.
    • Run If (JSONata): Provide a JSONata expression that returns true or false to determine whether the step should run.
    • State Name: Specify the name of the earlier step whose result becomes the data.

The Before/After Steps tab looks like this:

Before Steps

After steps

After steps are actions that run after the main request is made by the Unified API. Use them to add data to the response, fill in missing fields, or add logic for specific conditions before the data is returned to the caller. They behave like request steps in before steps.

How to set up after steps

  1. Choose the type of step
    There are three types of after steps you can configure:
    • Request: Fetch additional data. The response replaces the data passed along the after steps and is saved under the step's name.
    • State: Evaluate a JSONata expression. Its result replaces the data passed along the after steps and is saved under the step's name.
    • Replace data: Set the step data to the result of an earlier step, by name.

Step types in detail

1. Request (fetch additional data)

Use this step to call another Unified API resource and fetch additional data after the Unified API call.

  • When to use it:
    For example, if the underlying API returns only the id of a record after an update, an after step can call get to fetch the full record and return it to the caller.

  • Setup:

    • Name: Enter a name for the step.
      Example: interview

    • Run it conditionally: Enable this to only run the step when needed.

    • Run If (JSONata): Add a JSONata expression to decide whether the step should run.

    • Delay (ms): Optional. Wait this many milliseconds before the step runs.

    • JSONata expression: Enable this to specify a JSONata expression for the request. You should specify the following attributes in the JSONata expression :

      • resource - The name of the resource to call
      • method - The method to call: get, list, create, update, delete, or a custom method
      • type - The type of the request, unified or proxy. Defaults to unified.
      • config - An object with the id, query and body to send with the request.

      Return an array of these objects to make several requests in parallel. With two or more requests the step result is an array of their results, in the same order; an array with one request returns that request's result on its own.

      Example:

      {
        "resource": "interviews",
        "method": "get",
        "type": "unified",
        "config": { "id": query.interview_id }
      }

      You can also use the available Before/After JSONata Bindings to send, access, and modify body, query or id values.

    Alternatively, fill in the form:

    • Request type: Select Unified or Proxy.
    • Resource to fetch: Select the resource (e.g., interviews).
    • Method to call: Choose the method (e.g., get or list).
    • ID: The ID of the record to fetch, for get, update and delete. For example, {{id}}.
    • Query parameters: Add any parameters needed in JSON format.
      Example:
      {
        "include_details": true
      }
    • Request Body: Specify the body in JSON format, if the method takes one.

2. State

Use this to compute new data with a JSONata expression. The result replaces the data passed to the next step, and the data left after the last step is the Unified API response.

  • Setup:
    • Name: Enter a name for the step.
      Example: active_only
    • Run it conditionally: Enable this to only run the step when needed.
    • Run If (JSONata): Provide a JSONata expression that returns true or false to determine whether the step should run.
      Example:
      $not($exists(query.priority))
      This step will run only if the priority field is missing.
    • JSONata Expression: The expression whose result becomes the step's data. It receives data (the data so far; after steps start with the Unified API response), query, body and id from the request, context (the integrated account's context), and step (the result of each earlier step, by name). The result is passed to the next step and stored under this step's name. When the after steps finish, the data is the Unified API response.
      Example:
      data[status != "deleted"]

3. Replace data

Use this step to set the data passed along the after steps, which becomes the Unified API response, to the result of an earlier step.

  • Setup:
    • Name: Enter a name for the step.
    • Run it conditionally: Enable this to only run the step when needed.
    • Run If (JSONata): Provide a JSONata expression that returns true or false to determine whether the step should run.
    • State Name: Specify the name of the earlier step whose result becomes the data.

The after steps on the Before/After Steps tab look like this:

After Steps

Truto notes

The Advanced → Notes tab is where the Truto team writes down details, limitations and pitfalls specific to this resource. You can add your own notes here too.

What you can write here

  • Key Characteristics:
    Describe what makes this resource unique or any quirks it might have. This helps set expectations and provides context.

  • Usage Tips:
    Share simple tips and best practices on how to use this resource effectively. For example, mention common pitfalls or suggest smoother ways to handle certain tasks.

  • Limitations:
    Point out any known limitations or constraints. If the underlying API has restrictions that affect this resource, note them here in plain language.

  • Troubleshooting Advice:
    Offer friendly guidance on what to do if things don't work as expected. This can include hints on where to look for errors or how to fix common issues.

  • Reminders and Warnings:
    Add any reminders or gentle warnings that can help users avoid mistakes or understand important considerations when interacting with the resource.

  • General Observations:
    Write down observations or thoughts that might be useful for anyone working with or maintaining this resource in the future.

Truto Notes

Next

Install a Unified API covers installing into more environments and uninstalling. To change a mapping for one environment or one integrated account without editing the Unified API itself, see Overriding Unified API mappings.