ZebPay Trade API
This endpoint allows users to read order data, create a new order, or cancel a previously placed order. Signature Generation for POST Methods: The following JavaScript code should be added to the Pre-request Script tab in Postman. It automatically generates the required signature and includes the API key and signature in the request headers. // Import crypto for HMAC-SHA256 signature calculation const CryptoJS = require('crypto-js'); // API key and secret const APIKEY = ''; const SECRET = ''; // Generate the current timestamp const timestamp = Date.now(); // Unix time in milliseconds //read boday data and pass update timestamp const body = pm.request.body.raw const payload = JSON.parse(body); payload.timestamp = timestamp; // Stringify the payload const payloadString = JSON.stringify(payload); // Function to calculate HMAC-SHA256 signature function calculateSignature(payload, secret) { const hash = CryptoJS.HmacSHA256(payload, secret); return hash.toString(CryptoJS.enc.Hex); } // Calculate the signature const signature = calculateSignature(payloadString, SECRET); // Set headers dynamically pm.request.headers.upsert({ key: "X-AUTH-APIKEY", value: APIKEY, }); pm.request.headers.upsert({ key: "X-AUTH-SIGNATURE", value: signature, }); // Replace request body with the dynamically generated payload pm.request.body.update(payloadString); Signature Generation for GET Methods: // Import crypto for HMAC-SHA256 signature calculation const CryptoJS = require('crypto-js'); // API key and secret const APIKEY = ''; const SECRET = ''; // Function to calculate HMAC-SHA256 signature function calculateSignature(payload, secret) { const hash = CryptoJS.HmacSHA256(payload, secret); // Use CryptoJS for HMAC return hash.toString(CryptoJS.enc.Hex); // Convert to hexadecimal } // Generate a timestamp const timestamp = Date.now(); // Current Unix timestamp in milliseconds // Access the query parameters from the request URL let queryParams = pm.request.url.query; // Convert query parameters into a key-value object let queryObject = {}; queryParams.each(param => { queryObject[param.key] = param.value; }); // Update or set the parameter dynamically queryObject['timestamp'] = Date.now() // Update 'timestamp' parameter // Convert query parameters to query string const queryString = Object.entries(queryObject) .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`) .join('&'); // Generate the signature const signature = calculateSignature(queryString, SECRET); // Set headers dynamically pm.request.headers.upsert({ key: "X-AUTH-APIKEY", value: APIKEY, }); pm.request.headers.upsert({ key: "X-AUTH-SIGNATURE", value: signature, }); // Update the URL with the query parameters pm.request.url.query.clear(); // Clear existing query params queryString.split('&').forEach((param) => { const [key, value] = param.split('='); pm.request.url.query.add({ key, value }); });