Get all fields from google spreadsheet with api v4 - google-apps-script

I'm setting up a project in NodeJS and for testing I get the information from a spreadsheet in JSON format from the following page: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet
To obtain the information of a sheet, in the spreadsheetId field I put the ID of the spreadsheet and in the range field the name of the sheet.
This is the JSON I get:
{
"spreadsheetId": "{spreadsheetId}",
"valueRanges": [
{
"range": "Parameters!A1:Z1000",
"majorDimension": "ROWS",
"values": [
[
"Country",
"COLOMBIA"
]
]
}
]
}
What I want is to show all the fields of the sheet to obtain the title and the modification and creation dates. To do this, in the fields field, I am putting the title string but I get the following error:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "title",
"description": "Error expanding 'fields' parameter. Cannot find matching fields for path 'title'."
}
]
}
]
}
}
I have tried putting * but I get the same JSON.
My problem: How can I get the date of creation and the date of last modification of the spreadsheet?

you must use this endpoint to get a spreadsheet properties: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/get

Related

People API getting error when Age Ranges is specified

I have tried with People contact create API but I am getting error. I believe the ENUM data is correct
This happens for Skills and Age ranges
{
"error": {
"code": 400,
"message": "person.age_ranges is a read only field.",
"status": "INVALID_ARGUMENT"
}
}
People.People.createContact( {"skills": [
{
"value": "Playing"
}
],
"ageRanges": [
{
"ageRange": "TWENTY_ONE_OR_OLDER"
}
],
})
Answer:
The ageRanges[] field can not be set as it is a read-only field.
More Information:
As per the Person resource in the documentation:
ageRanges[]
object (AgeRangeType)
Output only. The person's age ranges
As this is an output only value, it can not be written to by calling people.createContact.

Why can't I submit a record to Zoho Sales Order API?

I'm trying to insert a record using the Zoho API, and I keep receiving a cryptic INVALID_DATA error message.
I've tried using their sample code which, of course, produces another error. And the sample code they provide for running in Postman also produces an error.
Their docs are lacking and inconsistent, and nobody is getting back to me on their message boards, and I'm getting desperate as I need to have this done today. Can anyone see what I'm doing wrong?
This is what I'm submitting via Postman
{
"data": [
{
"Owner": {
"id": "3938209039489388001"
},
"Contact_Name": {
"id": "398129039938498309"
},
"Subject": "Test",
"Product_Details": [
{
"product": {
"id": "1234567"
},
"quantity": 1
}
]
}
]
}
This is the error response
{
"data": [
{
"code": "INVALID_DATA",
"details": {
"api_name": "product",
"index": 0,
"parent_api_name": "Product_Details"
},
"message": "invalid data",
"status": "error"
}
]
}
The solution was to POST a product first, then grab that product ID and insert it under Product_Details. This is not documented, so I assumed the product would be created automatically, which it wasn't.

Google fit API add multiple data type based on scope

I am using google fit API with multiple user scopes. How can I add multiple data type for each source. If possible, why I cannot add this as a datasource.
{
"dataStreamName":"MyDataSource",
"type":"derived",
"application":{
"detailsUrl":"http://example.com",
"name":"Foo Example App",
"version":"1"
},
"dataType":[
{
//1st data type
"name":"com.google.step_count.delta",
"field":[
{
"name":"steps",
"format":"int"
}
]
},
{
//2nd data type
"name":"com.google.calories.bmr",
"field":[
{
"name":"calories",
"format":"float"
}
]
}
],
"device":{
"manufacturer":"Example Manufacturer",
"model":"ExampleTablet",
"type":"tablet",
"uid":"1000001",
"version":"1.0"
}
}
And I got a response of
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"dataType\" at 'data_source': Proto field is not repeating, cannot start list.",
"errors": [
{
"message": "Invalid JSON payload received. Unknown name \"dataType\" at 'data_source': Proto field is not repeating, cannot start list.",
"reason": "invalid"
}
],
"status": "INVALID_ARGUMENT"
}
}
But when I only add one scope which is like this
{
"dataStreamName":"MyDataSource",
"type":"derived",
"application":{
"detailsUrl":"http://example.com",
"name":"Foo Example App",
"version":"1"
},
"dataType":{
"name":"com.google.step_count.delta",
"field":[
{
"name":"steps",
"format":"integer"
}
]
},
"device":{
"manufacturer":"Example Manufacturer",
"model":"ExampleTablet",
"type":"tablet",
"uid":"1000001",
"version":"1.0"
}
}
It returns me 200 which is successful. Did I miss something or is what I am trying to do possible? Thanks.
Google fit API reference
https://developers.google.com/fit/rest/v1/reference/users/dataSources/create
I believe the nesting your trying to do has to go at the dataField level rather than the dataType level.
dataType.field[]
I think this because I noticed that 'field[]' is a collection while dataType is not.

