Reputation: 571
I'm trying to fetch data from the rainforestqa API but to gain access I need to send my api_key as a header. The code I already have is as follows,
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);
But this returns 405 error. Does anyone have any ideas why this isn't working?
Thanks
Upvotes: 17
Views: 48388
Reputation: 83
I believe you have misspelled the word headers
.
I know it is an old question, but I did not see this answer before and it might help others who arrive this page.
Upvotes: 3
Reputation: 571
It turns out the answer is as follows, I basically got to this via trial and error.
$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);
Upvotes: 40