I am trying to use the ImportJSON.gs script to import data from my WooCommerce Web site directly into a Google Sheet. I have enabled the REST API in WooCommerce and am able to enter the URL directly into Chrome and get an accurate JSON response. The problem I am having is that when using UrlFetchApp.fetch, the data I get back suggests everything in the URL following a ? or & seems to be either truncated or reencoded to something else, but I haven't quite figured out what URL would give this response.
I have created this simple script to test it:
function myFunction() {
var response = UrlFetchApp.fetch("https://kidswonder.net/wp-json/wc-bookings/v1/products/slots?min_date=2023-01-30&max_date=2023-01-31&product_ids=16304");
Logger.log(response.getContentText());
}
The expected JSON response, which I get by entering the URL directly into a browser is:
{"records":[{"date":"2023-01-30T09:00","duration":30,"available":50,"booked":0,"product_id":16304},{"date":"2023-01-30T09:30","duration":30,"available":47,"booked":3,"product_id":16304},{"date":"2023-01-30T10:00","duration":30,"available":48,"booked":2,"product_id":16304},{"date":"2023-01-30T10:30","duration":30,"available":50,"booked":0,"product_id":16304},{"date":"2023-01-30T11:00","duration":30,"available":50,"booked":0,"product_id":16304},{"date":"2023-01-30T11:30","duration":30,"available":50,"booked":0,"product_id":16304},{"date":"2023-01-30T12:00","duration":30,"available":50,"booked":0,"product_id":16304},{"date":"2023-01-30T12:30","duration":30,"available":50,"booked":0,"product_id":16304},{"date":"2023-01-30T13:00","duration":30,"available":45,"booked":5,"product_id":16304},{"date":"2023-01-30T13:30","duration":30,"available":50,"booked":0,"product_id":16304},{"date":"2023-01-30T14:00","duration":30,"available":50,"booked":0,"product_id":16304},{"date":"2023-01-30T14:30","duration":30,"available":50,"booked":0,"product_id":16304},{"date":"2023-01-30T15:00","duration":30,"available":50,"booked":0,"product_id":16304},{"date":"2023-01-30T15:30","duration":30,"available":50,"booked":0,"product_id":16304}],"count":14}
But the actual response I get, which is the same as if I had is:
{"records":[{"date":"2023-02-02T09:00","duration":30,"available":1,"booked":0,"product_id":140},{"date":"2023-02-02T10:00","duration":30,"available":1,"booked":0,"product_id":140},{"date":"2023-02-02T14:00","duration":30,"available":1,"booked":0,"product_id":140},{"date":"2023-02-02T15:00","duration":30,"available":1,"booked":0,"product_id":140},{"date":"2023-02-05T17:00","duration":30,"available":1,"booked":0,"product_id":12314},{"date":"2023-02-05T17:00","duration":30,"available":1,"booked":0,"product_id":12312},{"date":"2023-02-06T10:00","duration":30,"available":1,"booked":0,"product_id":103024},{"date":"2023-02-06T10:00","duration":30,"available":1,"booked":0,"product_id":12312},{"date":"2023-02-06T11:00","duration":30,"available":1,"booked":0,"product_id":103024},{"date":"2023-02-06T11:00","duration":30,"available":1,"booked":0,"product_id":12312},{"date":"2023-02-06T12:00","duration":30,"available":1,"booked":0,"product_id":103024},{"date":"2023-02-06T12:00","duration":30,"available":1,"booked":0,"product_id":12312},{"date":"2023-02-06T13:00","duration":30,"available":1,"booked":0,"product_id":103024},{"date":"2023-02-06T13:00","duration":30,"available":1,"booked":0,"product_id":12312},{"date":"2023-02-06T14:00","duration":30,"available":1,"booked":0,"product_id":103024},{"date":"2023-02-06T14:00","duration":30,"available":1,"booked":0,"product_id":12312},{"date":"2023-02-06T15:00","duration":30,"available":1,"booked":0,"product_id":103024},{"date":"2023-02-06T15:00","duration":30,"available":1,"booked":0,"product_id":12312}],"count":18}
I am planning to use Google spreadsheet API to fetch data from a spreadsheet and render it in my mobile app using Sencha Touch. I have seen few blogs and tutorial which explain how to fetch and parse data but when I am trying the same I am not getting column wise data as attributes in entry object instead I am getting comma separated data in content tag.
To give you an example, here is sample spreadsheet in which I have change headers and data:
https://docs.google.com/spreadsheet/ccc?key=0AkEOCoTxRKgvdDRZUnViSFlOVUF0QUJybkZ6VlBwTkE#gid=0
and here is its feed:
https://spreadsheets.google.com/feeds/list/0AkEOCoTxRKgvdDRZUnViSFlOVUF0QUJybkZ6VlBwTkE/od6/public/values?alt=json
but when I created same spreadsheet by hand from scratch I am not getting gsx$name & gsx$processedlinkurl attribute in JSON. Here is that sheet:
https://docs.google.com/spreadsheet/ccc?key=0AgduEz3vmQUTdHZlSEI4bjN6VnZ5TVpRMFlyOVAtR0E#gid=0
Here is the JSON:
https://spreadsheets.google.com/feeds/list/0AgduEz3vmQUTdHZlSEI4bjN6VnZ5TVpRMFlyOVAtR0E/od6/public/basic?alt=json
To mark first row as header I have frozen first row in my sheet still JSON is not giving me header wise data in JSON.
OK I got the mistake, it is values instead of basic which is to be used in URL while accessing spreadsheet API to get all headers in result which means
Correct URL:
https://spreadsheets.google.com/feeds/list/0AgduEz3vmQUTdHZlSEI4bjN6VnZ5TVpRMFlyOVAtR0E/od6/public/values?alt=json
Wrong URL:
https://spreadsheets.google.com/feeds/list/0AgduEz3vmQUTdHZlSEI4bjN6VnZ5TVpRMFlyOVAtR0E/od6/public/basic?alt=json