Google App脚本:带有标题的URLFetchApp.fetch [英] Google App Script: URLFetchApp.fetch with header

查看:147
本文介绍了Google App脚本:带有标题的URLFetchApp.fetch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从rainforestqa API中获取数据,但是要获得访问权限,我需要将api_key作为标头发送.我已经拥有的代码如下,

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);

但是这将返回405错误.有谁知道为什么这行不通?

But this returns 405 error. Does anyone have any ideas why this isn't working?

谢谢

推荐答案

原来的答案如下,我基本上是通过反复试验得出的.

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);

这篇关于Google App脚本:带有标题的URLFetchApp.fetch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