Reputation: 23
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!
Upvotes: 1
Views: 6149
Reputation: 34
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);
}
});
}
Upvotes: -1
Reputation: 27348
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."
Upvotes: 4