简体   繁体   中英

Connect apiary.io REST API v1+ in Google Data Studio

I need to connect apiary.io REST API v1+ to Google Data Studio .

As I checked, I need to develop a connector with JavaScript in Google Apps Script , as I checked in these tutorials Connect and visualize all your data in Data Studio and External APIs .

In this step by step software manufacturer, piperun REST API v1+ . There are several code snippets, but I can not make them work in GDS .

Unfortunately I do not have much experience with JavaScript , my main skill is with T-SQL , but I could make the successful connections in Microsoft PowerBI . But I was able to make the connections successfully in Microsoft PowerBI by inserting the URLs and the TOKENS of access, having the return code 200 .

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

And even if you enter a valid TOKEN , the error occurs:

Failed to request https://api.pipe.run/v1/activities returned code 401. Truncated server response: {"success": false, "message": "Unauthorized"} (use the muteHttpExceptions option to examine the complete answer) (line 8, file "Code")

So I would like help finding out if there is another easy way or what I need to learn to be able to establish a connection to apiary.io REST API v1+ .

With the help of a friend developer, we solve with the following solution:

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

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM