我正在尝试从雨林qa API获取数据,但要获得访问权限,我需要将api_key作为标头发送。我已经拥有的代码如下,
var header = {
"access-control-allow-headers":"Content-Type",
"CLIENT_TOKEN" : "API-TOKEN"
};
var options = {
"method" : "post",
"header" : header
};
UrlFetchApp.fetch("https://app.rainforestqa.com:443/api/1/runs/TESTNUMBER/tests.json?result=failed", options);
但这会返回 405 错误。有没有人知道为什么这不起作用?
谢谢
原来答案如下,我基本上是通过反复试验得出的。
$var options = {
"async": true,
"crossDomain": true,
"method" : "GET",
"headers" : {
"CLIENT_TOKEN" : "my-api-key",
"cache-control": "no-cache"
}
};
var response = UrlFetchApp.fetch("https://app.rainforestqa.com:443/api/1/runs/test_id/tests.json?result=failed", options);
我相信你拼错了headers
这个词。我知道这是一个老问题,但我以前没有看到这个答案,它可能会帮助到达此页面的其他人。