Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Martin91/03efa7e5ef21f6f0e92ebacad684ebe0 to your computer and use it in GitHub Desktop.
Save Martin91/03efa7e5ef21f6f0e92ebacad684ebe0 to your computer and use it in GitHub Desktop.

Revisions

  1. Martin91 revised this gist Mar 25, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion postman-pre-request-script-for-shopee-openapi.js
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,5 @@ var secretKey = pm.collectionVariables.get("secret_key");
    var hash = CryptoJS.HmacSHA256(signatureBaseString, secretKey).toString(CryptoJS.enc.Hex);
    console.log("signature is: ", hash);

    pm.request.headers.add({key: "Authorization", value: hash});
    pm.request.headers.add({key: "Authorization", value: hash});
    pm.request.headers.add({key: "Content-Type", value: "application/json"});
  2. Martin91 revised this gist Mar 24, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions postman-pre-request-script-for-shopee-openapi.js
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@ pm.collectionVariables.set("timestamp", timestampNow);
    var host = pm.collectionVariables.get("host");
    var path = pm.request.url.getPath();
    var requestURL = host + path;
    // https://github.com/postmanlabs/postman-app-support/issues/5043#issuecomment-414301254
    var requestBody = Property.replaceSubstitutions(pm.request.body.raw, pm.collectionVariables.toObject())

    var signatureBaseString = requestURL + "|" + requestBody;
  3. Martin91 revised this gist Mar 24, 2020. No changes.
  4. Martin91 renamed this gist Mar 24, 2020. 1 changed file with 0 additions and 0 deletions.
  5. Martin91 revised this gist Mar 24, 2020. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions pre-request-script.js
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,7 @@ pm.collectionVariables.set("timestamp", timestampNow);
    var host = pm.collectionVariables.get("host");
    var path = pm.request.url.getPath();
    var requestURL = host + path;
    console.log("requestURL: ", requestURL);
    var requestBody = Property.replaceSubstitutions(pm.request.body.raw, pm.collectionVariables.toObject())
    console.log("requestBody: ", requestBody);

    var signatureBaseString = requestURL + "|" + requestBody;
    var secretKey = pm.collectionVariables.get("secret_key");
  6. Martin91 created this gist Mar 24, 2020.
    20 changes: 20 additions & 0 deletions pre-request-script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    var CryptoJS = require("crypto-js");
    var Property = require('postman-collection').Property;

    var now = new Date();
    var timestampNow = parseInt(now.getTime() / 1000);
    pm.collectionVariables.set("timestamp", timestampNow);

    var host = pm.collectionVariables.get("host");
    var path = pm.request.url.getPath();
    var requestURL = host + path;
    console.log("requestURL: ", requestURL);
    var requestBody = Property.replaceSubstitutions(pm.request.body.raw, pm.collectionVariables.toObject())
    console.log("requestBody: ", requestBody);

    var signatureBaseString = requestURL + "|" + requestBody;
    var secretKey = pm.collectionVariables.get("secret_key");
    var hash = CryptoJS.HmacSHA256(signatureBaseString, secretKey).toString(CryptoJS.enc.Hex);
    console.log("signature is: ", hash);

    pm.request.headers.add({key: "Authorization", value: hash});