首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在中连接apiary.io REST v1+

在中连接apiary.io REST v1+
EN

Stack Overflow用户
提问于 2019-06-28 01:09:17
回答 1查看 1.4K关注 0票数 0

我需要连接apiary.io REST v1+Google Data Studio

正如我所检查的,我需要用JavaScriptGoogle脚本中开发一个连接器,就像我在这些教程在data中连接和可视化所有数据外部API中所做的那样。

在这一步中,软件制造商piperun REST v1+。有几个代码片段,但我不能让它们在GDS中工作。

不幸的是,我对JavaScript没有太多的经验,我的主要技能是使用T-SQL,但是我可以在Microsoft PowerBI中成功地建立连接。但是,通过插入URLs和access的TOKENS(返回代码200 ),我在Microsoft中成功地建立了连接。

代码语言:javascript
复制
function teste() {

  var url = 'https://api.pipe.run/v1/activities';

  var request = UrlFetchApp;

  request.fetch(url); 

  request.onreadystatechange = function () {
  if (this.readyState === 4) {
      console.log('Status:', this.status);
      console.log('Headers:', this.getAllResponseHeaders());
      console.log('Body:', this.responseText);
    }
  };

  request.send();

  var request = new XMLHttpRequest();

  request.open('GET', 'https://api.pipe.run/v1/activities/activity_id');

               request.setRequestHeader('Content-Type', 'application/json');
  request.setRequestHeader('Token', 'Q3VydGl1IGVzc2Ugam9iPyEgdHJhYmFsaGVjb25vc2NvQHBpcGUucnVu'); // Here I add TOKEN supplied internally by the application

  request.onreadystatechange = function () {
    if (this.readyState === 4) {
      console.log('Status:', this.status);
      console.log('Headers:', this.getAllResponseHeaders());
      console.log('Body:', this.responseText);
    }
  };

  request.send();  
}

即使输入有效的TOKEN,也会发生错误:

请求https://api.pipe.run/v1/activities返回代码401失败。截断的服务器响应:{“成功”:false,"message":“未经授权”}(使用muteHttpExceptions选项检查完整的答案)(第8行,文件“代码”)

因此,我想要帮助找出是否有另一种简单的方法,或者我需要学习什么才能建立到apiary.io REST API v1+的连接。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-28 20:24:00

在朋友开发人员的帮助下,我们使用以下解决方案进行解决:

代码语言:javascript
复制
   function myFunction() {

      var token = 'Q3VydGl1IGVzc2Ugam9iPyEgdHJhYmFsaGVjb25vc2NvQHBpcGUucnVu'
      var url = 'https://api.pipe.run/v1/deals'
      var params = { method:"GET",
                    headers:{Token: token,
                            contentType:'application/json',}
                    };

     var response = UrlFetchApp.fetch(url, params);

     var json = response.getContentText();
     var data = JSON.parse(json);
     Logger.log(response.getContentText());

    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56799898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档