Sending a request without specifying the fields in the body

I'm trying to send several PUT request to a specific endpoint.
I am using a CSV file within the columns and values, the name of the different columns reference the different variables inside the body, do you get me?
This is the endpoint:
{{URL_API}}/products/{{sku}} --sku is the id of the product, i created that variable because i use it to pass the reference
This is the body that i use:
{
"price":"{{price}}",
"tax_percentage":"{{tax_percentage}}",
"store_code":"{{store_code}}",
"markup_top":"{{markup_top}}",
"status":"{{status}}",
"group_prices": [
{
"group":"{{class_a}}",
"price":"{{price_a}}",
"website":"{{website_a}}"
}
]
}
I don't want to use the body anymore.. sometimes some products have more tan 1 group of prices, i mean:
"group_prices": [
{
"group":"{{class_a}}",
"price":"{{price_a}}",
"website":"{{website_a}}"
},
{
"group":"{{class_b}}",
"price":"{{price_b}}",
"website":"{{website_b}}"
}
Is it possible to create something like this in the CSV file?
sku,requestBody
99RE345GT, {JSON Payload}
How should i declare the {JSON Payload}?
Can you help me?
EDIT:
This is the CSV file i used:
sku,price,tax_percentage,store_code,markup_top,status,class_a,price_a,website_a
95LB645R34ER,147000,US-21,B2BUSD,1.62,1,CLASS A,700038.79,B2BUSD
I want to pass the JSON within the CSV file, i mean
sku,requestBody
95LB645R34ER,{"price":"147000","tax_percentage":"US-21","store_code":"B2BUSD","markup_top":"1.62","status":"1","group_prices":
[{ "group":"CLASS A","price":"700038.79","website":"B2BUSD"}]}
Is it okay?Should i specify anything on the request body or not? I read the documentation posted in POSTMAN website but i did not find an example like this.
As you're using JSON data as a payload, I would use a JSON file rather than a CSV file in the Collection Runner. Use this as a template and save it as data.json, it's in the correct format accepted in the Runner.
[
{
"sku": "95LB645R34ER",
"payload": {
"price": "147000",
"tax_percentage": "US-21",
"store_code": "B2BUSD",
"markup_top": "1.62",
"status": "1",
"group_prices": [
{
"group": "CLASS A",
"price": "700038.79",
"website": "B2BUSD"
}
]
}
},
{
"sku": "MADEUPSKU",
"payload": {
"price": "99999",
"tax_percentage": "UK-99",
"store_code": "BLAH",
"markup_top": "9.99",
"status": "5",
"group_prices": [
{
"group": "CLASS B",
"price": "88888.79",
"website": "BLAH"
}
]
}
}
]
In the pre-request Script of the request, add this code. It's creating a new local variable from the data under the payload key in the data file. The data needs to be transformed into a string so it's using JSON.stringify() to do this.
pm.variables.set("JSONpayload", JSON.stringify(pm.iterationData.get('payload'), null, 2));
In the Request Body, add this:
{{JSONpayload}}
In the Collection Runner, select the Collection you would like to run and then select the data.json file that you previously created. Run the Collection.

Asana- Invalid Field

I'm POST'ing the following JSON to asana's "tasks" endpoint.
{
"data": {
"options": {
"fields": [
"name",
"notes"
]
},
"workspace": <valid number>,
"assignee": <valid number>
}
}
It's giving me a "Invalid field" error every time. I've read through the API a few times now and this JOSN looks exactly how the API says it should. Any ideas?
Asana API for those of you who want to help out: Asana API Documentation
(I work for Asana)
The "options" field is a sibling of the "data" field, not a child. This is mentioned in the docs, but perhaps we aren't providing clarifying examples to make it more obvious.
If you change your request to look like this:
{
"options": {
"fields": [
"name",
"notes"
]
},
"data": {
"workspace": <valid number>,
"assignee": <valid number>
}
}
things should work.