Skip to main content

Using the pre-request script

In Postman, the following code is pasted into the Pre-request Script tab of the collection. Postman runs this script before every request, so the epoch and checksum headers are always fresh.
On the Authorization tab of the collection, Type is set to Bearer Token and the API Key is provided as the token. Postman adds the Authorization: Bearer <API Key> header automatically. On each request, two headers are added that read from the variables:
Why is a pre-request script needed? The signature is computed with HMAC-SHA512, which Postman cannot express declaratively. The pre-request script is the standard place to perform per-request crypto.

FAQ

Where are the API Key and API Secret obtained? Both values are available in the CHIP Control → Settings → Applications page of the merchant portal. The same page can also be used to generate new credentials or revoke existing ones. Why does a request fail even though the script ran? The most common cause is reuse of a previously computed checksum. The script must run on every request (the default behaviour). If Run pre-request script before each request has been disabled in the collection settings, it should be re-enabled.