Skip to content

Commit

Permalink
Updated to handle sheet name
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Moreton committed Aug 25, 2021
1 parent 2a09022 commit e0c84d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ module.exports = function (req, res, next) {
var params = req.query,
api_key = params.api_key || gauthkey,
id = params.id,
sheet = params.sheet || 1,
sheet = params.sheet,
query = params.q,
useIntegers = params.integers || true,
showRows = params.rows || true,
showColumns = params.columns || true,
url = 'https://sheets.googleapis.com/v4/spreadsheets/' + id + '/values/Sheet' + sheet + '?key=' + api_key;
url = 'https://sheets.googleapis.com/v4/spreadsheets/' + id + '/values/' + sheet + '?key=' + api_key;
request(url, function (error, response, body) {
if (!id) {
return res.status(response.statusCode).json('You must provide a sheet ID');
}
if (!sheet) {
return res.status(response.statusCode).json('You must provide a sheet name');
}
if (!error && response.statusCode === 200) {
var data = JSON.parse(response.body);
var responseObj = {};
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ First, you must make sure your Google Sheet is set to be shared to 'anyone with
You can then access your readable JSON API using the `/api` endpoint. You can change this in app.js.

```
http://example.com/api?id=SPREADSHEET_ID&sheet=SHEET_NUMBER
http://example.com/api?id=SPREADSHEET_ID&sheet=SHEET_NAME
```

This will update live with changes to the spreadsheet.
Expand All @@ -32,7 +32,7 @@ This will update live with changes to the spreadsheet.

**id (required):** The ID of your document. This is the big long aplha-numeric code in the middle of your document URL.

**sheet (optional):** The number of the individual sheet you want to get data from. Your first sheet is 1, your second sheet is 2, etc. If no sheet is entered then 1 is the default.
**sheet (required):** The name of the individual sheet you want to get data from.

**q (optional):** A simple query string. This is case insensitive and will add any row containing the string in any cell to the filtered result.

Expand Down

0 comments on commit e0c84d3

Please sign in to comment.