Clone Google spreadsheet using Google sheets V4 and give access to teammates - google-sheets-api

I'm Using Google.Apis.Sheets.v4 from my Java project and accessing it using service account. I'm trying to duplicate a spreadsheet to create new one with the same data and different spreadsheet id using V4 API but I couldn't. Is it possible to do so?
And how to add new gmail user to access already existing sheet using Google V4 sheets API?
{
"role":"editor",
"type":"user",
"emailAddress":mohammed_kamal#gmail.com
}

If you plan on copying only a sheet, Sheets API is the right choice in this case but if you want to copy the whole spreadsheet, you need to make use of Drive API's copy file method. You can replicate the behavior by using the below request:
POST https://www.googleapis.com/drive/v3/files/fileId/copy
As for creating the permissions to the already existing spreadsheet by adding new users, you need to make use of Drive API as well and use the request below:
POST https://www.googleapis.com/drive/v3/files/fileId/permissions
With the following body:
{
"role":"editor",
"type":"user",
"emailAddress":mohammed_kamal#gmail.com
}
Note
In both of these requests, the fileId here corresponds to the id of the spreadsheet wanted to make a copy of.
Reference
Sheets API spreadsheets.sheets.copyTo;
Drive API Files:copy;
Drive API Permissions:create.

Related

Is there a SpreadsheetApp.flush() option for the Google Sheets API?

I have a spreadsheet that I send data to it, I generate a 1-minute sleep (import time → time.sleep(60)) in the code to make sure that the calculations have all been done and then I copy the result of these calculations to another page of that same spreadsheet.
In Google Apps Script there is the SpreadsheetApp.flush() option to make sure that everything in the spreadsheet is perfect to continue the code.
But what about when we use the Google Sheets API, is there a way to do this instead of putting a sleep with a random value like I do?
I was curious about that too, so I reviewed the documentation, and it seems that there is no flush() method for Sheets API.
However, I found a workaround that might help so you can make sure that you are working on the latest version of the sheet. I took inspiration from the Writecontrol parameter in Google Docs API.
"Determines the revision of the document to write to and how the
request should behave if that revision is not the current revision of
the document."
So what I was thinking is to use the Drive API Revisions by using the Revisions: list method and get the latest version of the Sheet. After that, use Revision: get to retrieve the latest version of the sheet to work on it.
You can also submit a missing feature, Google might add this method to the Sheets API later on.
Reference:
Flush() method.
Writecontrol Google Docs API.
Changes and revisions overview.
Revisions: list.
Revisions: get.

Connect Google Sheets by C # using the KEY API (not OAuth2)

I want to do a search within a sheet.
I manage to get a list of entries (https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetsID}/values/1?alt=json&key={API KEY})
but am unable to perform a search.
I use API KEY Is it possible to get an example?
Unfortunately, there is no method in Sheets API which lets you perform a search.
This has already been reported on Google's Issue Tracker here. I suggest you star the issue and eventually add a comment as well stating that you are interested in this feature.

Headers are not picking up from the Google sheet in Google big query

I am trying to upload a google sheet to my dataset in the google bigquery. Below are the settings
Uploading configuration snap
I have made the "Header rows to skip" = 1 and =0 as well
Result doesn't pick the header on the top. It shows "string_field_0"
Here is the file with just one header column and 3 values https://docs.google.com/spreadsheets/d/1mnYBiDe-eOauhVa5QbM-BRelW2iwlhQD9lPMR50A9Lk/edit?usp=sharing
What am I doing wrong?
I was getting the same error. Then I realized that I got it because all the columns are in string format. After adding a field in integer format the issue was resolved.
It is important to follow the steps from the official documentation.
We need to take care of:
Retrieving the Google Drive URI by getting shareable link.
Enabling Google Drive access, because accessing data hosted within Google Drive requires an additional OAuth scope. We can use following command to authenticate with Google Drive:
gcloud auth login --enable-gdrive-access
Check if we are granted with required permissions and scopes. Finally, we can create a table.
Keep in mind that for JSON or CSV files, you can check the Auto-detect option to enable schema auto-detect. Schema auto-detection in the web UI is not currently supported for Google Sheets (though it is available using the bq command-line tool and the API).
I hope you find the above pieces of information useful.

The parameters to be passed in fetch API to get data from google sheets

What url should i pass as a parameter of ferch() to connect to my google sheet. Simple google sheet API url is not working as there is no option in it to mention my spreadsheet id. Please help
To get data from a Google Spreadsheet you have to call the spreadsheet.values.get API endpoint by performing a GET request to:
https://sheets.googleapis.com/v4/spreadsheets/YOU SPREADSHEET ID/values/THE RANGE OF DATA YOU WANT TO GET
You can experiment with the API on this link.

How to use Smartsheet- API to export specific data on Excel file

I am trying to find out if it's possible to use Smartsheet API or any other method to export specific columns data from Report Builder results to Excel file rather than the whole column that was generated from it. I am new to Smartheet and if you need better clarification or if there is any method to this approach, please let me know.
You can get the results of a Report via the Smartsheet API. When you make the request the Report is run to give you the current results of the Report just as if you opened it in your browser. There is also a specific request in the Smartsheet API on Reports to get the data provided as an Excel file. With this you can then work with the data in Excel as you need. This request is listed in the Smartsheet API docs here:
http://smartsheet-platform.github.io/api-docs/#get-report-as-excel-csv