An open API service indexing awesome lists of open source software.

https://github.com/benborgers/opensheet

💾 An API to get a Google Sheet as JSON, no authentication required.
https://github.com/benborgers/opensheet

hacktoberfest

Last synced: 3 months ago
JSON representation

💾 An API to get a Google Sheet as JSON, no authentication required.

Awesome Lists containing this project

README

          

# opensheet

#### opensheet's servers get 1.5 billion hits each month!
If the project is is useful to you, I'd love your help in covering hosting costs.
You can [sponsor me for $3/month on GitHub Sponsors](https://github.com/sponsors/benborgers). Thank you!

---

A free, super simple, hosted API for getting Google Sheets as JSON.

**Tutorial blog post:** [benborgers.com/posts/google-sheets-json](https://benborgers.com/posts/google-sheets-json)

**If you have questions:** benborgers@hey.com

## Documentation

This API returns a given Google Sheet's rows as JSON data.

In order to use it:

1. The first row of your Google Sheet should be a header row ([here's an example](https://docs.google.com/spreadsheets/d/1o5t26He2DzTweYeleXOGiDjlU4Jkx896f95VUHVgS8U/edit)).
1. Link sharing must be turned on so anyone with the link can _view_ the Google Sheet.

The format for this API is:

```
https://opensheet.elk.sh/spreadsheet_id/tab_name
```

For example:

```
https://opensheet.elk.sh/1o5t26He2DzTweYeleXOGiDjlU4Jkx896f95VUHVgS8U/Test+Sheet
```

You can also replace `tab_name` with the tab number (in the order that the tabs are arranged), if you don't know the name. For example, to get the first sheet:

```
https://opensheet.elk.sh/1o5t26He2DzTweYeleXOGiDjlU4Jkx896f95VUHVgS8U/1
```

_Take note that the first sheet in order is numbered `1`, not `0`._

Adding the `?raw=true` URL parameter returns the raw, unformatted data from the sheet. Without this parameter, Google Sheets formats numbers, dates, and other data types, but with `?raw=true`, you'll get the underlying values.

## Caching

Responses are cached for 30 seconds in order to improve performance and to avoid hitting Google Sheets' rate limits, so it might take up to 30 seconds for fresh edits to show up in the API response.

## Recent hosting changes

The base URL is now `opensheet.elk.sh`, not `opensheet.vercel.app`. `opensheet.vercel.app` will continue to redirect to the correct URL, but you should update your code to use `opensheet.elk.sh` to avoid the slight performance degradation that comes from needing to redirect.

## Self-hosting

_This section is only necessary if you want to fork opensheet and host your own instance of it. If you don't want to deal with that, you're welcome to use my hosted instance at `opensheet.elk.sh`._

opensheet is written as a [Bun](https://bun.sh) server. It uses Redis for caching and PostgreSQL for analytics.

If you host opensheet yourself, you'll need:

1. A Redis instance (Bun's built-in `redis` client is used)
2. A PostgreSQL database (Bun's built-in `sql` client is used)
3. A Google Sheets API key:
1. Go to the [Google Cloud Console](https://console.cloud.google.com) and create a new project from the top navigation bar.
2. Search for "Google Sheets API" and enable it.
3. Search for "Credentials" and create an API key. If you want, you can restrict it to only be able to access the Google Sheets API.
4. Set the `GOOGLE_API_KEY` environment variable.

## Local development

```sh
bun run dev
```