Outbound Proxy API Stage
The Outbound Proxy API stage allows a remote API service to be called from Integration Hub.
Stage Overview
The Outbound Proxy API stage allows a remote API service to be called from Integration Hub.
Stage Definition File Location
All Outbound Proxy API stages are defined by creating an appropriately formatted JSON definition file in the following location:
Stage JSON Definition File Format
The JSON definition file for an Outbound Proxy API stage is as follows:
{
"name": "api-name",
"operation": "operation-name",
"displayName": "Brief Stage Title",
"description": "Brief description of the stage.",
"enabled": "$env:STATUS_<INTEGRATION_NAME>",
"source": "source-event",
"concurrency": 10,
"contentType": "json",
"externalApiBaseUrl": "$env:BASE_URL",
"externalApiUrlPath": "$env:API_PATH",
"httpMethod": "GET|POST|PUT|PATCH|DELETE",
"header": {
// Custom headers
},
"httpParametersMode": "none|parameter|REST",
"pagedResponse": {
"moreDataField": "JSON Path Expression",
"mergeField": "JSON Path Expression"
},
"failOn2xx": {
"errorJsonPathQuery": "JSON Path Expression"
},
"authentication": {
// See Authentication Options below
},
"additionalRetryHttpCodes": [
409
],
"retryOn4xx": {
"errorCodePath": "error.code",
"errorMessagePath": "error.message",
"errors": [
{
"errorCode": "Code_1",
"errorMessage": "Message 1."
},
{
"errorCode": "Code_2",
},
{
"errorMessage": "Message 2."
}
]
},
"retryPolicy": {
"fastRetryAttempts": 5,
"fastRetryDelay": 10,
"slowRetryAttempts": 23,
"slowRetryDelay": 60
},
"disableRetry": false,
"emitEvent": "_result | previous-stage-name-1",
"emitError": false,
"emitErrorTerminateSuccess": false,
"leaseLockName": "lock-name",
"disablePolling": false,
"preLogTransformSchemaFileName": "schemas/path/to/schema/schema-name.liquid",
"preLogTransformSchemaType": "liquid|javascript",
"preLogTransformFormat": "json|xml|csv"
}
| Property | Description |
|---|---|
name | The API part of the stage name. See API Interface stage names. |
operation | The Operation part of the stage name. See API Interface stage names. |
displayName | Optional (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. |
description | Optional (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. |
enabled | Optional boolean flag (true or false). Default is true.Generally set via a DevOps variable. Controls if the stage is deployed enabled or not. |
source | The source event that the stage subscribes to. See Pub/Sub Model. Alternatively, sources may be supplied, and an array of one or more source events can be subscribed to. |
concurrency | Optional number of concurrent runs permitted for the stage. Default is 10. |
externalApiBaseUrl | The base URL of the remote API destination. |
externalApiUrlPath | The path of the remote API destination. (Appended to the externalApiBaseUrl.) |
httpMethod | The HTTP method used when calling the remote API destination. GET, POST, PUT, PATCH and DELETE are supported. |
header | An optional object of key-value pairs, which will be included in the headers when the remote API is called. |
httpParametersMode | Either none (default), parameter, or REST. See Outbound API Parameter Options. |
pagedResponse | Optional object to configure handling of responses from remote APIs that return paginated data. See the Handling Paginated Responses section below. |
failOn2xx | Optional object to configure handling of responses from APIs that return an HTTP 2xx response code indicating success, but where the payload returned contains details of errors, and it would be desirable for the stage to fail. See the Handling Errors in HTTP 2xx Responses section below. |
authentication | Optional section defining how authentication to the remote API destination is performed, if required. See Outbound API Authentication Options. |
additionalRetryHttpCodes | An optional array of additional retry HTTP codes. By default, the stage will automatically retry the remote API call in the event of a standard "transient error" HTTP response code being received. (See also the retryPolicy section below.) However, if required, additional HTTP response codes can be defined, and if these response codes are received from the remote API, these will also trigger a retry of the remote API call. This is useful when remote APIs do not respect standard HTTP response codes. |
retryOn4xx | An optional object to inspect HTTP 4xx error payloads, and retry under defined conditions. See Outbound API Retry on HTTP 4xx Errors for more details. |
retryPolicy | Optional object defining a custom retry policy. By default, an initial fast retry (with 5 attempts, 10 minutes apart) is followed by a slow retry (23 attempts, 60 minutes apart). Retry attempt values can be set to 0 to disable the fast and/or slow retry steps, if desired. |
disableRetry | Optional boolean flag (true or false). Default is false. When true, the stage does not attempt to retry calls to the remote API if a retryable error is detected. |
emitEvent | When the call to the remote API is successful, the stage will normally terminate. However, under certain circumstances, it may be desirable to continue workflow processing. The optional emitEvent flag can either:Allow the response of the API call made to be output as a message from this stage, by setting the value to a hard-coded string of _result. This makes the Outbound Proxy API Stage behave in the same way as an Outbound Proxy API Store Response Stage, and is preferred, as the stage name is more concise.Allow the payload of a previously run stage to be output as a message from this stage, by setting the value to the name of the relevant previous stage. The stage must have previously been executed in the run history of the overall Integration Hub integration, with the stage's exported payload details being present in the Cloud Event Attributes section. |
emitError | Optional boolean flag (true or false). Default is false. When true, the stage will capture and emit a payload if a non-retryable error is detected, or if a retryable error is detected on the final retry attempt. See below for more info. |
emitErrorTerminateSuccess | Optional boolean flag (true or false). Default is false. When true, and when emitError is also true, the stage will terminate with a Successful state, rather than a Failed state, in the event of an error being detected and emitted.When the stage is configured to operate in this way, the integration should be defined so that a subsequent stage, or series of stages, will be triggered by the emitted error payload to "handle" the error condition in such a way that reporting and alerting on the error (as would happen if the stage terminated with a Failed state) is unnecessary. |
leaseLockName | Optional. See Lease Locking. |
disablePolling | Optional boolean flag (true or false). Default is false. When true, the stage does not attempt to poll the "location" URL (if found) when an HTTP 202 response is returned. See the section below on handling HTTP 202 responses. |
Pre-Logging Transformation
This stage supports the optional pre-logging transformation feature using the following fields:
preLogTransformSchemaFileNamepreLogTransformSchemaTypepreLogTransformFormat
See the Pre-Logging Transformation for details.
Emit Error Payload
In the event that the emitError option has been set to true and:
- a non-retryable error is detected when calling the external API; or
- a retryable error is detected on the final retry attempt
then the stage will emit a payload in the following format:
{
"errorCode": xxx,
"errorPayload": {
// ERROR PAYLOAD FROM REMOTE API HERE
}
}
The event used to emit the payload will be the full stage name with -error appended, e.g. out-proxy-api-stage-name1-stage-name2-error.
Handling HTTP 202 Responses
In the event that the API being called by the Outbound Proxy API stage return an HTTP 202 response code and the response also includes a "location" header, then the stage will automatically call the URL defined by the "location" header value.
If the "location" URL responds with an HTTP 202 response and the response also includes a "location" header, then the process will be repeated.
However, if the "location" URL responds in any other way (e.g. with an HTTP 200 or an HTTP 5xx response code), then this is the result that the stage will complete with.
This process the Outbound Proxy API stage to call APIs that accept a request and that requires "background processing", and to then "poll" the required URL until background processing has been completed and the results are available.
The process will poll the "location" URL up to 49 times, with a 5 second delay between the calls. This means that the background processing will need to complete within around 4 minutes for this process to work. If this is insufficient for the background processing task being called, use the disablePolling feature to disable automatic polling, and handle the process manually in the integration design.
Handling Paginated Responses
In the event that the API being called by the Outbound Proxy API stage returns paginated data, the stage can be configured to retrieve any additional page(s) of data, and merge all of the pages into a single payload, allowing the stage to call an API and pass all of the available data from that API through for processing in Integration Hub.
When needed, this can be configured via the optional pagedResponse object, which contains two values:
| Property | Description |
|---|---|
moreDataField | A JSON Path field selection expression, in bracket notation form, which selects the JSON response payload field that contains the URL that links to the next "page" of data (if there is one). |
mergeField | A JSON Path expression, in bracket notation form, which selects the JSON response payload field that contains the current response's "page" of data. |
For example, consider a typical GET API call to Dynamics 365 which, when called, returns the following (paginated) JSON payload:
{
"@odata.context": "https://hostname.operations.dynamics.com/data/$metadata#CustomersV3(dataAreaId,CustomerAccount)",
"value": [
{
"@odata.etag": "W/\"JzMwNjgwMzI5NCw1NjM3MTQ2MDc2OzAsMDswLDA7MCwwOzIwOTYyOTkyNDksNTYzNzE1ODE5MTsxLDU2MzcxNjQwODA7MCwwOzAsMDswLDA7MCwwOzAsMCc=\"",
"dataAreaId": "Company1",
"CustomerAccount": "Customer1"
},
{
"@odata.etag": "W/\"JzE5MjI4ODEyODYsNTYzNzE0NjA3NzswLDA7MCwwOzAsMDs5OTU2NTQ0MTYsNTYzNzE1ODE5MjsxLDU2MzcxNjQxMjE7MCwwOzAsMDswLDA7MCwwOzAsMCc=\"",
"dataAreaId": "Company1",
"CustomerAccount": "Customer2"
},
{
"@odata.etag": "W/\"JzE3MDk5MDc2ODAsNTYzNzE1NjA3NTswLDA7MCwwOzAsMDs5OTE2MDM3NDksNTYzNzE2ODE5MDsxLDU2MzcxNzc2ODU7MCwwOzAsMDswLDA7MCwwOzAsMCc=\"",
"dataAreaId": "Company2",
"CustomerAccount": "Customer3"
}
],
"@odata.nextLink": "https://hostname.operations.dynamics.com/data/CustomersV3?cross-company=true&$select=dataAreaId%2CCustomerAccount&$skip=3&$top=3"
}
This payload contains two fields of interest with regards to handling the paginated response:
- The
valuefield, which is an array of objects being retrieved, representing the current "page" of results; and - The
@odata.nextLinkfield, which contains the URL that should be called to obtain the "next page" of results.
To configure an Outbound Proxy API stage that would retrieve all of the possible results from the GET API call - no matter how many pages of data there are - there are two key configurations required.
Firstly, ensure that the stage definition includes the pagedResponse object, configured to correctly identify where the "next page" URL and the array of data being returned can be located. In the above example, this would be:
"pagedResponse": {
"moreDataField": "['@odata.nextLink']",
"mergeField": "['value']"
},
Secondly, ensure that the stage is configured so that the API is called in the same way as the "next link" API format is presented. That is, the "next link" API will include at least one variable, but possibly more, indicating how the API knows which "page" of results to return - and the stage must be set up to call the API for the first page of data in the same way as this format.
In the above example, the "next page" URL is in the format:
https://hostname.operations.dynamics.com/data/CustomersV3?cross-company=true&$select=dataAreaId%2CCustomerAccount&$skip=XXX&$top=XXX
with both a skip and a top URL parameter present. As a result, this means that the stage will need to be configured in the following way:
"externalApiBaseUrl": "https://hostname.operations.dynamics.com",
"externalApiUrlPath": "/data/CustomersV3",
"httpMethod": "GET",
"httpParametersMode": "parameter",
"pagedResponse": {
"moreDataField": "['@odata.nextLink']",
"mergeField": "['value']"
},
In addition, given the httpParametersMode is set to parameter, a payload will need to be passed to the stage in the format required (see Outbound API Parameter Options for more details), which in this case, would be:
{
"pathParameters": "?cross-company=true&$select=dataAreaId&$skip=0&$top=3"
}
This payload allows the initial page to be loaded (skipping 0 pages, and asking for 3 results per page), and then the configured pagedResponse details will continue to load and merge subsequent pages of data, until no further pages are found.
Obviously, it will be more efficient to load more than 3 results per page in the above example - a value of $top=3 has been used to simplify the example.
When the pagedResponse feature is enabled, the result of merging the page values (from the payload result specified by the mergeField value) is returned in the stage's output as a top-level array in JSON.
All other details that may be present in the JSON response for each page (e.g. the @odata.context values, etc.) are stripped from the response, and only a single, top-level array of the merged page object values is returned.
This applies even if only one page of data is found.
Please note that paginated response handling is only supported when the API being called uses either parameter or REST mode parameters (as this is required to be able to iterate through the pages of data), and returns a JSON response payload.
Handling Errors in HTTP 2xx Responses
In the event that the API being called by the Outbound Proxy API stage returns an HTTP 2xx response (indicating a successful API call), but the response payload contains information that indicates one or more issues with the API call, the failOn2xx feature can be used to detect these issues, and cause the Outbound Proxy API stage to fail and terminate processing (or, to pass the error payload on to a subsequent stage, by using the emitError feature), instead of treating the HTTP 2xx response as "success".
To do this, include the failOn2xx object in the stage definition, with the following value:
| Property | Description |
|---|---|
errorJsonPathQuery | A JSON Path field selection expression. The expression must be one that returns an array of zero or more JSON objects. If no objects are returned, then the Outbound Proxy API stage will succeed. If one or more objects are returned, then the Outbound Proxy API stage will fail. |
For example, consider a batch processing API call to Dynamics 365 which, when called, returns the following JSON payload that looks something like this:
{
"$content-type": "multipart/mixed; boundary=batchresponse_c369d0d6-b97e-4e89-ae39-f7b92ff03e39",
"$content": "[...]",
"$multipart": [
{
"headers": {
"Content-Type": "multipart/mixed; boundary=changesetresponse_b1fc7af4-0c06-45cb-a336-a761b1d46734",
"Content-Length": "1485"
},
"body": {
"$content-type": "multipart/mixed; boundary=changesetresponse_b1fc7af4-0c06-45cb-a336-a761b1d46734",
"$content": "[...]",
"$multipart": [
{
"headers": {
"Content-Type": "application/http; msgtype=response",
"Content-Transfer-Encoding": "binary",
"Content-ID": "1",
"Content-Length": "1283"
},
"body": {
"$content-type": "application/http; msgtype=response",
"$content": "[...]",
"$applicationHttp": {
"headers": {
"OData-Version": "4.0"
},
"body": {
"error": {
"code": "",
"message": "An error has occurred.",
"innererror": {
"message": "Write failed for table row of type 'Entity'. Infolog: Warning: The value 'VALUE' in field 'FIELD' is not found in the related table 'TABLE'.",
"type": "Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataWriteException",
"stacktrace": "[...]"
}
}
},
"statusCode": 500
}
}
}
]
}
}
]
}
(The response payload has been edited for brevity.)
Although a batch call to Dynamics 365 will return with an HTTP 200 response, the details of the payload indicate that an error has occurred, and it may be desirable for the stage to fail and terminate (or emit the error as a payload for a specific error handling integration pathway), rather than succeeding because of the HTTP 200 OK response.
In this case, the failOn2xx feature flag could be configured in the following way:
"failOn2xx": {
"errorJsonPathQuery": "$..['$multipart'][?(@['body']['$applicationHttp']['statusCode'] > 299)]"
},
This JSON Path expression searches the JSON response body for a field called $multipart that occurs anywhere in the payload where, under the $multipart field, an object containing a structure of body.$applicationHttp.statusCode can be found, and where the statusCode value is more than 299, i.e. any HTTP response code above the 2xx range.
Note the use of bracket notation form in the example, due to the presence of the $ character in one of the fields that needs to be searched for in the payload response.
This expression will return an array of all objects found that match the expression (in the example above, there is only one), causing the stage to fail when errors are found - or to pass if no such errors are found that match based on the expression.
Last updated on