我试图获取Wise以将汇率保存到Google,但由于某种原因,返回的数据是不正确的。
它适用于邮递员,但当我通过Google脚本在谷歌页面上发出同样的请求时,脚本数据就不匹配了。
文档中的curl示例
https://api.transferwise.com/v3/quotes/ \
-H "Authorization: Bearer <your client credentials token>"
-H 'Content-type: application/json' \
-d '{
"sourceCurrency": "GBP",
"targetCurrency": "USD",
"sourceAmount": null,
"targetAmount": 110 }'邮递员中的响应:

Google脚本中的请求:
const url = "https://api.transferwise.com/v3/quotes/";
const response = UrlFetchApp.fetch(url, {
"method": "POST",
"headers": {
"Authorization": "Bearer + mytoken",
"Content-Type": "application/json"
},
"muteHttpExceptions": true,
"followRedirects": true,
"validateHttpsCertificates": true,
"contentType": "application/json",
"payload": JSON.stringify({"\\\"sourceCurrency\\\"":"\\\"EUR\\\"","\\\"targetCurrency\\\"":"\\\"USD\\\"","\\\"sourceAmount\\\"":"null","\\\"targetAmount\\\"":"1000"})
});
const data = JSON.parse(response.getContentText())
Logger.log("Response code is %s", response.getResponseCode());
Logger.log(data.rate);
} 控制台上的响应:

API返回的是"1.0176“而不是"0.98015”,我无法发现自己做错了什么。
发布于 2022-10-03 16:46:19
将有效载荷更改为:
"payload": `{
"sourceCurrency": "EUR",
"targetCurrency": "USD",
"souceAmount": 1000,
"targetAmount": null
}`https://stackoverflow.com/questions/73937942
复制相似问题