Docs
uapigateway
Operation Guide
Invoke API
Use Postman for Signature

Using Postman for Signatures

Postman is commonly used for debugging backend HTTP services. We can use the POST’s Pre-request Script feature to construct the HTTP request header to complete the signature.

As shown in the figure, fill in the necessary information for signature in Headers. The variable parameters are defined in the {{}} modifier, and the parameters in {{}} in POSTMAN are global variables. We need two global variables in the example: the parameter values of X-Gw-Timestamp and X-Gw-Signatured.

Switch to the Pre-request Script menu, Pre-request Script has built-in javascript interpreter, combined with POSTMAN API, you can modify HTTP request parameters. Due to the different versions of POSTMAN, there are differences in POSTMAN API. For specific API, please refer to this.

The code is as follows:

var stage = "user_prd_stage";
var appKey = "76976226127534999";
var appSecret = "d1bb0aead0fd4f36b7e58eb55de46543";
var timeStamp = Math.ceil(Date.now() / 1000)
var signedString = "X-Gw-Timestamp:"+timeStamp+",X-Gw-App-Key:"+appKey;
var signature = CryptoJS.HmacSHA256(signedString , appSecret).toString(CryptoJS.enc.Base64);
postman.setGlobalVariable("timeStamp" , timeStamp);
postman.setGlobalVariable("X-Gw-SignedString",signedString);
postman.setGlobalVariable("X-Gw-Signature",signature);