{"id":13433199,"url":"https://github.com/mewpk/Google-Apps-Script","last_synced_at":"2025-03-17T10:33:30.228Z","repository":{"id":234521378,"uuid":"789065094","full_name":"mewpk/Google-Apps-Script","owner":"mewpk","description":"Google Apps Script for Spreadsheet Data Management","archived":false,"fork":false,"pushed_at":"2024-04-19T16:39:48.000Z","size":3,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-27T13:04:53.606Z","etag":null,"topics":["google","google-apps-script","google-sheets","sheet"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mewpk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-04-19T16:32:39.000Z","updated_at":"2024-07-09T20:41:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"90075237-1b0d-4d12-b27e-6b4ec1719525","html_url":"https://github.com/mewpk/Google-Apps-Script","commit_stats":null,"previous_names":["mewpk/google-apps-script"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mewpk%2FGoogle-Apps-Script","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mewpk%2FGoogle-Apps-Script/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mewpk%2FGoogle-Apps-Script/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mewpk%2FGoogle-Apps-Script/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mewpk","download_url":"https://codeload.github.com/mewpk/Google-Apps-Script/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244016984,"owners_count":20384248,"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","google-apps-script","google-sheets","sheet"],"created_at":"2024-07-31T02:01:22.360Z","updated_at":"2025-03-17T10:33:30.220Z","avatar_url":"https://github.com/mewpk.png","language":"JavaScript","readme":"# Google Apps Script: Spreadsheet Interaction\n\n## By mewpk\n\nThis guide provides details on using a Google Apps Script to interact with a Google Sheet via web requests. The script handles `GET` requests to retrieve all data and `POST` requests to append new data.\n\n## Setup Instructions\n\n### 1. Prepare Your Google Sheet\n\n- Open or create a Google Sheet.\n- Note the name of the sheet you want to interact with.\n\n### 2. Open the Script Editor\n\n- In your Google Sheet, go to `Extensions` \u003e `Apps Script`.\n\n### 3. Insert the Script\n\nCopy and paste the following script into the script editor, replacing `\"Sheet1\"` with your sheet's name if different.\n\n```javascript\n// Handles GET requests\nfunction doGet(e) {\n  const ss = SpreadsheetApp.getActiveSpreadsheet();\n  const sheet = ss.getSheetByName(\"Sheet1\");\n  const range = sheet.getDataRange();\n  const values = range.getValues();\n  return ContentService.createTextOutput(JSON.stringify(values))\n                       .setMimeType(ContentService.MimeType.JSON);\n}\n\n// Handles POST requests\nfunction doPost(e) {\n  const ss = SpreadsheetApp.getActiveSpreadsheet();\n  const sheet = ss.getSheetByName(\"Sheet1\");\n  try {\n    const data = JSON.parse(e.postData.contents);\n    if (Array.isArray(data.data) \u0026\u0026 data.data.length \u003e 0) {\n      sheet.appendRow(data.data);\n      return ContentService.createTextOutput(JSON.stringify({ \"status\": \"success\" }))\n                           .setMimeType(ContentService.MimeType.JSON);\n    } else {\n      return ContentService.createTextOutput(JSON.stringify({ \"status\": \"error\", \"message\": \"Invalid data format\" }))\n                           .setMimeType(ContentService.MimeType.JSON);\n    }\n  } catch (error) {\n    return ContentService.createTextOutput(JSON.stringify({ \"status\": \"error\", \"message\": error.toString() }))\n                         .setMimeType(ContentService.MimeType.JSON);\n  }\n}\n```\n\n# Deploying as a Web App\n\nThis section outlines how to deploy your Google Apps Script as a web app, allowing it to be accessed via HTTP requests.\n\n## 1. Deployment Process\n\n- **Navigate to Deployment Options**:\n  - In the Apps Script editor, click on `Deploy` \u003e `New deployment`.\n- **Configure the Deployment**:\n  - Choose `Web app` from the list of deployment types.\n  - Set `Execute as` to `Me` to run the script as your account.\n  - Choose who can access the web app. Select `Anyone` or `Anyone, even anonymous` if you want it to be publicly accessible.\n\n## 2. Authorization\n\n- **Review Permissions**:\n  - Click on `Review Permissions`, choose your Google account, and accept the necessary permissions to allow the script to operate.\n\n## 3. Obtain API URL\n\n- **API Endpoint**:\n  - After completing the deployment, you will be provided with a URL. This is your endpoint for API calls.\n\n# API Usage\n\nInteract with your Google Sheet through API by making HTTP requests to the endpoint provided after deployment.\n\n## Making a GET Request\n\n- **Retrieve Data**:\n  - Send a GET request to the endpoint URL to fetch all data from the sheet. Use tools like Postman, curl, or write code in JavaScript using `fetch` to make these requests.\n\n## Making a POST Request\n\n- **Add Data**:\n  - To append new data to your sheet, send a POST request with a JSON payload. Ensure your request content type is set to `application/json`.\n\n### Example JSON Payload for POST Request\n\n```json\n{\n  \"data\": [\"Example Name\", \"Example Email\", \"Example Date\"]\n}\n```\n\n## Sample Code to Make a POST Request\n\n- **Here is a simple example using JavaScript:**:\n\n```javascript\nfunction sendData() {\n  const url = 'YOUR_API_ENDPOINT';  // Replace YOUR_API_ENDPOINT with the actual URL provided after deployment\n  const data = {\n    data: [\"Example Name\", \"Example Email\", \"Example Date\"]\n  };\n  fetch(url, {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json'\n    },\n    body: JSON.stringify(data)\n  })\n  .then(response =\u003e response.json())\n  .then(data =\u003e console.log('Success:', data))\n  .catch((error) =\u003e console.error('Error:', error));\n}\n```\n - Replace YOUR_API_ENDPOINT with the actual URL to successfully send data to your Google Sheet.\n\n\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmewpk%2FGoogle-Apps-Script","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmewpk%2FGoogle-Apps-Script","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmewpk%2FGoogle-Apps-Script/lists"}