Klevr Product Documentation logo

Synchronous API-to-API Stage

The Synchronous API-to-API stage allows Integration Hub to present an external API that calls a back-end API and returns its transformed response.

Stage Overview

The Synchronous API-to-API stage allows Integration Hub to present an external-facing API, which, when called, will:

  • Transform the incoming message payload into a new format (if required);
  • Send the transformed payload to another (back-end) API;
  • Receive the response from that API;
  • Transform the response payload into a new format (if required); and
  • Return the transformed response payload to the original caller.

This process is synchronous, allowing the caller of the external API to wait for and receive the proxied/transformed response from the back-end API.

Stage Definition File Location

All Synchronous API-to-API stages are defined by creating an appropriately formatted JSON definition file in the following location:

interfaces
{businessUnitCode}
{domainCode}
{integrationName}
sync
api-to-api
{STAGE_NAME}.json

Stage JSON Definition File Format

The JSON definition file for a Synchronous API-to-API stage is as follows:

{
  "name": "stage-name",
  "operation": "",
  "nameExtension": "",
  "displayName": "Brief Stage Title",
  "description": "Brief description of the stage.",
  "enabled": "$env:STATUS_DEVOPS_VARIABLE",
  "actions": {
    "in-api": {
      "contentType": "json | xml",
      "httpMethod": "GET | POST | PUT | PATCH | DELETE",
      "httpParametersMode": "none | parameter | REST",
      "externalApiUrlPath": "/{rest}/{params}",
      "publicAPI": true | false,
      "publicAuth": {
      }
    },
    // One of either "in-tr-js" or "in-tr-lq"
    "in-tr-js": {
      "contentType": "json-to-json | json-to-xml | xml-to-json | xml-to-xml",
      "schemaFilename": "schemas/path/to/schema/schema-name.js",
      "templateVariables": {
        // See Below
      }
    },
    "in-tr-lq": {
      "contentType": "json-to-json | json-to-xml | xml-to-json | xml-to-xml",
      "schemaFilename": "schemas/path/to/schema/schema-name.liquid",
      "templateVariables": {
        // See Below
      }
    },
    "out-proxy-api-store-response": {
      "contentType": "json | xml",
      "externalApiBaseUrl": "$env:DEVOPS_VARIABLE_BaseUrl",
      "externalApiUrlPath": "$env:DEVOPS_VARIABLE_ApiPath",
      "httpMethod": "GET | POST | PUT | PATCH | DELETE",
      "header": {
        // Custom Headers
      },
      "httpParametersMode": "none | parameter | REST",
      "authentication": {
        // See Authentication Options Below
      },
    },
    // One of either "out-tr-js" or "out-tr-lq"
    "out-tr-js": {
      "contentType": "json-to-json | json-to-xml | xml-to-json | xml-to-xml",
      "schemaFilename": "schemas/path/to/schema/schema-name.js",
      "templateVariables": {
        // See Below
      }
    },
    "out-tr-lq": {
      "contentType": "json-to-json | json-to-xml | xml-to-json | xml-to-xml",
      "schemaFilename": "schemas/path/to/schema/schema-name.liquid",
      "templateVariables": {
        // See Below
      }
    }
  }
}
PropertySub-PropertySub-PropertyDescription
nameThe API part of the stage name. See API Interface stage names.
operationThe Operation part of the stage name. See API Interface stage names.
nameExtensionSee the Using the nameExtension Property section below.
displayNameOptional (but highly recommended). A short (3 or 4 word) "display name" for the stage, used as a "title" of the stage in the Integration Hub Portal service's self-documentation capability.
descriptionOptional (but highly recommended). A brief (10 to 15 word) description of the stage, used as a brief description of the stage's purpose in the Integration Hub Portal service's self-documentation capability. For a more detailed explanation (when needed), use the stage markdown feature.
enabledOptional boolean flag (true or false). Default is true.

Generally set via a DevOps variable. Controls if the stage is deployed enabled or not.
actionsAn object of up to four sub-objects, defining the synchronous API-to-API pathway:

Firstly, a required in-api object.

Secondly, an optional in-tr-js or in-tr-lq object.

Then, a required out-proxy-api-store-response object.

Finally, an optional out-tr-js or out-tr-lq object.
in-apiAn object that defines how the inbound API of the Synchronous API-to-API stage operates.
contentTypeThe incoming message payload format for the Inbound API. Either json or xml.
httpMethodThe REST method that the inbound API of the Synchronous API-to-API stage should be exposed as. One of GET, POST, PUT, PATCH, or DELETE.
httpParametersModeOptionally defines if the inbound API of the Synchronous API-to-API stage supports passing parameters. Default is none.

See the Handling Inbound Parameters section of the in-api stage for more details.
externalApiUrlPathWhen the httpParametersMode value is set to REST, the externalApiUrlPath defines the REST parameter structure that must be included when calling the API.

See the Handling Inbound Parameters section of the in-api stage for more details.
publicAPIOptional boolean flag (true or false). Default is false.

When true, the API will not require an API Management subscription key to call the stage's API endpoint. See also the publicAuth option below.
publicAuthOptional object for enabling alternate API authentication options when publicAPI is set to true, and the standard API Management subscription key authentication has been disabled.

See the Public Authentication Options section of the Inbound API stage for details.
in-tr-js or in-tr-lqAn object that defines how the inbound payload sent to the Synchronous API-to-API stage should be transformed before being sent to the back-end API.

