Can we use Google Spreadsheet as a backend database
Asked Answered
M

7

10

I am trying to develop an application, where I where fetching data from multiple clients related to some transactions. Now I want to make some analysis using the Google Spreadsheet. Is there any way by which I can achieve this using the ASP.Net MVC(using C#). Google provides OAuth and When I implement the code and when I am trying to send the data to Google spreadsheet which I receive form the clients. However, when I am doing that, for every new client, Google asks for login credential. Client enter their own credentials, and the Google sheet instead a common sheet, client own sheet is used. Thus, my purpose is not solved. Is there any way possible to do this. I does not seem to find proper documentation on Google as well. Please provide some suggestions to implement this. Thanks in advance.

Mcclintock answered 22/1, 2016 at 4:21 Comment(2)
Related: #5037723Duky
Related: #6270710Duky
R
17

This can be done very easily if you just want a read only database. You must publish your Google Sheet to the web and, from its url, copy its id.

For example my sheet has this url: https://docs.google.com/spreadsheets/d/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/edit

The long alphanumeric string in the middle is my sheet id. Copy it and place it instead of XXXX in the following url, as follows:

https://spreadsheets.google.com/feeds/list/XXXX/1/public/basic?alt=json"

So the final url would look like this: https://spreadsheets.google.com/feeds/list/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/1/public/basic?alt=json

Then you can simply access this url and get all your data as json. Using jQuery:

var $url = 'https://spreadsheets.google.com/feeds/list/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/1/public/basic?alt=json';
$.getJSON($url,function(data){
    alert(JSON.stringify(data.feed.entry));
});

You will get a long json structure. The relevant data is in data.feed.entry. There you'll have many entries. On each one you'll have a "content" property and within it, a "$t" one. These will give you all the cells. So for getting the first row, you will have to get data.feed.entry[0].content.$t.

Hope it helps.

Rolling answered 11/6, 2016 at 2:6 Comment(1)
Rather than getting the whole file as a JSON object, can we query like SQL?Diseuse
G
8

This can be accomplished using Google Apps Script. In particular, you can achieve this with a "bound" script in Google Sheets (i.e. a script that was created in the context of the sheet that you wish to create as the "backend") that you then publish as a "web app" script. When you publish it, you can make it execute with the authority of the owner of the spread sheet (rather than the authority of the user who invokes the url), which will not require the end user to explicitly authorize themselves (since it is the script publisher's credentials, not the user's credentials, that are being used).

It should be noted that, while this (and generally building on top of Google Apps Script) is a reasonable approach for small-to-medium apps, you'll probably find using Google Cloud Platform (and, in this particular case, the Cloud Datastore) as the better, more scalable solution for small-to-large apps. That is, if you are prototyping or creating an internal tool that is unlikely to catch fire overnight, I'd go with whichever approach you find more convenient / simpler; if you are creating an app that could potentially experience a "success disaster", I'd go with Cloud Platform, instead.

Gherlein answered 22/1, 2016 at 4:39 Comment(5)
I think that is important to note that Google Sheets has a 2 million cells limit.Duky
Are the scalability concerns from a 'success disaster' based on the size of the db, or on the reliability (or possible rate-limiting) of requests to the sheet? My use case involves presenting a read-only db to the web app. If I need to I can implement a caching layer.Lag
@Lag you may find these of interest: script.google.com/dashboard cloud.google.com/appengine/quotas cloud.google.com/datastore/sla cloud.google.com/datastore/pricingGherlein
@Lag in short, the services on Google Cloud Platform typically offer a clear SLA; the Cloud Datastore, for example, offers 99.95% uptime if querying from multiple zones and doesn't really have an upper limit on the quantity of data that can be stored (though there is a max free amount)...Gherlein
@Lag ... by contrast, there does not seem to be a published SLA for Google Apps Script, and assuming that the Sheets API limits apply (developers.google.com/sheets/api/limits), has a max of 40,000 queries per day (below the free read quota for Cloud Datastore).Gherlein
D
3

If your sheet is public, you can do it withouth authentication. You can use google API Visualization with the query language or use the Google Sheets API. But if your sheet is private, it is mandatory the use of OAuth2 authentication through service account credentials. In order to do that, you have to create a service account (with owner of the project role for example). Then you have to download the client_secret.json file which will be the one you use in your code. Finally you have to share your spreadsheet with the email you get in this file. Look in the file and you will see it.

I have made a tutorial. You can visit at http://edba.xyz/google-sheets-as-database. It is mainly based in PHP but it is easily trasportable to other languages.

Dinse answered 19/2, 2018 at 13:26 Comment(1)
The link is brokenDuky
W
2

I have recently been developing a website using google sheet as backend. It is great. The speed is also appreciable. I have integrated the custom backend which I wrote on google apps script with my Django app. So now my website stores the user information on google sheets. The google sheet code and Django app interact via Rest API which can be easily developed using doGet() and doPost() in apps script and python request on the Django side. Once the necessary structure is built( it does take some time tweaking if you are new) but then it works as a great database for your website.

Wideangle answered 16/5, 2020 at 20:8 Comment(0)
A
1

Google spreadsheet is a great solution for quick prototyping database and even in some cases for production use.

People have already realized the potential and there are many tools today for turning your Google spreadsheet into a backend api

There are couple of libraries such as node-sheets for obtaining a json feed from a Google spreadsheet (read-only)

Also, if you need a complete standalone service you have some paid options like

And also open source options such as

This can be installed on any cloud provider via Docker and you can point it to your spreadsheet and it will dynamically turn it into an api.

So if, for example, your spreadsheet has the following sheets:

| articles | products | users |

It will automatically create the 3 endpoints

GET /articles
GET /products
GET /users

It is suitable for read-only apis (you update the spreadsheet directly, not through code) that don't need to be changed too often (although you can control the update interval)

Alcestis answered 6/11, 2019 at 15:31 Comment(0)
P
0

You can use Kodem.io.

Google Sheets As Backend allows you to do CRUD requets using Google Sheets.

Disclaimer: I work at Kodem

Picayune answered 24/9, 2019 at 6:7 Comment(1)
Link looks to be brokenDuky
I
-1

You can try https://sheet2db.com

PS. I am founder of Sheet2DB

Inoperable answered 11/8, 2024 at 16:14 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewStickpin

© 2022 - 2025 — McMap. All rights reserved.