Google Spreadsheet REST API Simplified - CRUD
3.5K
A simple implementation for Google Spreadsheets to use a micro service with your stack.
This allow you to use Google Spreadsheets as a backend.
credentials.jsonGOOGLE_CREDENTIALS=`base64 credentials.json`
You can add the email that was generated with the service account as an editor to a folder on Google Drive or on a Google Sheet.
git clone [email protected]:melalj/gsheet-api.git
docker run -p 8080:80 -e GOOGLE_CREDENTIALS=$GOOGLE_CREDENTIALS melalj/gsheet-api
You can also deploy it on Heroku and set the config vars (GOOGLE_CREDENTIALS)
start it locally
yarn install
# You can add your environement variables in a .env file
yarn start
# the api will be available on http://localhost:80/
# You can customize the port with the environmenet variable PORT
GET /Lists all available Spreadsheets from your Google Drive
GET /[
{
"id": "1MNXlNRwbUo4-qbTCdBZGW3Q8sq7pUDov-2ElTFOA0wo",
"name": "Leads",
"modifiedTime": "2020-04-24T13:36:53.699Z"
}
]
GET /:sheetIdLists all available Sheets from your spreadsheet.
GET /1MNXlNRwbUo4-qbTCdBZGW3Q8sq7pUDov-2ElTFOA0wo[
{
"title": "Sheet1",
"sheetId": 4543532,
"rowNumber": 0,
"rowCount": 2,
"columnCount": 2,
}
]
GET /:sheetId/:sheetNameQuery data from a sheet
GET /1MNXlNRwbUo4-qbTCdBZGW3Q8sq7pUDov-2ElTFOA0wo/Sheet1 {
"columns": {
"name": "Sheet1!A",
"email": "Sheet1!B"
},
"pagination": {
"haveNext": false,
"totalItems": 2,
"range": "Sheet1!A2:DD1001"
},
"data": [
{
"name": "Simo",
"email": "[email protected]"
},
{
"name": "Jane",
"email": "[email protected]"
}
]
}
| Name | Type | Required | Description |
|---|---|---|---|
| perPage | integer | No | How many items per page (default: 1000) |
| offset | integer | No | Query data from a specific row (default: 2) |
| maxColumns | integer | No | Number of colums in the sheet (default: 109) |
| returnColumn | string | No | Returns only one specific |
POST /:sheetId/:sheetNameAppend rows to a sheet. If a column doesn't exists, it will be added on the right of the table. You can you the query string valueInputOption=RAW to determine how input data should be interpreted.
POST /1MNXlNRwbUo4-qbTCdBZGW3Q8sq7pUDov-2ElTFOA0wo/Sheet1[{ "name": "Jean", "email": "[email protected]" }, { "name": "Bunny", "email": "[email protected]" }, ]{"insertedRow": 2}GET /:sheetId/:sheetName/:rowNumberQuery a specific row from a sheet
GET /1MNXlNRwbUo4-qbTCdBZGW3Q8sq7pUDov-2ElTFOA0wo/Sheet1/3{"rowNumber": 3, "name": "Jane", "email": "[email protected]"}PUT /:sheetId/:sheetNameUpdate rows in a sheet. If a column doesn't exists, it will be added on the right of the table.
You can you the query string valueInputOption=RAW to determine how input data should be interpreted.
PUT /1MNXlNRwbUo4-qbTCdBZGW3Q8sq7pUDov-2ElTFOA0wo/Sheet1{ "4" : { "email": "[email protected]" }, "1": { "phone": "415-500-7000" } }[
{
"spreadsheetId": "1MNXlNRwbUo4-qbTCdBZGW3Q8sq7pUDov-2ElTFOA0wo",
"updatedRange": "Sheet1!B4",
"updatedRows": 1,
"updatedColumns": 1,
"updatedCells": 1
},
{
"spreadsheetId": "1MNXlNRwbUo4-qbTCdBZGW3Q8sq7pUDov-2ElTFOA0wo",
"updatedRange": "Sheet1!C1",
"updatedRows": 1,
"updatedColumns": 1,
"updatedCells": 1
}
]
DELETE /:sheetId/:sheetNameDelete rows from a sheet
Delete /1MNXlNRwbUo4-qbTCdBZGW3Q8sq7pUDov-2ElTFOA0wo/Sheet1[4, 5]{ "deletedRows": 2 }You can secure these endpoints with either:
X-Private-Api-Key header: You need to set the environement variable PRIVATE_API_KEYkey query string: You need to set the environement variable PRIVATE_API_KEY_QUERYFollowing Google Sheets API documentation. This version of the Google Sheets API has a limit of 500 requests per 100 seconds per project, and 100 requests per 100 seconds per user. Limits for reads and writes are tracked separately. There is no daily usage limit.
Be mindful about this limitation, if you want to use this api as a backend for your frontend!
You are welcomed to fork the project and make pull requests. Or just file an issue or suggestion 😊
Content type
Image
Digest
Size
92.1 MB
Last updated
about 5 years ago
docker pull melalj/gsheet-api