Use either in-tr-js to use a JavaScript transformation, or in-tr-lq to use a Liquid transformation.
contentTypeDefines the incoming payload format (which must match the in-api section's contentType - for example, if the incoming type is json, then the transform must be either json-to-json, or json-to-xml) and expected output format of the transformation (which must be what the back-end API expects to receive).

One of json-to-json, json-to-xml, xml-to-json, or xml-to-xml.
schemaFilenameA filename that defines the JavaScript or Liquid transformation schema, as appropriate for the selected type of transformation.

See the JavaScript transformation or Liquid transformation stage types for more details on the schema formats.
templateVariablesAn optional object of key/value pairs. Prior to deploying the stage, the JavaScript or Liquid transformation schema will be updated to replace any instances of <<KEY_NAME>> in the schema with the corresponding value from this object. This allows a JavaScript or Liquid transformation schema to be more easily used across different stages where only minor differences in the transformation are required.
out-proxy-api-store-response
contentTypeThe outgoing message payload format for the back-end API. Either json or xml.
externalApiBaseUrlThe base URL of the back-end API destination.
externalApiUrlPathThe path of the back-end API destination. (Appended to the externalApiBaseUrl.)
httpMethodThe HTTP method used when calling the back-end API destination. GET, POST, PUT, PATCH and DELETE are supported.
httpParametersModeEither none (default), parameter, or REST. See Outbound API Parameter Options.
headerAn optional object of key-value pairs, which will be included in the headers when the back-end API is called.
out-tr-js or out-tr-lqAn object that defines how the response payload returned to the Synchronous API-to-API stage from the back-end API should be transformed before being returned to the original caller of the stage.

Use either out-tr-js to use a JavaScript transformation, or out-tr-lq to use a Liquid transformation.

When designing the return payload transformation, remember to take into account that the back-end API may return multiple payload formats (e.g. success format vs error format). The transformation will need to take this into account, and be able to handle all possible response formats.

See below for more details.
contentTypeDefines the incoming payload format (from the back-end API) and expected output format of the transformation.

One of json-to-json, or xml-to-json. See below for more details.
schemaFilenameA filename that defines the JavaScript or Liquid transformation schema, as appropriate for the selected type of transformation.

See the JavaScript transformation or Liquid transformation stage types for more details on the schema formats.
templateVariablesAn optional object of key/value pairs. Prior to deploying the stage, the JavaScript or Liquid transformation schema will be updated to replace any instances of <<KEY_NAME>> in the schema with the corresponding value from this object. This allows a JavaScript or Liquid transformation schema to be more easily used across different stages where only minor differences in the transformation are required.

Using the nameExtension Property

While the Synchronous API-to-API stage in Integration Hub has many uses, one common use case is the implementation of SCIM-compatible endpoints as part of Identity Provisioning with the Entra ID Provisioning service, to allow (for example) the write-back of provisioned email address details from Entra ID to an integrated HRIS solution.

In this scenario, the ability to deploy multiple Synchronous API-to-API endpoints that use the same URL path with different HTTP verbs is needed.

For example, the Entra ID implementation of the SCIM requires the /Users/{userId} path to be available via both a GET verb (used to validate that a user exists in the HRIS solution), and via a PATCH verb (used to update the user's email address in the HRIS solution).

Integration Hub's approach to API Interface stage names is that the name property sets the API Management API value (i.e. the API "grouping"), while the operation property sets the API Management operation value (i.e. the endpoint name) and also sets the final part of the URL path for the API endpoint.

This means that creating two Synchronous API-to-API endpoints, grouped in API Management by using the same name value, with the same URL path ending, but different HTTP verbs, is normally not possible.

To overcome this, the nameExtension property allows an additional name extension for the API Management operation value to be defined, allowing multiple Synchronous API-to-API endpoints to be deployed that have the same name and operation values, so that the APIs are grouped together, and have the same URL path ending, but without causing a naming conflict at the API Management operation level.

Tracing Requests from Other Systems

Integration Hub gives each call a correlation ID, and makes a new one for each request by default. To trace a request from the calling system into Integration Hub, send your own correlation ID in the x-klv-ih-client-tracking-id HTTP header. Use a value that is different for each request, so that each call can be found on its own. See Tracing Requests from Other Systems on the Inbound API stage page for more details.

Outbound Transformation Output Format

The outbound transformation "step" in the Synchronous API-to-API stage must produce a JSON-formatted payload, in the following format:

{
  "responseCode": "404", // Optional, if not set, will respond with HTTP 200
  "responseHeaders": {   // Optional object of custom headers to include in response
    "Content-Type": "application/scim+json", // Example
    // Additional headers as required
  },
  "responsePayload": {
    // JSON formatted response payload
  }
}

This payload format allows the Synchronous API-to-API stage's out-tr-js or out-tr-lq step to define not just the response body to return to the caller, but also the response code (if needed), and any custom response headers that need to be set.

A different payload, with a different response code, headers and/or payload body, can be created in the out-tr-js or out-tr-lq step, based on the response body of the back-end API, to allow the Synchronous API-to-API stage to respond differently depending on (for example) if the call to the back-end API was successful, or failed.

The out-tr-js or out-tr-lq step must always produce a JSON payload. If the in-api step is defined with a contentType of xml, then the responsePayload component of the above object will be automatically converted to the equivalent XML structure before transmission back to the caller.

Last updated on