Google sheets unable to parse range - google-sheets-api

I am posting the following (incomplete code) to Google sheets batch update values:
{"valueInputOption":"USER_ENTERED","data":[{"range":"'Home Sheet'!B2:B2","values":[
And for some reason I am getting:
{
"error": {
"code": 400,
"message": "Invalid data[0]: Unable to parse range: 'Home Sheet'!B2:B2",
"status": "INVALID_ARGUMENT"
}
}
However if you refer to https://developers.google.com/sheets/api/guides/concepts this clearly looks like the range is valid. Interestingly this is only in the Javascript not if I use the PHP sdk.

When accessing a public sheet via URL like this:
https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetID}/values/{sheetName}?key={API Key}
I have to replace the space in the sheet name with %20, or remove the space from the sheet name if possible. Like this:
https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetID}/values/Home%20Sheet!B2:B2?key={API Key}
So this works for me so long as the sheet sharing is set to "Anyone with the link can view."
See this answer for more detailed info.

Related

How to get the link data with pretty text in it from Google Sheet API

I'm getting data from google sheet in CSV format. But when the sheet has a Hyperlink in its cell, like =Hyperlink("URL", "pretty text"), the google sheet only gives me the pretty text not the link, So my question is how can I get both links & pretty text from google sheet.
Thanks for helping me
You will have to make use of the valueRenderOption parameter when making the spreadsheets.values.get API call.
Assuming your cell looks like this:
You can retrieve the following values using different values for the valueRenderOption parameter as this one will determine how values are rendered in the output.
1. If valueRenderOption is FORMATTED_VALUE (which is the default value when making the API call):
GET https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/A1?valueRenderOption=FORMATTED_VALUE
Then the response will look like this:
{
"range": "Sheet1!A1",
"majorDimension": "ROWS",
"values": [
[
"pretty text"
]
]
}
2. If valueRenderOption is UNFORMATTED_VALUE:
GET https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/A1?valueRenderOption=UNFORMATTED_VALUE
Then the response will look like this:
{
"range": "Sheet1!A1",
"majorDimension": "ROWS",
"values": [
[
"pretty text"
]
]
}
3. If valueRenderOption is FORMULA:
GET https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/A1?valueRenderOption=FORMULA
Then the response will look like this:
{
"range": "Sheet1!A1",
"majorDimension": "ROWS",
"values": [
[
"=HYPERLINK(\"URL\", \"pretty text\")"
]
]
}
Therefore, depending on the exact result you want to achieve, it would be best to use the FORMULA parameter as this will retrieve the formula with its link and value as well. This might require some string processing if you simply want the link and its value.
Reference
Sheets API spreadsheets.values.get;
Sheets API ValueRenderOption.

Integromat: Rename Google Sheet (individual sheet vs entire spreadsheet)

I'm working with Integromat and am wanting to rename an individual sheet in a Google Spreadsheet. How can I do this?
Integromat has a number of similar/related options for Google Sheets:
Create a Spreadsheet
Add a Sheet
But neither allows me to update the name of an existing sheet.
Integromat also has an option Make an API Call for Google Sheets.
The Google Sheets API has an HTTP request method for updating properties of spreadsheets, including UpdateSheetPropertiesRequest which is used to update the properties of an individual sheet, specified by the sheet ID. Using this and the SheetProperties object we can update the name of an individual sheet via Integromat as follows:
In Integromat:
Add Google Sheets module Make an API Call
In the URL field enter spreadsheets/your-spreadsheet-id:batchUpdate
Set the method to POST
In the Body field, enter:
{
"requests": [{
"updateSheetProperties": {
"properties": {
"sheetId": "id-of-the-individual-sheet-to-be-updated",
"title": "your new sheet name"
},
"fields": "title"
}
}]
}

Trello REST API: Delete Custom Field item from a Card

How do I delete a Custom Field item from a card, using Trello REST API?
The documentation only mentions updating, not removing an already set value.
The closest I'll get, is setting an empty value, like this:
{
"value": {
"text": ""
}
}
When I'll then fetch the card in JSON format (card url + .json at the end), it's still shows up among other customFieldItems, with an empty value.
If I manually clear the value using Trello in the browser, the custom field item is removed from the card, and no longer shows up in the json format.
How can I achieve the same thing, but using the REST API ?
According to the documentation, this can be done by setting an empty string for value.
i.e. instead of
{
"value": {
"text": ""
}
}
you want to send a request with
{
"value": ""
}
It took me a while to figure this out because the documentation is kind of confusing and has empty strings for everything else as well, but this one particular empty string is useful.

Are Google Spreadsheets' first sheets always given an ID of 0?

I'm using the Google Spreadsheets API and I'm curious as to whether or not the default first sheet, at the time of creating any new sheet, always has an ID of 0. I tried to research about this, but could not find any documentation regarding this.
Should I assume it will always be 0, or should I get it every time just to be on the safe side, in case they change it?
How about this answer?
Situation 1:
When new Spreadsheet is created without the parameter for sheetId, the sheet, which is existing as the 1st index, has the sheet id of 0 (gid=0) as the default value. In the current stage, this is the specification. For example, when the following request body is used to create new Spreadsheet, new Spreadsheet which has a sheet of "Sheet1" is created. And the sheet ID of "Sheet1" is 0.
Request body:
{
"properties": {
"title": "SampleSpreadsheet"
}
}
Endpoint:
POST https://sheets.googleapis.com/v4/spreadsheets
Situation 2:
When new Spreadsheet is created with the parameter for sheetId, the sheet ID can be given using the parameters. For example, when the following request body is used to create new Spreadsheet, new Spreadsheet which has a sheet of "Sheet1" is created. And the sheet ID of "Sheet1" is 123.
Request body:
{
"sheets": [
{
"properties": {
"sheetId": 123
}
}
],
"properties": {
"title": "SampleSpreadsheet"
}
}
Endpoint:
POST https://sheets.googleapis.com/v4/spreadsheets
Result:
Should I assume it will always be 0, or should I get it every time just to be on the safe side, in case they change it?
From above situations, the answer for your above question is as follows.
When new Spreadsheet is created without using the property of sheetId for each sheet, the 1st sheet has the sheet ID of 0.
When new Spreadsheet is created with using the property of sheetId for each sheet, the 1st sheet can have also the sheet ID except for 0.
Reference:
Method: spreadsheets.create
If I misunderstood your question and this was not the direction you want, I apologize.

Remove auto-link formatting from Google Sheet via api

When using Google Sheets Api to create automated reports I've found that any string that ends with ".com" automatically gets formatted as a link (I've attached a picture). I'd like to remove this formatting via the api, Is this possible?
Two examples of the autolink formatting
You can change the hyperlink format to the plain text format using "hyperlinkDisplayType". The endpoint and request body are as follows. As a sample, the request body removes the hyperlink format of cells "A1:A3". I thought that from the image of your question, repeatCell might be suitable for your situation.
Endpoint :
POST https://sheets.googleapis.com/v4/spreadsheets/### spreadsheet ID ###:batchUpdate
Request body :
{
"requests":
[
{
"repeatCell":
{
"cell":
{
"userEnteredFormat":
{
"hyperlinkDisplayType": "PLAIN_TEXT"
}
},
"fields": "userEnteredFormat.hyperlinkDisplayType",
"range":
{
"sheetId": sheetId,
"startRowIndex": 0,
"endRowIndex": 3,
"startColumnIndex": 0,
"endColumnIndex": 1
}
}
}
]
}
Note :
This answer supposes that you can use Sheets API.
Reference :
HyperlinkDisplayType
RepeatCellRequest
If I misunderstand your question, I'm sorry.