【发布时间】:2022-01-08 08:29:48
【问题描述】:
我正在使用 Postman 测试 Coinbase API 端点,挑战在于何时需要分页
为了设置 Postman,我遵循了可用的指南 here,总结如下:
- 添加变量
- coinbase-api-base
- coinbase-api-key
- coinbase-api-secret
- coinbase-api-timestamp
- coinbase-api-签名
- 添加了预请求脚本以生成请求签名
// 1. Import crypto-js library var CryptoJS = require("crypto-js"); // 2. Create the JSON request object var req = { timestamp: Math.floor(Date.now() / 1000), // seconds since Unix epoch method: pm.request.method, path: pm.request.url.getPath(), body: '', // empty for GET requests message: undefined, secret: pm.collectionVariables.get("coinbase-api-secret"), // read value from collection variable hmac: undefined, signature: undefined, }; // 3. Create the message to be signed req.message = req.timestamp + req.method + req.path + req.body; // 4. Create HMAC using message and API secret req.hmac = CryptoJS.HmacSHA256(req.message, req.secret); // 5. Obtain signature by converting HMAC to hexadecimal String req.signature = req.hmac.toString(CryptoJS.enc.Hex); // 6. Log the request console.info("request: ", req); // 7. Set Postman request's authentication headers for Coinbase REST API call pm.collectionVariables.set("coinbase-api-timestamp", req.timestamp); pm.collectionVariables.set("coinbase-api-signature", req.signature);
对于一个简单的请求,一切都很好,例如:
获取 {{coinbase-api-base}}/v2/accounts
那么,如果我添加正文请求参数(如here 解释的那样):
限制=50
要更改默认分页,我得到一个身份验证错误....
“错误”:[ { "id": "authentication_error",
“消息”:“无效签名”
}
问题:
我该如何解决?
请求正文如何与请求签名配合使用...
非常感谢任何帮助建议
谢谢
【问题讨论】:
标签: api authentication pagination coinbase-api