0
function myfunction() {
  var url = "https://storename.myshopify.com/admin/api/2020-10/orders.json";
  var payloaddata =  "orders_number"
  
  var payload = JSON.stringify(payloaddata);
  var username = "<user>";
  var password = "<pass>";

  var response = UrlFetchApp.getRequest(url,{
    method: "GET",
    payload: payload,
    contentType: "application/json",
    headers: { "Authorization": "Basic " + Utilities.base64Encode(username + ":" + password) }
  });

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

any help with Shopify API to google sheet app script? I got an error that says no function getContentText();. Any recommendation ?

HymnZzy
  • 2,357
  • 1
  • 12
  • 23
  • What does the `Logger.log(response)` has? Have you checked the documentation on [getRequest()](https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#getrequesturl)? – Kessy Dec 07 '20 at 09:02

1 Answers1

0

For why it is not working, because there is no such function on the returned object. getRequest documentation states that

Returns the request that is made if the operation were invoked. This method does not actually issue the request.

getContentText is a method of HTTP Response that is returned by fetch.

Moreover, Payload can only be sent for POST requests. Fixing above, your code will be

function myfunction() {
    var url = "https://storename.myshopify.com/admin/api/2020-10/orders.json";
    var payloaddata = "orders_number"


    var payload = JSON.stringify(payloaddata);
    var username = "<user>";
    var password = "<pass>";

    var response = UrlFetchApp.fetch(url, {
        method: "GET",
   //     payload: payload,
        contentType: "application/json",
        headers: {
            "Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)
        }
    });


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

For query params with GET requests, send them via URL.

Bilal Akbar
  • 3,306
  • 1
  • 12
  • 23