Skip to content

Create a Canonical Request

Refer to the pseudocode below:

CanonicalRequest = 
        HTTPRequestMethod + '\n' +
        hostname/uri + '\n' +
        formattedQueryParameters + '\n' +
        formattedHeaders + '\n' +
        FormattedRequestParameters

formattedQueryParameters, formattedHeaders, and formattedRequestParameters are sorted key-value pairs of parameters joined by '&'. Each key-value string follows RFC3886 encoding.

For practical insight and examples of constructing canonical requests for online APIs, see Canonical Request Samples for Online APIs.

Examples of Canonical Requests

POST / PUT Method

POST
amazonpay-sandbox.amazon.in/v1/payments/charge

x-amz-algorithm=AWS4-HMAC-SHA384&x-amz-client-id=A2XMNOQAN8MC64&x-amz-date=20200906T043202Z&x-amz-expires=500&x-amz-source=Browser&x-amz-user-agent=Postman&x-amz-user-ip=52.95.75.13
accessToken=Atza%7CI3M2u2aZQ&amount=1.0&attributableProgram=S2SPay&callbackUrl=&chargeId=Order001&currencyCode=INR&intent=Capture&merchantId=A2XMNOQAN8MC64&paymentMetaData=&referenceId=Order001&selectedPaymentInstrument=AmazonPayLater

Note

For the POST / PUT API, as there are no query parameters, pass an empty string.

GET Method

GET
amazonpay-sandbox.amazon.in/v1/payments/charge
merchantId=A2XMNOQAN8MC64&txnId=order001&txnIdType=MerchantTxnId
x-amz-algorithm=AWS4-HMAC-SHA384&x-amz-client-id=A2XMNOQAN8MC64&x-amz-date=20200906T055702Z&x-amz-expires=500&x-amz-source=Browser&x-amz-user-agent=Postman&x-amz-user-ip=52.95.75.13

Note

For the GET API, as there are no body parameters, add a new line character after the headers.

Verify Response Signatures

To ensure the authenticity of response signatures, review these sample canonical response formats for verification.

Example Canonical Response for POST Method

POST
amazonpay-sandbox.amazon.in/v1/payments/charge

x-amz-algorithm=AWS4-HMAC-SHA384&x-amz-date=20200906T071710Z&x-amz-request-id=ab6e5e05-1f15-48a1-ae39-84fd9ae62a17
amazonChargeId=S04-9469628-4357128&amazonPayUrl=url&chargeId=Order001&currencyCode=INR&merchantId=A2XMNOQAN8MC64&requestedAmount=1.0&status=CapturePending

Example Canonical Response for GET Method

GET
amazonpay.amazon.in/v1/payments/charge

x-amz-algorithm=AWS4-HMAC-SHA384&x-amz-date=20200906T072009Z&x-amz-request-id=33c6c2f3-7de0-4e31-bb5e-7e637da8a04d
amazonChargeId=S04-9469628-4357128&amazonPayUrl=url&chargeId=Order001&currencyCode=INR&merchantId=A2XMNOQAN8MC64&requestedAmount=1.0&status=CapturePending

Note

As responses are returned in the body, canonical requests for both POST and GET methods follow the same pattern for signature verification.