1

I would like to make a GET request with Google Script App on a RestAPI. I was planning on using the function fetchAPI(url, params). Here is the list of arguments I can use in parameters: params arguments from https://developers.google.com/

I don't see "body" in the list of arguments. Does that mean it's not possible to make a GET request WITH BODY with the Google script App?

Thanks for you help!

Rubén
  • 24,097
  • 9
  • 55
  • 116
Henri45
  • 13
  • 5
  • 1
    Not only in apps script, but in all cases. – TheMaster Jul 24 '20 at 11:55
  • @TheMaster are you sure? we can use in all cases except google apps script. – doğukan Dec 23 '20 at 05:54
  • 1
    @dgknca [Checking again](https://stackoverflow.com/questions/978061/http-get-with-request-body), it does seem possible but not http compliant at least in server side to do anything with the body. – TheMaster Dec 23 '20 at 05:59
  • @dgknca Having said that, I believe most libraries convert the body to url query parameters. You're probably looking for this answer: https://stackoverflow.com/questions/56200001/jsonp-ajax-in-google-script/56216818 – TheMaster Dec 23 '20 at 06:18
  • @TheMaster unfortunately it doesn't work in my case. I click 'connect' and nothing happens. I guess we need to convert the API working logic to POST. – doğukan Dec 23 '20 at 06:26
  • @dgknca What do you mean by "connect"? – TheMaster Dec 23 '20 at 06:33
  • @TheMaster sorry. I'm trying to bind a data to google data studio. – doğukan Dec 23 '20 at 09:26
  • 1
    @dgknca I guess It's better to ask a new question(where data studio experts might also help) – TheMaster Dec 23 '20 at 09:48

2 Answers2

3

According to the official documentation UrlFetchApp:

GET requests do not accept a payload body.

"the payload (that is, the POST body) for the request. Certain HTTP methods (for example, GET) do not accept a payload."

soMario
  • 22,501
  • 7
  • 19
  • 38
0

An example of using UrlFetchApp: In this example, you can GET the JSON content.

function CallAPI() {
  
  // 
  
  var token = ""; // Example key
  
  // Call the API
  var response = UrlFetchApp.fetch("https://api.something");
  
  // Analyze JSON
  var content = response.getContentText();
  
  Logger.log(content);
  
  var obj = JSON.parse(content, function (key, value) {
  if (key == "status") {
    Logger.log("value status is = " + value);
  } else if (key == "origin")
  {
   Logger.log("The value origin is= " + value);
  }
}); 
  
}