{"id":926,"date":"2020-09-05T14:23:41","date_gmt":"2020-09-05T14:23:41","guid":{"rendered":"https:\/\/codeinsightacademy.com\/blog\/?p=926"},"modified":"2021-05-06T16:05:47","modified_gmt":"2021-05-06T16:05:47","slug":"fetch-data-from-google-sheet","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/javascript\/fetch-data-from-google-sheet\/","title":{"rendered":"Fetch Data From Google Sheet"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>let offset = 'A2';\nlet limit = 'Z999';\nconst sheetid = \"&lt;sheetid&gt;\"; \n\nconst apikey = \"&lt;api key&gt;\"; \n\nconst sheetname = \"Sheet1\";\nconst url = `https:\/\/sheets.googleapis.com\/v4\/spreadsheets\/${sheetid}\/values\/${sheetname}!${offset}:${limit}?key=${apikey}`;\n\nvar sheet_data = &#91;];\n\nfetch(url).then(data =&gt; data.json()).then(data =&gt; { \n\tsheet_data = data.values;\n\tconsole.table(sheet_data);\n});<\/code><\/pre>\n\n\n\n<ul><li>https:\/\/docs.google.com\/spreadsheets\/d\/<strong>sheetid<\/strong>\/edit?usp=sharing<\/li><li>create\/get apikey from <a rel=\"noreferrer noopener\" href=\"https:\/\/console.developers.google.com\/apis\/credentials\" target=\"_blank\">https:\/\/console.developers.google.com\/apis\/credentials<\/a><\/li><li>in <a href=\"https:\/\/console.developers.google.com\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/console.developers.google.com<\/a> <br>Go to &gt; Libraries &gt; Google Sheets &gt; Enable<\/li><\/ul>\n\n\n\n<p>Sample Google Sheet Data<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-11.png\"><img loading=\"lazy\" width=\"496\" height=\"302\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-11.png\" alt=\"\" class=\"wp-image-1210\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-11.png 496w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-11-300x183.png 300w\" sizes=\"(max-width: 496px) 100vw, 496px\" \/><\/a><\/figure>\n\n\n\n<p>To get sheet id<br>Click on share then copy link<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-13.png\"><img loading=\"lazy\" width=\"1024\" height=\"638\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-13-1024x638.png\" alt=\"\" class=\"wp-image-1220\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-13-1024x638.png 1024w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-13-300x187.png 300w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-13-768x479.png 768w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-13.png 1049w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Create API Key<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-14.png\"><img loading=\"lazy\" width=\"1024\" height=\"490\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-14-1024x490.png\" alt=\"\" class=\"wp-image-1226\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-14-1024x490.png 1024w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-14-300x143.png 300w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-14-768x367.png 768w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/04\/image-14.png 1186w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Final Output in HTML<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/05\/image.png\"><img loading=\"lazy\" width=\"518\" height=\"210\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/05\/image.png\" alt=\"\" class=\"wp-image-1249\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/05\/image.png 518w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/05\/image-300x122.png 300w\" sizes=\"(max-width: 518px) 100vw, 518px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/docs.google.com\/spreadsheets\/d\/sheetid\/edit?usp=sharing create\/get apikey from https:\/\/console.developers.google.com\/apis\/credentials in https:\/\/console.developers.google.com Go to &gt; Libraries &gt; Google Sheets &gt; Enable Sample Google Sheet Data To get sheet idClick on share then copy link Create API Key Final Output in HTML<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[19],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/926"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=926"}],"version-history":[{"count":12,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/926\/revisions"}],"predecessor-version":[{"id":1250,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/926\/revisions\/1250"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}