Google Sheet API JavaScript

How to use the Google Sheet API using JavaScript.

How to use the Google Sheet API using JavaScript.

There are two ways to do this:

  1. Directly use the Google Sheet API. The downside of this being it takes a significant amount of time to learn and setup all the configuration.
  2. Just use sheet2api. This takes care of all that configuration for you, all you need is the URL to your Google Sheet spreadsheet to get started.

Easy setup

  1. Install the JavaScript package with npm.
  2. npm install sheet2api-js --save
  3. Run Google Sheet API request with JavaScript.
  4. import Sheet2API from 'sheet2api-js';
    
    const url = 'https://sheet2api.com/v1/FgI6zV8qT121/characters/';
    const options = {};
    Sheet2API.read(url, options).then(function(result){
        console.log(result);
    }, function(error){
        console.log(error);
    });
  5. Create and use your own sheet2api API.

Examples

Here are some ready to use Google Sheet API examples using the JavaScript client. Simply copy them into your project and you're good to go.

Read all rows

// Returns all rows from the first Sheet.
import Sheet2API from 'sheet2api-js';

const url = 'https://sheet2api.com/v1/FgI6zV8qT121/characters/';
const options = {};
Sheet2API.read(url, options).then(function(result){
    console.log(result);
}, function(error){
    console.log(error);
});

Read rows which match search terms

// Returns all rows from the first Sheet, filtered by search terms.
import Sheet2API from 'sheet2api-js';

const url = 'https://sheet2api.com/v1/FgI6zV8qT121/characters/';
const options = {query: { 'Name': 'Bugs Bunny' }};
Sheet2API.read(url, options).then(function(result){
    console.log(result);
}, function(error){
    console.log(error);
});

Add a new row

// Adds a new row to the Sheet.
import Sheet2API from 'sheet2api-js';

const url = 'https://sheet2api.com/v1/FgI6zV8qT121/characters/';
const newRowData = { 'Favourite Thing': 'Carrots', 'Name': 'Bugs Bunny' };
const options = {};
Sheet2API.write(url, options, newRowData).then(function(result){
console.log(result);
}, function(error){
console.log(error);
});

Update existing rows matching a search query

// Adds a new row to the Sheet.
import Sheet2API from 'sheet2api-js';

const url = 'https://sheet2api.com/v1/FgI6zV8qT121/characters/';
const updateWithData = { "Favourite Thing": "Beer", "Name": "Bugs Bunny" };
const options = {query: { 'Name': 'Bugs Bunny' }};
Sheet2API.update(url, options, updateWithData).then(function(result){
  console.log(result);
}, function(error){
  console.log(error);
});

For more in-depth examples check out the Github code repository.


It's as easy as that 🎉.

If you need help, please feel free to send a message via the contact page.

Start using sheet2api now

Be up & running in seconds.