REST extension

Plugin ID

The plugin ID for REST API is fr.cantor.c4i.RESTDelivery.

Properties

Environment independent parameters (set in extension configuration or properties file)

Property keyDescriptionMandatoryDefault value
configAssetIdThe ID of the asset containing the YAML mappingsYes
connectionThe name of the connection in the c4i.properties fileYes
isKeyInURLtrue to send each object in a single request with the object ID in the URL, false otherwise. Use {id} in URL templateYes
batchSizeThe maximum number of elements to send in a single queryYes
authenticationModeNONE, BASIC_AUTH, API_KEY_TOKEN, API_KEY_BEARER, X_API_KEY, OAUTH2_CLIENT_CREDENTIALS or CUSTOM_TOKENNoNONE
contentTypeContent-Type header value. Authorized values are APPLICATION_JSON (application/json) and TEXT_PLAIN (text/plain;charset=UTF-8)Yes
outputFormatCSV, EXCEL, JSON, JSONL, XML or XMLLYes
headers.{headerName}Any additional header to send in the HTTP call. See section "Headers templating" for more infoNo
lastBatchHeaderIf a value is provided, then the last batch for an object type will have this value as a header. It may produce an additional REST call with an empty bodyNo
cacheConfigThe ID of the asset containing the JCS configurationNo
displayPerfStattrue to display performance statistics (see Performance statistics dedicated page)Nofalse

Environment dependent parameters (set in centralized c4i.properties file)

Property keyDescriptionMandatoryDefault value
destinationURLURL of the target REST API. See section "URL templating" for more infoYes
authenticationModeNONE, BASIC_AUTH, API_KEY_TOKEN, API_KEY_BEARER, X_API_KEY, OAUTH2_CLIENT_CREDENTIALS or CUSTOM_TOKENNoNONE
usernameThe username (Basic Auth) or Client ID (OAuth2)No
passwordThe password (Basic Auth), API Key or Client Secret (OAuth2) in standalone mode onlyNo
readTimeoutThe maximum time of inactivity between two data packets when waiting for the server's response in secondsNo
oAuth2TokenEndpointThe endpoint to retrieve the OAuth2 tokenIf authenticationMode is OAUTH2_CLIENT_CREDENTIALS or CUSTOM_TOKEN
oAuth2ScopeThe OAuth2 token scopeNo
loginQueryScriptThe Asset ID/File path of the script to use to build the custom token callIf authenticationMode is CUSTOM_TOKEN
tokenExtractorScriptThe Asset ID/File path of the script to use to extract the token from the custom token call responseIf authenticationMode is CUSTOM_TOKEN
tokenHeaders.{headerName}Any additional header to send in the custom HTTP token request call.No

Notes

All HTTP queries are performed using the POST method.

Configuration example

extensions.[0].pluginId=fr.cantor.c4i.RESTDelivery
extensions.[0].isKeyInURL=true
extensions.[0].batchSize=100
extensions.[0].outputFormat=JSON
extensions.[0].configAssetId=C4I-Configuration
extensions.[0].additionalHeader1=Execution-Id: {uuid}
extensions.[0].additionalHeader2=MyHeader: Value
extensions.[0].contentType=APPLICATION_JSON
extensions.[0].lastBatchHeader=Last-Batch= true
pluginId=fr.cantor.c4i.RESTDelivery
batchSize=100
outputFormat=JSON
configAssetId=/Path/to/C4I/Configuration.yml
additionalHeader1=Execution-Id: {uuid}
additionalHeader2=MyHeader: Value
contentType=APPLICATION_JSON
lastBatchHeader=Last-Batch= true
licenseAssetId=/Path/to/C4I/License.cat
cacheConfig=/Path/to/JCS/Config.ccf
destinationURL=http://my-web-server.com
username=c4i
password=client_secret
authenticationMethod=OAUTH2_CLIENT_CREDENTIALS
oAuth2TokenEndpoint=https://my-oauth2-endpoint.com/auth/realms/myrealm/protocol/openid-connect/token
oAuth2Scope=my-custom-scope
readTimeout=10

URL templating

The target URL can be templated with :

  1. Context ID using the variable {contextId}
  2. Destination name from YAML configuration file using the variable {destination}
  3. Object ID using the variable {id}

For instance, given the following URL tempate : http://my-web-server.com/{destination}?lang={contextId},

And using the following YAML configuration file :

- Product:
    products[id]:
      ...

- Entity:
    entities[id]:
      ...

While parsing a file in the context fr_FR,

Products will be sent to the following URL : http://my-web-server.com/products?lang=fr_FR.

Entities will be sent to the following URL : http://my-web-server.com/entities?lang=fr_FR.

Using the following URL template : http://my-web-server.com/{destination}/{id}?lang={contextId},

The product with ID PRD0001 will be sent to the following URL : http://my-web-server.com/products/PRD0001?lang=fr_FR.

Header templating

The headers can be templated with the following values :

  • {uuid} : Will generate a unique ID to link all the batches of the same execution

Custom token authentication

When using CUSTOM_TOKEN authentication, you must provide two additional Javascript script parameters, loginQueryScript and tokenExtractorScript.

The first one is used to construct the body of the authentication request. It accepts the following parameters : endpoint, username, password, scope

Example :

function getLoginQueryBody(username, password)
{
    return {
        "username": username,
        "password": password
    };
}
getLoginQueryBody(username, password);

The second one is used to extract the token from the authentication request response. It accepts a single JSON parameter.

Example :

function extractToken(token)
{
    return token.token_type + " " + token.access_token;
}

extractToken(token);
Last Updated: