Integromat: Rename Google Sheet (individual sheet vs entire spreadsheet) - google-sheets-api

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"
}
}]
}

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.

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.

Google sheets unable to parse range

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.

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.

How can I Group Rows via the Google Sheets API?

I'm looking for a way to create a group of rows via the Google Sheets API - is there a way to do this? I can't see to find an API that will do this, but it seems like it should be a fairly common formatting need.
This feature is supported in the UI by selecting a set of rows, right clicking and the option pops up to create a group, see the screenshot linked below. I'm just looking for a way to do that via an API.
Use this --> Range.shiftColumnGroupDepth
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var range = sheet.getActiveRange();
// The column grouping depth is increased by 1.
range.shiftColumnGroupDepth(1);
// The column grouping depth is decreased by 1.
range.shiftColumnGroupDepth(-1);
You can accomplish this through version 4 of the Google Sheets API.
You will need to submit an HTTP POST to this endpoint:
https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}:batchUpdate
You will need to pass a valid JSON request. I created a simple spreadsheet with some rows to group and used this JSON as a test to group rows 14-17:
{
"requests": [
{
"addDimensionGroup": {
"range": {
"dimension": "ROWS",
"sheetId": 0,
"startIndex": 14,
"endIndex": 17
}
}
}
]
}
Note that the startIndex is the row (or column) number that everything will fold into and will remain visible even if you collapse the group, while endIndex is the last element of the group which will remain hidden when the group is collapsed.
The documentation for this is here. If your window is wide enough it will show a "Try this API" pane on the right side. You can enter the spreadsheetId of your sheet and build up the JSON request body and test it to see it work directly on a sheet - if you have it open in another window you should see the update happen almost immediate after you click the "Execute" button.
Creating Column and Row Groups
Column Groups
function createSomeColumGroups() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName("Sheet189");//this is used in the request
var resource='{"requests": [';
for(var i=1;i<25;i+=3) {//start at column 1 and ends at 24 making them in groups of 3
if(i>1){resource+=', ';}
resource+=Utilities.formatString('{"addDimensionGroup": {"range": {"dimension": "COLUMNS","sheetId": %s,"startIndex": %s ,"endIndex": %s}}}',sh.getSheetId(),i,i+2);
}
resource+=']}';
Logger.log(resource);
Sheets.Spreadsheets.batchUpdate(resource, ss.getId());
}
Row Groups
function createSomeRowGroups() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName("Sheet189");
var resource='{"requests": [';
for(var i=1;i<25;i+=3) {
if(i>1){resource+=', ';}
resource+=Utilities.formatString('{"addDimensionGroup": {"range": {"dimension": "ROWS","sheetId": %s,"startIndex": %s ,"endIndex": %s}}}',sh.getSheetId(),i,i+2);
}
resource+=']}';
Logger.log(resource);
Sheets.Spreadsheets.batchUpdate(resource, ss.getId());
}
Don't forget to go the Advanced Google Services and enable Sheets API version 4 and you will also have to enable on the Google Cloud Platform