{"id":19151434,"url":"https://github.com/sc5/google-sheets-api","last_synced_at":"2025-05-07T05:24:39.514Z","repository":{"id":29318140,"uuid":"32851579","full_name":"SC5/google-sheets-api","owner":"SC5","description":"Unofficial Google Sheets node API","archived":false,"fork":false,"pushed_at":"2023-12-24T23:53:40.000Z","size":195,"stargazers_count":21,"open_issues_count":9,"forks_count":16,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-30T14:43:41.505Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SC5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-25T08:24:21.000Z","updated_at":"2022-09-07T18:37:32.000Z","dependencies_parsed_at":"2024-06-18T21:23:33.628Z","dependency_job_id":"6c775aa1-c4ea-41b7-a0ee-ee397735dcb6","html_url":"https://github.com/SC5/google-sheets-api","commit_stats":{"total_commits":38,"total_committers":9,"mean_commits":4.222222222222222,"dds":0.6052631578947368,"last_synced_commit":"1271047cea3ce35f7e8605419db535026979bfee"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SC5%2Fgoogle-sheets-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SC5%2Fgoogle-sheets-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SC5%2Fgoogle-sheets-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SC5%2Fgoogle-sheets-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SC5","download_url":"https://codeload.github.com/SC5/google-sheets-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252819590,"owners_count":21809045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T08:14:42.403Z","updated_at":"2025-05-07T05:24:39.489Z","avatar_url":"https://github.com/SC5.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# google-sheets-api\n\n[![Build Status](https://travis-ci.org/SC5/google-sheets-api.svg?branch=master)](https://travis-ci.org/SC5/google-sheets-api)\n\nAn unofficial client for *reading* data from Google Sheets, since [googleapis does not come with one](https://github.com/google/google-api-nodejs-client/tree/master/apis).\n\n**Table of contents**\n\n\u003c!-- MarkdownTOC depth=3 autolink=true bracket=round --\u003e\n\n- [google-sheets-api](#google-sheets-api)\n  - [Usage](#usage)\n  - [API](#api)\n    - [Sheets(options)](#sheetsoptions)\n    - [sheets.getSheets(id, sheetId)](#sheetsgetsheetsid-sheetid)\n    - [sheets.getSheet(id, sheetId)](#sheetsgetsheetid-sheetid)\n    - [sheets.getRange(id, sheetId, rangeInfo)](#sheetsgetrangeid-sheetid-rangeinfo)\n    - [sheets.getCells(id, sheetId)](#sheetsgetcellsid-sheetid)\n  - [Changelog](#changelog)\n  - [License](#license)\n  - [Credit](#credit)\n\n\u003c!-- /MarkdownTOC --\u003e\n\n## Usage\n\n1.  Install module\n\n    ```shell\n    npm install google-sheets-api\n    ```\n\n2.  Create a project in [Google Developer Console](https://console.developers.google.com/project), for example: \"Sheets App\"\n3.  Enable Drive API for project under *APIs \u0026 auth* \u003e *APIs*\n4.  Create service auth credentials for project under *APIs \u0026 auth* \u003e *Credentials* \u003e *Create new Client ID*: *Service account*\n5.  Collect the listed service email address\n6.  Regenerate and download the P12 key\n7.  Convert the .p12 file into .pem format:\n\n    ```shell\n    openssl pkcs12 -in *.p12 -nodes -nocerts \u003e sheets.pem\n    ```\n\n    when prompted for password, it's `notasecret`\n\n8.  Share the Sheets document to *service email address* using the *Share* button\n9.  Pick up the Sheets document id from URL or Share dialog. Example:\n\n    ```shell\n    # Sheets document browser URL\n    https://docs.google.com/a/sc5.io/spreadsheets/d/1FHa0vyPxXj3BtqigQ3LcwPoa7ldlRtUDx6fFV6CqkNE/edit#gid=0\n    # Sheets document id\n    1FHa0vyPxXj3BtqigQ3LcwPoa7ldlRtUDx6fFV6CqkNE\n    ```\n\n9.  Put it all together:\n\n    ```javascript\n    var fs = require('fs');\n    var Promise = require('polyfill-promise');\n    var Sheets = require('google-sheets-api').Sheets;\n\n    // TODO: Replace these values with yours\n    var documentId = 'generated-by-sheets';\n    var serviceEmail = 'generated-by-dev-console@developer.gserviceaccount.com';\n    var serviceKey = fs.readFileSync('path/to/your/sheets.pem').toString();\n\n    var sheets = new Sheets({ email: serviceEmail, key: serviceKey });\n\n    sheets.getSheets(documentId)\n    .then(function(sheetsInfo) {\n      // NOTE: Using first sheet in this example\n      var sheetInfo = sheetsInfo[0];\n      return Promise.all([\n        sheets.getSheet(documentId, sheetInfo.id),\n        sheets.getRange(documentId, sheetInfo.id, 'A1:C3')\n      ]);\n    })\n    .then(function(sheets) {\n      console.log('Sheets metadata:', sheets[0]);\n      console.log('Sheets contents:', sheets[1]);\n    })\n    .catch(function(err){\n      console.error(err, 'Failed to read Sheets document');\n    });\n    ```\n\n10. Success!\n\n\n## API\n\nRelevant API methods, see code for details and internal ones.\n\n**NOTE:** All the methods returns a native (polyfilled when needed) Promise.\n\n### Sheets(options)\n\nInitialize Sheets client with provided options\n\n* @param {Object} options        All the options\n* @param {String} options.email  Service email address\n* @param {String} options.key    Service .PEM key contents\n\n### sheets.getSheets(id, sheetId)\n\nFetch info from one sheet\n\n* @param  {String} id      Sheets document id\n* @param  {String} sheetId Worksheet id (use getSheets to fetch them)\n* @return {Promise}        A promise that resolves to a list of worksheet info\n\n### sheets.getSheet(id, sheetId)\n\nFetch info from one sheet\n\n* @param  {String} id      Sheets document id\n* @param  {String} sheetId Worksheet id (use getSheets to fetch them)\n* @return {Promise}        A promise that resolves to a worksheet info containing id, title, rowCount, colCount\n\n\n### sheets.getRange(id, sheetId, rangeInfo)\n\nRetrieve cells data based on given range\n\n**NOTE:** \n*  * All below ranges are v4 compatible but full matrix are [SUPPORTED] only for few of them:\n*\n* -  [SUPPORTED] \"Sheet1!A1:B2\" refers to the first two cells in the top two rows of Sheet1.\n* -  [SUPPORTED] \"A3:\" refres to all cells starts from 'A' column and 3rd row.\n* - \"Sheet1!A:A\" refers to all the cells in the first column of Sheet1.\n* - \"Sheet1!1:2\" refers to all the cells in the first two rows of Sheet1.\n* - \"Sheet1!A5:A\" refers to all the cells of the first column of Sheet 1, from row 5 onward.\n* - [SUPPORTED]\"Sheet1\" refers to all the cells in Sheet1.\n* - \"'My Custom Sheet'!A:A\" refers to all the cells in a sheet named \"My Custom Sheet.\"\n*   Single quotes are required for sheet names with spaces, special characters, or an alphanumeric combination.\n*\n*\n* @param  {String} id        Sheet document id\n* @param  {String} sheetId   Sheet id\n* @param  {Mixed} rangeInfo  Range info\n* @return {Array}            Rows containing cells\n\n\n### sheets.getCells(id, sheetId)\n\nFetch cell contents from one worksheet\n\n* @param  {String} id      Sheets document id\n* @param  {String} sheetId Worksheet id (use getSheets to fetch them)\n* @return {Promise}        A promise that resolves to a list of rows\n\n### sheets.getRowAndColCount(data)\n\nGet total count of rows and columns in a data array\n\n* @param {Array} data Title, name of the sheet\n* @return {Array\u003cnumber\u003e} Total count of rows and columns\n\n### sheets.paddedEmptyMatrix(data)\n\nGenerate a empty matrix from startRow,startCol\n\n* @param {number} totalRow no of total rows in raw v4 data\n* @param {number} totalCol no of total cols in raw v4 data\n* @param {number} startRow start row number\n* @param {number} startCol start col number\n* @return {Array\u003c[{row: number, column: string, content: string}]\u003e} A full empty matrix\n\n### sheets.paddedDataMatrix(data, rangePattern)\n\nCreates a full, padded data matrix\n\n* if the range is like 'A3:' or 'B1:C2' and there are missing\n* cells (no content) this function adds them there (unlike other functions),\n* thus you'll always have full matrix like B1:C2 --\u003e\n* [\n    [\n      { row: 1, column: \"B\", content: \"B1\" },\n      { row: 1, column: \"C\", content: \"C1\" },\n    ],\n    [\n      { row: 2, column: \"B\", content: \"\" },\n      { row: 2, column: \"C\", content: \"C2\" },\n    ],\n  ]\n* or in either case it will return raw v4 response like, A:B --\u003e [[A1, B1], ['', B2]]\n* \n* @param  {Array}   data     Sheet document id\n* @param  {String}  rangePattern Range info\n* @return {Array\u003c[]\u003e}  A full data matrix\n\n## Changelog\n\n- 1.0.0: Google sheet API migration from v3 to v4\n- 0.4.3: Fixed JWT auth issue with recent Google API\n- 0.4.2: Updated dependencies / fixed vulnerabilities\n- 0.4.1: Fixed the double letter range issue, like: `A1:AA5`\n- 0.4.0: Added support for setting auth scope (makes module usable with other Google APIs as well)\n- 0.3.0: Using native promises if available, added `rowCount` and `colCount` to `getSheet()` response\n- 0.2.3: Improved documentation\n- 0.2.2: Fixed the issue the range with double digits, like `A1:C10`\n- 0.2.1: Fixed the documentation\n- 0.2.0: Added support for getRange()\n- 0.1.0: Initial release\n\n## License\n\nModule is MIT -licensed\n\n## Credit\n\nModule is backed by\n\n\u003ca href=\"http://sc5.io\"\u003e\n  \u003cimg src=\"http://logo.sc5.io/78x33.png\" style=\"padding: 4px 0;\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsc5%2Fgoogle-sheets-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsc5%2Fgoogle-sheets-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsc5%2Fgoogle-sheets-api/lists"}