The easiest way to convert your google sheets into a REST API.
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.
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.
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.
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 | |
---|---|
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.
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
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.
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
Returns a list of all available sheets (tabs)
{
"data": {
"38371392": {
"name": "Contact",
"slug": "contact"
}
}
}
Returns an array with all keys from google sheet (first row of the document)
{
"data": [
"id",
"Name"
]
}
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.
{
"data": [
{
"name": "John Due",
"row_id": 1
},
{
"name": "Jane Due",
"row_id": 2
}
]
}
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}
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"}]} |
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 specific row from your google sheet
{
"data": {
"name": "John Due",
"row_id": 1
}
}
Add multiple new rows into Google Sheet.
{
"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"
}
]
}
{
"data": {
"name": "Jane Due",
"row_id": 3
}
}
Update specific row on your google sheet
{
"data": {
"name": "New Due"
}
}
{
"data": {
"name": "New Due",
"row_id": 3
}
}
Delete specific row from your google sheet
{
"message": "Deleted Successfully"
}
Add new sheet on your google sheet
{
"title": "Your new sheet"
}
{
"data": {
"title": "Your new sheet"
}
}
Delete sheet from your google sheet
{
"message": "Deleted Successfully"
}