Google Sheets

The easiest way to convert your google sheets into a REST API.

Overview

Some people are using Google Sheet for their daily life activities e.g financial budget, create a guest list, and some people building websites with Google Sheet. Since it is a cloud-based app, you can also use them as a database for your small application or websites. You can easily discard the heavily priced DB’s such as MySQL, PostgreSQL, etc., and use Google Sheets to store the data and manage it in real-time.

We are not saying that Google Sheets eliminates DB’s usage, but for smaller datasets, this can be considered an option.

Getting Started

SlashApi allow you to transform your Google Sheet data into an API without any backend code, so you can easily integrate it into your app.

Prepare your spreadsheet

Each spreadsheet document you want to access must be in a particular format. With a few tweaks to your spreadsheet you can make it compatible with SlashApi.

Make the first row of your spreadsheet as the header

The first row of your sheet will be used as the header. This is the most important part of preparing your sheet, as the names you use here will be used as the property names in the returned objects. Each column in your sheet represents that property’s value.

For example, if your spreadsheet looked like this:

Name Email
John Doe john@domain.com
Jane Doe jane@domain.com

SlashApi will return the above data like this:

{
    "data": [
        {
            "name": "John Doe",
            "email": "john@domain.com"
        },
        {
            "name": "Jane Doe",
            "email": "jane@domain.com"
        }
    ]
}

SlashApi will also ‘camelCase’ your header names to make them more JSON friendly.

Sheet names act as API endpoints

The name of your sheets will be used as the API endpoint name. So if your spreadsheet has a sheet called "Contacts" and another sheet called “Events”, the URLs will look something like:

https://v1.slashapi.com/<team>/google-sheets/<identifier>/contacts
https://v1.slashapi.com/<team>/google-sheets/<identifier>/events

You can also access your sheet with sluggable format, for example if your sheet name contains a space called "Contact Sheet", you can access with URL like this:

https://v1.slashapi.com/<team>/google-sheets/<identifier>/contact-sheet

Create your Google Sheet API

After you create an account and log in to the dashboard, choose Google Sheet on the collections page. To make Google Sheet API you have to Authenticate your Google Account by click on the "Authenticate Account" at the top of the Google Sheet form.

After authenticating you will be redirected back to the SlashApi with a Google Sheet Form. In this form, we just need your spreadsheet id to allow SlashApi connect with your Google Sheet.

Getting your spreadsheet id

Every spreadsheet has a unique identifier called spreadsheetId, containing letters, numbers, hypens or underscores. You can find the spreadsheet ID in a Google Sheets URL:

https://docs.google.com/spreadsheets/d/spreadsheetId/edit#gid=0

API Endpoints

List of available sheets

Returns a list of all available sheets (tabs)

GET
<team>/google-sheets/<identifier>

Response

{
    "data": {
        "38371392": {
            "name": "Contact",
            "slug": "contact"
        }
    }
}

Get Keys

Returns an array with all keys from google sheet (first row of the document)

GET
<team>/google-sheets/<identifier>/keys

Response

{
    "data": [
        "id",
        "Name"
    ]
}

Get Rows

Returns an array with data from google sheet. SlashApi will append a new attribute to the response called row_id to help you identify the row for another Google Sheet endpoints.

GET
<team>/google-sheets/<identifier>/<sheet>

Response

{
    "data": [
        {
            "name": "John Due",
            "row_id": 1
        },
        {
            "name": "Jane Due",
            "row_id": 2
        }
    ]
}

Filtering

Sheet queries are created as valid JSON documents. A query object consists of fields and operators that make up a complete query.

Query example:

/users?q={"name":"John"}

Multiple parameters;

/users?q={"name":"John","age":17}
Logic Operators
Abbr Description Example
$ne Not equal {"field":{"$ne":value}}
$contains field contains the given value {"field":{"$contains":value}}
$in Match any value in array {"field":{"$in":[value1,value2,...]}}
$nin Not match any value in array {"field":{"$nin":[value1,value2,...]}}
$or Logical operator {"$or":[{"field":"value"},{"field":"Another Value"}]}
Conditional Operators
Abbr Description Example
$gt Greater than {"field":{"$gt":value}}
$gte Greater than equal {"field":{"$gte":value}}
$lt Less than {"field":{"$lt":value}}
$lte Less than equal {"field":{"$lte":value}}
$between Matches field value between two numeric values {"field":{"$between":[1,5]}}

Get Single Row

Get specific row from your google sheet

GET
<team>/google-sheets/<identifier>/<sheet>/<row_id>

Response

{
    "data": {
        "name": "John Due",
        "row_id": 1
    }
}

Add new rows

Add multiple new rows into Google Sheet.

POST
<team>/google-sheets/<identifier>/<sheet>

Body

{
    "data": {
        "name": "Jane Due"
    }
}

You can also insert multiple rows on single API call by define the data as an array.

{
    "data": [
        {
            "name": "John Due"
        },
        {
            "name": "Jane Due"
        }
    ]
}

Response

{
    "data": {
        "name": "Jane Due",
        "row_id": 3
    }
}

Update Row

Update specific row on your google sheet

PUT
<team>/google-sheets/<identifier>/<sheet>/<row_id>

Body

{
    "data": {
        "name": "New Due"
    }
}

Response

{
    "data": {
        "name": "New Due",
        "row_id": 3
    }
}

Delete Row

Delete specific row from your google sheet

DELETE
<team>/google-sheets/<identifier>/<sheet>/<row_id>

Response

{
   "message": "Deleted Successfully"
}

Add New Sheet

Add new sheet on your google sheet

POST
<team>/google-sheets/<identifier>

Body

{
    "title": "Your new sheet"
}

Response

{
    "data": {
        "title": "Your new sheet"
    }
}

Delete Sheet

Delete sheet from your google sheet

DELETE
<team>/google-sheets/<identifier>/<sheet>

Response

{
   "message": "Deleted Successfully"
}