Add data to google sheet api

API Connector is a powerful, easy-to-use extension that pulls data from any API into Google Sheets. Start quickly with a library of ready-to-use APIs, or create your own custom connections to the data sources you choose.

👇 More info

✨ Standard (free) features:
*Free, unlimited requests through the IMPORTAPI() custom function 
*Access thousands of preset requests through a built-in API library
*Visual field editor to filter and re-arrange fields
*Save your API requests for future access
*Choose whether new data should overwrite or append to existing data
*Use cell values in API requests for dynamic queries
*Four built-in JSON-to-Sheets converter algorithms
*GET / POST / PUT / PATCH /  DELETE support
*Works with all major data formats (JSON, XML, and CSV)
*Log timestamps and request URLs to your output sheet
*Import Curl commands and preset request files
*Preview JSON output
*JMESPath query language support for filtering API results
*250 monthly sidebar requests, 3 saved requests

_______________________________________________________________________________________

🔥 Pro features:
*Schedule API pulls to refresh automatically
*Set trigger execution order
*Cycle through a list of stacked requests
*Automatically handle pagination
*Higher save/run limits
*Connect to APIs by clicking a button (OAuth)
_______________________________________________________________________________________

✅ Ready-to-use Integrations:
➜AccuWeather, AdRoll, Ahrefs, Airtable, API-Football, Asana, BambooHR, Binance, BscScan, Coinbase, CoinMarketCap, CryptoCompare, Facebook Ads, Facebook Pages, Github, Google Ads, Google Analytics, Google Calendar, Google Classroom, Google PageSpeed Insights, Google Search Console, Harvest, Hubspot, Instagram Insights, Jira, Klaviyo, LinkedIn Ads, LinkedIn Pages, Mailchimp, OpenSea, OpenWeatherMap, Pipedrive, Pinterest Ads, Procore, QuickBooks, Quora Ads, Reddit, Spotify, Strava, Stripe, TD Ameritrade, Trello, Twitter, Vimeo, Xero, YouTube Analytics, YouTube Public Data,  Zendesk, Zoho CRM + many more interesting, unique, and popular data APIs. This is a totally flexible add-on that connects to almost any platform, so you can build what you want.

_______________________________________________________________________________________

⭐️ Trial
When you install this add-on, you automatically enter a 14-day free trial that activates all premium features. After 14 days, you will be switched to the free plan. 

_______________________________________________________________________________________

📓 Beginner-friendly templates & tutorials:
https://mixedanalytics.com/knowledge-base/

💬 Fast, friendly support from Mixed Analytics
https://mixedanalytics.com/contact/

🧑‍🤝‍🧑 User forum
https://www.reddit.com/r/api_connector/

Google Sheets, part of Google Workspace, allows teams to create and share spreadsheets online and has grown into a widely used business tool. For many processes, all you need is a shared spreadsheet and a robot using it!

Which automation library should you use?

The RPA.Cloud.Google library, part of RPA Framework, enables interaction with Google Sheets.

Installation and setup

Your robots will need to authenticate with Google to be able to interact with Google Sheets spreadsheets, using the concept of service accounts. The account used by the robot will then need to be added as a collaborator to the sheet(s) you want to access.

Create a Google Service Account

To access the data stored in Google Sheets, you will need to create a service account and get a set of OAuth2 credentials from the Google API Console.

  1. Access the Google APIs Console while logged into your Google account.
  2. Create a new project and give it a name.
    Add data to google sheet api
  3. Click on ENABLE APIS AND SERVICES.
  4. Find and enable the Google Sheet API.
    Add data to google sheet api
  5. Create new credentials to the Google Sheets API. Select Other UI from the dropdown and select Application Data. Then click on the What credentials do I need? button.
    Add data to google sheet api
  6. On the next screen, choose a name for your service account, assign it a role of Project->Editor, and click Continue.
    Add data to google sheet api
  7. The credentials JSON file will be downloaded by your browser.

    The credentials file allows anyone to access your cloud resources, so you should store it securely. More information from Google.

  8. Find the downloaded file and rename it to service_account.json.

Create a new Google Sheet and add the Service Account as an editor to it

  1. Create or select an existing Google Sheet.
  2. Open the service_account.json file and find the client_email property.
  3. Click on the Share button in the top right, and add the email address of the service account as an editor.
    Add data to google sheet api

    If you want only to allow the account read access to the spreadsheet, assign it the Viewer role instead.

  4. Take note of the ID of the Google Sheet document, which is contained in its URL, after the /d element. So, for example, if the URL of your document is https://docs.google.com/spreadsheets/d/1234567890123abcf/edit#gid=0, the ID will be 1234567890123abcf.

Robot example

Now that our account setup is complete, we will build a robot that:

  1. Reads the existing data from a Google Spreadsheet and logs it.
  2. Adds more data to the Google Sheet.

