Articles in this section

Using hmacOptions

When using the hmac handlebars helper to generate an authentication header or URI parameter, the Celigo platform provides and populates a set of hmacOptions fields you can use to create the signature. hmacOptions is a JSON object that contains fields that are commonly used to create authentication signatures (such as the request body and the URI). The following table lists all available fields:

Note

For demonstration purposes, the examples provided use the following full URL:

https://www.celigo-test.com/this/is/a/test?username=Integrator&domain=IO

Field name

Description

hmacOptions.headers

Path to parameters sent in the request header.

hmacOptions.body

The HTTP request body, in string format.

hmacOptions.bodyParametersMap

Path to parameters sent in request body.

hmacOptions.method

The HTTP request method (verb). For example, PUT, POST, GET, etc.

hmacOptions.http.encrypted

The contents of the http.encrypted field from your HTTP connection. If you store the key in your HTTP connection as hmacKey, it is available for use as hmacOptions.http.encrypted.hmacKey.

hmacOptions.baseURI

The base URI used in the request. In this example, the value is:

www.celigo-test.com

hmacOptions.relativeURI

The relative URI used in the request. In this example, the value is:

/this/is/a/test

hmacOptions.orderedQueryParams

Reorders the query parameters in alphabetical order (except for 'sign' and 'access_token'. ('sign' and 'access_token' won't be present in this hmacOption field')

Caution

Celigo does not check for typos or validate query parameters when using this option.

hmacOptions.urlParameters*

The URL parameters used in the request. In this example, the value is:

username=Integrator&domain=IO

hmacOptions.urlParametersMap

Path to parameters sent in request URL.

hmacOptions.URI*

The full URI used in the request. In this example, the value is:

https://www.celigo-test.com/this/is/a/test?username=Integrator&domain=IO

* Not available with authentication URL parameters.

Examples using hmacOptions with the hmac helper

To create an HMAC-SHA256 digest from the full URI in base64 format:

{{{hmac "sha256" hmacOptions.http.encrypted.hmacKey "base64" hmacOptions.URI}}}

To create an HMAC-SHA256 digest from the request body in hexadecimal format:

{{{hmac "sha256" hmacOptions.http.encrypted.hmacKey "hex" hmacOptions.body}}}

Example using hmacOptions.urlParametersMap.timestamp to create a signature included in the API request

Alibaba requires the following public parameters and service parameters:

Base URL: http://gw.api.taobao.com/router/rest

Public parameters:

method = “aliexpress.solution.order.fulfill”
app_key = “12345678”
session = “test”
timestamp = “2016-01-01 12:00:00”
format = “json”
v = “2.0”
sign_method = “md5”

Service parameters:

service_name = “SPAIN_LOCAL_CORREOS”
out_ref = “1000006270175804”
send_type=“all”
logisitics_no=“ES2019COM0000123456”

The handlebars template to build the request is as follows:

  http://gw.api.taobao.com/router/rest?method=aliexpress.solution.order.fulfill&app_key=12345678&session=test&timestamp={{dateFormat
  "MM-DD-YYYY hh:mm:ss" timestamp}}&format=json&v=2.0&sign_method=md5&logistics_no=ES2019COM0000123456&out_ref=1000006270175804&send_type=all&service_name=SPAIN_LOCAL_CORREOS&sign={{{hmac
  'md5' 'connection.http.encrypted.secret_key' 'hex' (join ‘’ ‘app_key’ ‘12345678’
  ‘format’ ‘json’ ‘logisitics_no’ ‘ES2019COM0000123456’ ‘method’ ‘aliexpress.solution.order.fulfill’
  ‘out_ref’ ‘1000006270175804’ ‘send_type’ ‘all’ ‘service_name’ ‘SPAIN_LOCAL_CORREOS’
  ‘session’ ‘test’ ‘sign_method’ ‘md5’ ‘timestamp’ hmacOptions.urlParametersMap.timestamp
  ‘v’ ‘2.0’)}}}

The above handlebars template generates the following request which includes the required signature:

  http://gw.api.taobao.com/router/rest?method=aliexpress.solution.order.fulfill&app_key=12345678&session=test&timestamp=09-28-2023%2004%3A48%3A24&format=json&v=2.0&sign_method=md5&logistics_no=ES2019COM0000123456&out_ref=1000006270175804&send_type=all&service_name=SPAIN_LOCAL_CORREOS&sign=a70e11b72e9c728d2fc560993410dfe2
19167486085403-hmac2.png
Was this article helpful?
0 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.