InputTransform

When integrating with external REST APIs using a function in Jigx, the inputTransform property defines how input parameters are mapped to the body of the HTTP request. This is essential when the function’s format is set to json.

The inputTransform is written using JSONata, a lightweight query and transformation language for JSON. It allows you to dynamically construct the JSON payload by referencing the parameters defined in the parameters section of the function.

Use inputTransform to:

  • Map parameters into a structured JSON object.

  • Build a request body that matches the target API’s requirements.

  • Dynamically generate values based on user input or context.

Simple Parameter Mapping

In this example:

  • Two parameters are defined: orderNumberParameter and orderDescriptionParameter.

  • Inside the inputTransform, these are referenced directly (without quotes).

  • The resulting JSON object maps these values to the expected keys for the API call.

inputTransform
parameters:
  orderNumberParameter:
    type: string
    location: body
    required: true
  orderDescriptionParameter:
    type: string
    location: body
    required: true

inputTransform: |
  $.{
    "orderNumber": orderNumberParameter,
    "orderDescription": orderDescriptionParameter
  }

Multi-line YAML Strings

The | character in YAML indicates a multi-line string. This is useful for formatting complex transformations like JSONata expressions over multiple lines for better readability.

Example and code snippet

Below is a more advanced example showing how to send an email using the SendGrid API. The URL for the service is https://api.sendgrid.com/v3/mail/send

The JSON body for this service is:

In this configuration:

  • parameters are defined for values like emailto, name, subject, and content.

  • The inputTransform builds a JSON structure required by the SendGrid API using those parameters.

  • The function constructs the request body at runtime, ensuring it dynamically reflects user or system inputs.

Last updated

Was this helpful?