Here's our example spreadsheet with some test data:

Add data to google sheet api

Create a new robot and add the RPA.Cloud.Google library

  1. Create a new robot using the VS Code Robocorp extension.
  2. Edit the conda.yaml file in your robot like this:

channels:
  - conda-forge
dependencies:
  - python=3.9.13
  - pip=22.1.2
  - pip:
      - rpaframework-google==6.0.0

The google package in RPA Framework is not included by default because of the size of its dependencies. By adding the - rpaframework-google==6.0.0 line you are adding it explicitly to your robot.

Robot script

Important! Remember to add the service_account.json file to the root directory of your robot.

*** Settings ***
Documentation       An example robot that reads and writes data
...                 into a Google Sheet document.

Library             RPA.Cloud.Google

Suite Setup         Init Sheets    service_account.json


*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10


*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ...    ${SHEET_ID}
    ...    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END

Add values to the Google Sheet
    ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
    Insert Sheet Values
    ...    ${SHEET_ID}
    ...    ${SHEET_RANGE}
    ...    ${values}
    ...    ROWS

Robot script explained

*** Settings ***
Documentation       An example robot that reads and writes data
...                 into a Google Sheet document.

Library             RPA.Cloud.Google

Suite Setup         Init Sheets    service_account.json

In the *** Settings *** section, the Documentation setting explains what our robot does. We then add the RPA.Cloud.Google library. Finally, we use the Suite Setup setting to initialize the Google Sheets client. This way, it will be initialized only once, even if our robot has multiple tasks.

You can learn more about Suite Setup and Teardown in the Robot Framework User Guide.

*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10

In the *** Variables *** section, we set two variables:

  • ${SHEET_ID} will hold the id of our Google Sheet document.
  • ${SHEET_RANGE} is the range of cells that we want to work on, written in A1 notation. In our case, the area we are interested in in our spreadsheet starts from the A2 cell, and ends with the D10 cell of the first sheet, so our value will be Sheet1!A2:D10.

*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ...    ${SHEET_ID}
    ...    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END

In this task, we are reading the rows specified by the ${SHEET_RANGE} of our Google Sheet, which is identified by the ${SHEET_ID}, into the ${spreadsheet_content} variable.

The Get Sheet Values keyword returns a dictionary with a values item containing a list of rows. To make the robot more robust, we check the existence of the values key before accessing it (an empty sheet would cause the values to be missing). Using the Log Many keyword, we can log that row data:

Add data to google sheet api

*** Tasks ***
Add values to the Google Sheet
    ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
    Insert Sheet Values
    ...    ${SHEET_ID}
    ...    ${SHEET_RANGE}
    ...    ${values}
    ...    ROWS

In this task, we add some arbitrary data to a new row in the spreadsheet.

  1. Using the Evaluate keyword, we create a variable with the values for the row.
  2. We pass the values, the sheet id, and range to the Insert Sheet Values keyword. The values will be added to the first available row using the ROWS major dimension option.

Add data to google sheet api

Storing the credentials in Control Room Vault

You should never include passwords or credential files directly into the code of your robot. Instead of reading the credentials from the service_account.json file, our robot can use the vault feature of Control Room.

  1. Set up your robot to run in Control Room

  2. Create a new vault in the robot's workspace. Assign it the name GoogleSheets.

  3. Create a new secret in the vault. Give it a key of service_account, and paste the contents of the service_account.json file into the value field:

    Add data to google sheet api

  4. Modify the ***Settings*** section of the script to configure the RPA.Cloud.Google library to use the vault:

    *** Settings ***
    Documentation       An example robot that reads and writes data
    ...                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    ...                 vault_name=GoogleSheets
    ...                 vault_secret_key=service_account
    
    Suite Setup         Init Sheets    use_robocorp_vault=True
    

August 31, 2022

How do I add data to Google Sheets?

Enter text or data: Click a cell and enter text. Insert more items: Click Insert and add charts, images, drawings, functions, notes, and more. Note: You can also add a function to a cell by typing =. To see which functions are available, see the Google spreadsheets function list.

How do I add API to Google Sheets?

Example 1: Connecting Google Sheets to the Numbers API.
Step 1: Open a new Sheet. ... .
Step 2: Go to the Apps Script editor. ... .
Step 3: Name your project. ... .
Step 4: Add API example code. ... .
Step 5: Run your function. ... .
Step 6: Authorize your script. ... .
Step 7: View the logs. ... .
Step 8: Add data to Sheet..

Does Google Sheets have an API?

The Google Spreadsheets data API is an extension of the GData API protocol, which you can use to create programs that interact with Google Spreadsheets.

How do I append data in Google Sheets using Python?

Create a project and service account. ... .
Create JSON credentials file. ... .
Share your google sheet to the service account. ... .
Access google sheet using libraries. ... .
Write or Append the dataframe to Google Sheet..