Inspired by this gist.
- Create a new App Script project.
- Paste the content of the file
google-app-script-crud.gs
in the defaultCode.gs
file. - Create a new Spreadsheet.
- Copy the Spreadsheet ID found in the URL into the variable
SHEET_ID
located in line 1 of your file.
- Every Sheet should have an
id
column as the recommended structure. Think of it as a relational database. - There is no auto-increments in the script logic for the
id
column, but can be easy send in the payload just getting the total length of the table + 1.
Query params:
@parameter-required action=read
@parameter-required table=<SHEET_NAME>
@parameter-optional id=<COLUMN_ID>
When providing the optional id, it will fetch that record in key-value format.
Request
GET https://<yourappscripturl>?action=read&table=employees
Response:
{"success":true,"data":[{"id":1,"name":"Carls","email":"[email protected]","account":000000000,"row":2},{"id":2,"name":"Alf","email":"[email protected]","account":000000000,"row":3},{"id":3,"name":"Rich","email":"[email protected]","account":000000000,"row":4},{"id":4,"name":"Salem!","email":"[email protected]","account":000000000,"row":5}]}
Query params:
@parameter-required action=insert
@parameter-required table=<SHEET_NAME>
@parameter-required data=JSON
Request
GET https://<yourappscripturl>?action=insert&table=employees&data={"id":5,"name":"John Doe","email":"[email protected]","account":1111}
Response:
{"success":true,"data":{"id":5,"name":"John Doe","email":"[email protected]","account":1111}
Query params:
@parameter-required action=update
@parameter-required table=<SHEET_NAME>
@parameter-required id=ID
@parameter-required data=JSON
To update you only need to provide with the key-value JSON of what's going to change.
Request
GET https://<yourappscripturl>?action=update&table=employees&id=5&data={"name":"Johnnathan"}
Response:
{"success":true,"data":{"id":5,"name":"Johnnathan","email":"[email protected]","account":1111}
Query params:
@parameter-required action=delete
@parameter-required table=<SHEET_NAME>
@parameter-required id=ID
Request
GET https://<yourappscripturl>?action=delete&table=employees&id=5
Response:
{"success":true,"data":{"id":5,"name":"Johnnathan","email":"[email protected]","account":1111}
- Richard Blondet - RichardBlondet
This project is licensed under the MIT License - see the LICENSE file for details.