【问题标题】:google apps script post request to streak api谷歌应用程序脚本发布请求到条纹 api
【发布时间】:2016-03-16 21:29:41
【问题描述】:

连续 api:https://www.streak.com/api/

我尝试将这个 streak api 与 GAS UrlService 一起使用,并找到了获取请求的正确语法。但我没有找到 put 和 post 的正确语法:

(1) f.e.创建盒子

    var RequestArguments = {
      "contentType": "application/json",
      "headers":{
        "User-Agent": "MY_APP_NAME",
        "Authorization": "Basic " + Utilities.base64Encode(streakApiKey),
       },
     "validateHttpsCertificates" :false,
     "method": "PUT",
     "????": "????"
   }; 

  var result = UrlFetchApp.fetch(RequestUrl,RequestArguments);   

(2) f.e.编辑框

    var RequestArguments = {
     "contentType": "application/json",
     "headers":{
      "User-Agent": "MY_APP_NAME",
      "Authorization": "Basic " + Utilities.base64Encode(streakApiKey),
     },
     "validateHttpsCertificates":false,
     "method": "PUT",
     "????": "????"
   }; 

  var result = UrlFetchApp.fetch(RequestUrl,RequestArguments);

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    我在我的 Chrome 扩展中使用了这种方式,没有尝试过这段代码,但在 GAS 中应该是类似的:

      "url": "https://www.streak.com/api/v1/boxes/"+boxKey+"/fields/"+fieldKey;        
      "type": 'POST',
      "dataType": "json",
      "contentType": 'application/json; charset=utf-8',
      "data": {value: yourValue}
    

    我花了一些时间来找出正确的参数组合(Streak API 文档在这部分不友好),但我在您的代码中看到的内容对我来说还不错。它应该可以工作。

    【讨论】:

      【解决方案2】:

      这是您可以用来编辑现有框中的字段的功能。创建一个新框将遵循相同的格式。

      function editBox(boxKey, fieldKey, value) {
        var url = 'https://www.streak.com/api/v1/boxes/' + boxKey + '/fields/' + fieldKey;
        var params = {
            headers: {Authorization: 'Basic ' + Utilities.base64Encode(STREAK_API_KEY + ":")},
            method: "POST",
            payload: JSON.stringify({
                value: value
            }),
            contentType: 'application/json'
        };
        var field = UrlFetchApp.fetch(url,params );
        return JSON.parse(field.getContentText());
      }
      

      【讨论】:

        【解决方案3】:

        这是有效的:

        function editBox() {
          var boxKey =      "xxx";
          var value = "{value:Test}";
          var fieldKey = "1001";
          //{name:"Deal Size", key:"1001", type:"TEXT_INPUT", lastUpdatedTimestamp:1457089319053}
        
          var url = 'https://www.streak.com/api/v1/boxes/' + boxKey + '/fields/' + fieldKey;
        
          var params = {
            headers: {Authorization: 'Basic ' + Utilities.base64Encode(streakApiKey)},
            method: "POST",
            payload: value,
            contentType: 'application/json'
          };
        
          var result = UrlFetchApp.fetch(url,params );
        
          var string = result.getContentText();
          var Object = JSON.parse(string);    
        
          return Object;
        }
        
        
        function createBox() {
        
          var pipelineKey = "xxx";
          var name = "sample box name";
        
          var url = 'https://www.streak.com/api/v1/pipelines/' + pipelineKey + '/boxes';
        
          var RequestArguments = {
            headers: {"Authorization": "Basic " + Utilities.base64Encode(streakApiKey)},
            method: "PUT",
            payload: {
              name: name
            }
          };
        
          var box = UrlFetchApp.fetch(url,RequestArguments);
        
          var result = JSON.parse(box.getContentText());
        
          return result;
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-08-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-04-10
          相关资源
          最近更新 更多