{"id":13479699,"url":"https://github.com/gglukmann/google-sheets-mapper","last_synced_at":"2025-03-27T10:30:37.525Z","repository":{"id":45725259,"uuid":"308855396","full_name":"gglukmann/google-sheets-mapper","owner":"gglukmann","description":"📝  A library for getting data from Google Sheets API v4","archived":false,"fork":false,"pushed_at":"2022-07-15T12:27:57.000Z","size":212,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T23:18:05.663Z","etag":null,"topics":["google-sheets","google-sheets-api","google-sheets-api-v4"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/gglukmann.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}},"created_at":"2020-10-31T10:20:14.000Z","updated_at":"2023-05-01T07:53:17.000Z","dependencies_parsed_at":"2022-09-26T17:50:42.998Z","dependency_job_id":null,"html_url":"https://github.com/gglukmann/google-sheets-mapper","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gglukmann%2Fgoogle-sheets-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gglukmann%2Fgoogle-sheets-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gglukmann%2Fgoogle-sheets-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gglukmann%2Fgoogle-sheets-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gglukmann","download_url":"https://codeload.github.com/gglukmann/google-sheets-mapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245826686,"owners_count":20678843,"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":["google-sheets","google-sheets-api","google-sheets-api-v4"],"created_at":"2024-07-31T16:02:21.632Z","updated_at":"2025-03-27T10:30:37.259Z","avatar_url":"https://github.com/gglukmann.png","language":"TypeScript","readme":"# Google Sheets Mapper\n\n## A library for getting data from [Google Sheets API v4](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values)\n\n[![Minified file size](https://img.badgesize.io/https://www.unpkg.com/google-sheets-mapper/dist/google-sheets-mapper.esm.js.svg)](https://bundlephobia.com/result?p=google-sheets-mapper) [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) [![NPM version](https://img.shields.io/npm/v/google-sheets-mapper)](https://www.npmjs.com/package/google-sheets-mapper)\n\n---\n\n## Installation\n\nPackage can be added using **yarn**:\n\n```bash\nyarn add google-sheets-mapper\n```\n\nOr, use **NPM**:\n\n```bash\nnpm install google-sheets-mapper\n```\n\nUMD build available on [unpkg](https://www.unpkg.com/browse/google-sheets-mapper@1.0.0/dist/google-sheets-mapper.cjs.production.min.js).\n\n---\n\n## Usage\n\n1. Go to [Google Cloud Console](https://console.cloud.google.com/) to get API key for Google Sheets API.\n2. Create a Google Sheet and add some data. See [example sheet](https://docs.google.com/spreadsheets/d/1zbEyIfga05-gXTCVGejJHpl8ZrlcTYanvgnQBa1t2DM/edit#gid=0).\n3. Share it with \"Anyone with this link can view\".\n4. Get sheet id from url of the sheet.\n\n```html\nhttps://docs.google.com/spreadsheets/d/[THIS-IS-THE-SHEET-ID]/\n```\n\n5. I suggest adding API key and sheet id to `.env` file\n\n---\n\n## Examples\n\n### Get data from all sheets inside the spreadsheet\n\n```js\nimport { fetchGoogleSheetsData } from 'google-sheets-mapper';\n\nconst getData = async () =\u003e {\n  try {\n    return await fetchGoogleSheetsData({\n      apiKey: process.env.REACT_APP_GOOGLE_API_KEY,\n      sheetId: process.env.REACT_APP_GOOGLE_SHEETS_ID,\n    });\n  } catch (error) {\n    console.error(error);\n  }\n};\n```\n\n### Get data from specific sheets inside the spreadsheet\n\nDon't use single quotes on sheet names, they will be removed because when using space in sheet name it will be returned wrapped with single quotes and plugin will remove them for clean string id.\n\n```js\nimport { fetchGoogleSheetsData } from 'google-sheets-mapper';\n\nconst getData = async () =\u003e {\n  try {\n    return await fetchGoogleSheetsData({\n      apiKey: process.env.REACT_APP_GOOGLE_API_KEY,\n      sheetId: process.env.REACT_APP_GOOGLE_SHEETS_ID,\n      sheetsOptions: [{ id: 'Sheet1' }],\n    });\n  } catch (error) {\n    console.error(error);\n  }\n};\n```\n\n---\n\n## API Documentation\n\nThe `GoogleSheetsMapper.fetchGoogleSheetsData` function takes an object with three properties:\n\n| Name          | Value  |\n| ------------- | ------ |\n| apiKey        | string |\n| sheetId       | string |\n| sheetsOptions | array  |\n\n- `apiKey` is a Google Sheets API v4 key from [Google Cloud Console](https://console.cloud.google.com/).\n- `sheetId` is the id of the sheet.\n- `sheetsOptions` is an array of specific objects `{ id, headerRowIndex }`. Can be left out then it will fallback to all sheets inside the spreadsheet and use first row from sheet as header.\n\n### Exposed Data\n\nThe function produces an `MapperState` object:\n\n```js\ntry {\n  const data = await GoogleSheetsMapper.fetchGoogleSheetsData({\n    apiKey,\n    sheetId,\n  });\n} catch (error) {\n  console.error(error);\n}\n```\n\n| Name  | Value          |\n| ----- | -------------- |\n| data  | array          |\n| error | null or object |\n\n- `data` is an array of mapped data objects.\n\n```js\n[\n  {\n    id: 'Sheet1',\n    data: [\n      { value: 'et', key: 'language' },\n      { value: 'Test sheet', key: 'title' },\n    ],\n  },\n];\n```\n\n- `error` lets you know when there is something wrong. It returns an error object where you can get specific error properties from `error.response`\n\n```js\n{\n  status: '404',\n  statusText: '',\n  url: 'https://sheets.googleapis.com/v4/spreadsheets/...',\n}\n```\n\n---\n\n## Migration from v1 to v2\n\n- Change `sheetsNames` array of string to `sheetsOptions` array of objects with `{ id: 'sheetName' }`\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgglukmann%2Fgoogle-sheets-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgglukmann%2Fgoogle-sheets-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgglukmann%2Fgoogle-sheets-mapper/lists"}