├── .eslintrc.js ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE.md ├── dependabot.yml ├── linters │ ├── .htmlhintrc │ ├── .yaml-lint.yml │ └── sun_checks.xml ├── sync-repo-settings.yaml └── workflows │ ├── automation.yml │ ├── lint.yml │ └── test.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── adminSDK ├── README.md ├── directory │ └── index.html ├── reports │ └── index.html └── reseller │ └── index.html ├── apps-script ├── execute │ └── index.js └── quickstart │ ├── README.md │ └── index.html ├── calendar └── quickstart │ ├── README.md │ └── index.html ├── classroom └── quickstart │ ├── README.md │ └── index.html ├── docs └── quickstart │ ├── README.md │ └── index.html ├── drive ├── activity-v2 │ └── index.html ├── picker │ └── helloworld.html └── quickstart │ ├── README.md │ └── index.html ├── gmail └── quickstart │ ├── README.md │ └── index.html ├── images └── googlelogo_color_272x92dp.png ├── package-lock.json ├── package.json ├── people └── quickstart │ ├── README.md │ └── index.html ├── sheets ├── quickstart │ ├── README.md │ └── index.html └── snippets │ ├── README.md │ ├── base_test.js │ ├── index.html │ ├── sheets_append_values.js │ ├── sheets_batch_get_values.js │ ├── sheets_batch_update.js │ ├── sheets_batch_update_values.js │ ├── sheets_conditional_formatting.js │ ├── sheets_create.js │ ├── sheets_get_values.js │ ├── sheets_pivot_tables.js │ ├── sheets_update_values.js │ ├── snippets.js │ ├── test_append_spreadsheet_values.js │ ├── test_batch_get_spreadsheet_values.js │ ├── test_batch_update_spreadsheet.js │ ├── test_batch_update_spreadsheet_values.js │ ├── test_conditionally_format.js │ ├── test_create_pivot_tables.js │ ├── test_create_spreadsheet.js │ ├── test_get_spreadsheet_values.js │ └── test_update_spreadsheet_values.js ├── slides ├── quickstart │ ├── README.md │ └── index.html └── snippets │ ├── README.md │ ├── base_test.js │ ├── index.html │ ├── slides_copy_presentation.js │ ├── slides_create_bulleted_text.js │ ├── slides_create_image.js │ ├── slides_create_presentation.js │ ├── slides_create_sheets_chart.js │ ├── slides_create_slide.js │ ├── slides_create_textbox_with_text.js │ ├── slides_image_merging.js │ ├── slides_refresh_sheets_chart.js │ ├── slides_simple_text_replace.js │ ├── slides_text_merging.js │ ├── slides_text_style_update.js │ ├── snippets.js │ ├── test_slides_copy_presentation.js │ ├── test_slides_create_bulleted_text.js │ ├── test_slides_create_image.js │ ├── test_slides_create_presentation.js │ ├── test_slides_create_sheets_chart.js │ ├── test_slides_create_slide.js │ ├── test_slides_create_textbox_with_text.js │ ├── test_slides_image_merging.js │ ├── test_slides_refresh_sheets_chart.js │ ├── test_slides_simple_text_replace.js │ ├── test_slides_text_merging.js │ └── test_slides_text_style_update.js └── tasks └── quickstart ├── README.md └── index.html /.eslintrc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module.exports = { 18 | 'extends': 'google', 19 | 'parserOptions': { 20 | 'ecmaVersion': 8, 21 | 'sourceType': 'script', 22 | }, 23 | 'env': { 24 | 'browser': true, 25 | }, 26 | 'plugins': [ 27 | 'html', 28 | ], 29 | 'rules': { 30 | 'require-jsdoc': 'off', 31 | 'max-len': ['error', {'code': 100}], 32 | 'camelcase': ['error', { 33 | 'ignoreDestructuring': true, 34 | 'ignoreImports': true, 35 | 'allow': ['client_id', 'access_type', 'redirect_uris'], 36 | }], 37 | 'no-unused-vars': 'off', 38 | }, 39 | }; 40 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners 16 | 17 | .github/ @googleworkspace/workspace-devrel-dpe 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | TODO 4 | 5 | ## Expected Behavior 6 | 7 | Sample URL: 8 | Description: 9 | 10 | ## Actual Behavior 11 | 12 | 13 | ## Steps to Reproduce the Problem 14 | 15 | 1. 16 | 1. 17 | 1. 18 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | commit-message: 8 | prefix: "chore(deps):" 9 | -------------------------------------------------------------------------------- /.github/linters/.htmlhintrc: -------------------------------------------------------------------------------- 1 | { 2 | "tagname-lowercase": true, 3 | "attr-lowercase": true, 4 | "attr-value-double-quotes": true, 5 | "attr-value-not-empty": false, 6 | "attr-no-duplication": true, 7 | "doctype-first": false, 8 | "tag-pair": true, 9 | "tag-self-close": false, 10 | "spec-char-escape": false, 11 | "id-unique": true, 12 | "src-not-empty": true, 13 | "title-require": false, 14 | "alt-require": true, 15 | "doctype-html5": true, 16 | "id-class-value": false, 17 | "style-disabled": false, 18 | "inline-style-disabled": false, 19 | "inline-script-disabled": false, 20 | "space-tab-mixed-disabled": "space", 21 | "id-class-ad-disabled": false, 22 | "href-abs-or-rel": false, 23 | "attr-unsafe-chars": true, 24 | "head-script-disabled": false 25 | } 26 | -------------------------------------------------------------------------------- /.github/linters/.yaml-lint.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ########################################### 3 | # These are the rules used for # 4 | # linting all the yaml files in the stack # 5 | # NOTE: # 6 | # You can disable line with: # 7 | # # yamllint disable-line # 8 | ########################################### 9 | rules: 10 | braces: 11 | level: warning 12 | min-spaces-inside: 0 13 | max-spaces-inside: 0 14 | min-spaces-inside-empty: 1 15 | max-spaces-inside-empty: 5 16 | brackets: 17 | level: warning 18 | min-spaces-inside: 0 19 | max-spaces-inside: 0 20 | min-spaces-inside-empty: 1 21 | max-spaces-inside-empty: 5 22 | colons: 23 | level: warning 24 | max-spaces-before: 0 25 | max-spaces-after: 1 26 | commas: 27 | level: warning 28 | max-spaces-before: 0 29 | min-spaces-after: 1 30 | max-spaces-after: 1 31 | comments: disable 32 | comments-indentation: disable 33 | document-end: disable 34 | document-start: 35 | level: warning 36 | present: true 37 | empty-lines: 38 | level: warning 39 | max: 2 40 | max-start: 0 41 | max-end: 0 42 | hyphens: 43 | level: warning 44 | max-spaces-after: 1 45 | indentation: 46 | level: warning 47 | spaces: consistent 48 | indent-sequences: true 49 | check-multi-line-strings: false 50 | key-duplicates: enable 51 | line-length: 52 | level: warning 53 | max: 120 54 | allow-non-breakable-words: true 55 | allow-non-breakable-inline-mappings: true 56 | new-line-at-end-of-file: disable 57 | new-lines: 58 | type: unix 59 | trailing-spaces: disable -------------------------------------------------------------------------------- /.github/sync-repo-settings.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # .github/sync-repo-settings.yaml 16 | # See https://github.com/googleapis/repo-automation-bots/tree/main/packages/sync-repo-settings for app options. 17 | rebaseMergeAllowed: true 18 | squashMergeAllowed: true 19 | mergeCommitAllowed: false 20 | deleteBranchOnMerge: true 21 | branchProtectionRules: 22 | - pattern: main 23 | isAdminEnforced: false 24 | requiresStrictStatusChecks: false 25 | requiredStatusCheckContexts: 26 | # .github/workflows/test.yml with a job called "test" 27 | - "test" 28 | # .github/workflows/lint.yml with a job called "lint" 29 | - "lint" 30 | # Google bots below 31 | - "cla/google" 32 | - "snippet-bot check" 33 | - "header-check" 34 | - "conventionalcommits.org" 35 | requiredApprovingReviewCount: 1 36 | requiresCodeOwnerReviews: true 37 | permissionRules: 38 | - team: workspace-devrel-dpe 39 | permission: admin 40 | - team: workspace-devrel 41 | permission: push 42 | -------------------------------------------------------------------------------- /.github/workflows/automation.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | --- 15 | name: Automation 16 | on: [ push, pull_request, workflow_dispatch ] 17 | jobs: 18 | dependabot: 19 | runs-on: ubuntu-latest 20 | if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }} 21 | env: 22 | PR_URL: ${{github.event.pull_request.html_url}} 23 | GITHUB_TOKEN: ${{secrets.GOOGLEWORKSPACE_BOT_TOKEN}} 24 | steps: 25 | - name: approve 26 | run: gh pr review --approve "$PR_URL" 27 | - name: merge 28 | run: gh pr merge --auto --squash --delete-branch "$PR_URL" 29 | default-branch-migration: 30 | # this job helps with migrating the default branch to main 31 | # it pushes main to master if master exists and main is the default branch 32 | # it pushes master to main if master is the default branch 33 | runs-on: ubuntu-latest 34 | if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }} 35 | steps: 36 | - uses: actions/checkout@v2 37 | with: 38 | fetch-depth: 0 39 | # required otherwise GitHub blocks infinite loops in pushes originating in an action 40 | token: ${{ secrets.GOOGLEWORKSPACE_BOT_TOKEN }} 41 | - name: Set env 42 | run: | 43 | # set DEFAULT BRANCH 44 | echo "DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')" >> "$GITHUB_ENV"; 45 | 46 | # set HAS_MASTER_BRANCH 47 | if [ -n "$(git ls-remote --heads origin master)" ]; then 48 | echo "HAS_MASTER_BRANCH=true" >> "$GITHUB_ENV" 49 | else 50 | echo "HAS_MASTER_BRANCH=false" >> "$GITHUB_ENV" 51 | fi 52 | env: 53 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 54 | - name: configure git 55 | run: | 56 | git config --global user.name 'googleworkspace-bot' 57 | git config --global user.email 'googleworkspace-bot@google.com' 58 | - if: ${{ env.DEFAULT_BRANCH == 'main' && env.HAS_MASTER_BRANCH == 'true' }} 59 | name: Update master branch from main 60 | run: | 61 | git checkout -B master 62 | git reset --hard origin/main 63 | git push origin master 64 | - if: ${{ env.DEFAULT_BRANCH == 'master'}} 65 | name: Update main branch from master 66 | run: | 67 | git checkout -B main 68 | git reset --hard origin/master 69 | git push origin main 70 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | --- 15 | name: Lint 16 | on: [push, pull_request, workflow_dispatch] 17 | jobs: 18 | lint: 19 | concurrency: 20 | group: ${{ github.head_ref || github.ref }} 21 | cancel-in-progress: true 22 | runs-on: ubuntu-20.04 23 | steps: 24 | - uses: actions/checkout@v3.0.2 25 | with: 26 | fetch-depth: 0 27 | - uses: actions/setup-node@v3 28 | with: 29 | node-version: "14" 30 | - run: npm ci 31 | - run: npm run lint 32 | - uses: github/super-linter/slim@v4.9.0 33 | if: always() 34 | env: 35 | ERROR_ON_MISSING_EXEC_BIT: true 36 | VALIDATE_JSCPD: false 37 | VALIDATE_JAVASCRIPT_STANDARD: false 38 | VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' }} 39 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 40 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Test 16 | on: [push, pull_request] 17 | jobs: 18 | test: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v2 22 | - run: | 23 | echo "No tests"; 24 | exit 1; 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # General 2 | .DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | # Icon must end with two \r 7 | Icon 8 | 9 | # Thumbnails 10 | ._* 11 | 12 | # Files that might appear in the root of a volume 13 | .DocumentRevisions-V100 14 | .fseventsd 15 | .Spotlight-V100 16 | .TemporaryItems 17 | .Trashes 18 | .VolumeIcon.icns 19 | .com.apple.timemachine.donotpresent 20 | 21 | # Directories potentially created on remote AFP share 22 | .AppleDB 23 | .AppleDesktop 24 | Network Trash Folder 25 | Temporary Items 26 | .apdisk 27 | node_modules -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | Please fill out either the individual or corporate Contributor License Agreement 9 | (CLA). 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then you'll need to sign an 13 | [individual CLA](https://developers.google.com/open-source/cla/individual). 14 | * If you work for a company that wants to allow you to contribute your work, 15 | then you'll need to sign a 16 | [corporate CLA](https://developers.google.com/open-source/cla/corporate). 17 | 18 | Follow either of the two links above to access the appropriate CLA and 19 | instructions for how to sign and return it. Once we receive it, we'll be able to 20 | accept your pull requests. 21 | 22 | ## Contributing A Patch 23 | 24 | 1. Submit an issue describing your proposed change to the repository in question. 25 | 1. The repository owner will respond to your issue promptly. 26 | 1. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above). 27 | 1. Fork the desired repository, develop and test your code changes. 28 | 1. Ensure that your code adheres to the existing style in the sample to which you are contributing. 29 | 1. Ensure that your code has an appropriate set of unit tests which all pass. 30 | 1. Submit a pull request! 31 | 32 | ## Style 33 | 34 | Samples in this repository follow the [JavaScript Semi-Standard 35 | Style](https://github.com/Flet/semistandard). 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # browser-samples 2 | 3 | Browser samples for [Google Workspace APIs](https://developers.google.com/workspace/) docs. 4 | 5 | ## APIs 6 | 7 | ### [Admin SDK](https://developers.google.com/admin-sdk/) 8 | 9 | ### [Apps Script API](https://developers.google.com/apps-script/api) 10 | 11 | - [Quickstart](apps-script/quickstart) 12 | 13 | ### [Calendar](https://developers.google.com/calendar) 14 | 15 | - [Quickstart](calendar/quickstart) 16 | 17 | ### [Classroom](https://developers.google.com/classroom) 18 | 19 | - [Quickstart](classroom/quickstart) 20 | 21 | ### [Drive](https://developers.google.com/drive/v3) 22 | 23 | - [Quickstart](drive/quickstart) 24 | 25 | ### [Docs](https://developers.google.com/docs) 26 | 27 | - [Quickstart](docs/quickstart) 28 | 29 | ### [Gmail](https://developers.google.com/gmail/api/) 30 | 31 | - [Quickstart](gmail/quickstart) 32 | 33 | ### [People](https://developers.google.com/people/) 34 | 35 | - [Quickstart](people/quickstart) 36 | 37 | ### [Sheets](https://developers.google.com/sheets/api/) 38 | 39 | - [Quickstart](sheets/quickstart) 40 | - [Snippets](sheets/snippets) 41 | 42 | ### [Slides](https://developers.google.com/slides/) 43 | 44 | - [Quickstart](slides/quickstart) 45 | - [Snippets](slides/snippets) 46 | 47 | ## Setup 48 | 49 | 1. Clone this repository. 50 | 1. Follow the README instructions in the API folder to run and test samples. 51 | 52 | ## Troubleshooting 53 | 54 | Here are some tips for troubleshooting errors when running these samples: 55 | 56 | - Be sure to create a local HTTP server to server the HTML page in the quickstart example. Otherwise the `gapi` client may encounter errors. 57 | - Check your browser console for errors. In Chrome, this is under **View > Developer > JavaScript Console** 58 | 59 | Below are some possible errors you may encounter: 60 | 61 | ### Error: origin_mismatch 62 | 63 | This error will occur during the authorization flow if the host and port used to serve the web page doesn't match an allowed JavaScript origin on your Google Developers Console project. Make sure to correctly specify **Authorized JavaScript origins** in the quickstart steps. 64 | 65 | ### idpiframe_initialization_failed: Failed to read the 'localStorage' property from 'Window' 66 | 67 | The Google Sign-in library requires that third-party cookies and data storage is enabled in the web browser. For users that run into this error, prompt them to enable the feature or add an exception for accounts.google.com. 68 | 69 | ### idpiframe_initialization_failed: Not a valid origin for the client 70 | 71 | The Google Sign-in library requires that the domain registered in the Google Developers Console matches the domain being used to host the web page. Make sure to correctly specify **Authorized JavaScript origins** in the quickstart steps. 72 | 73 | ## Linting 74 | 75 | This project uses [htmllint](https://github.com/htmllint/htmllint). 76 | 77 | Install & run: 78 | 79 | ```sh 80 | sudo npm install -g htmllint-cli 81 | htmllint 82 | ``` 83 | 84 | Configure [options](https://github.com/htmllint/htmllint/wiki/Options) in the `.htmllintrc`. 85 | 86 | ## Client Library 87 | 88 | Google Workspace APIs use the [Google API JavaScript client library](https://github.com/google/google-api-javascript-client). 89 | 90 | ## Contributing 91 | 92 | Contributions welcome! See the [Contributing Guide](CONTRIBUTING.md). 93 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Report a security issue 2 | 3 | To report a security issue, please use [https://g.co/vulnz](https://g.co/vulnz). We use 4 | [https://g.co/vulnz](https://g.co/vulnz) for our intake, and do coordination and disclosure here on 5 | GitHub (including using GitHub Security Advisory). The Google Security Team will 6 | respond within 5 working days of your report on [https://g.co/vulnz](https://g.co/vulnz). 7 | -------------------------------------------------------------------------------- /adminSDK/README.md: -------------------------------------------------------------------------------- 1 | # Admin SDK 2 | 3 | Manage your domains and apps with the [Admin SDK](https://developers.google.com/admin-sdk/). 4 | -------------------------------------------------------------------------------- /adminSDK/directory/index.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | Directory API Quickstart 21 | 22 | 23 | 24 |

Directory API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
165 |     
166 |     
167 |   
168 | 
169 | 
170 | 


--------------------------------------------------------------------------------
/adminSDK/reports/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Reports API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Reports API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
169 |     
170 |     
171 |   
172 | 
173 | 
174 | 


--------------------------------------------------------------------------------
/adminSDK/reseller/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Google Workspace Reseller API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Google WOrkspace Reseller API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
166 |     
167 |     
168 |   
169 | 
170 | 
171 | 


--------------------------------------------------------------------------------
/apps-script/execute/index.js:
--------------------------------------------------------------------------------
 1 | /**
 2 |  * @license
 3 |  * Copyright Google Inc.
 4 |  *
 5 |  * Licensed under the Apache License, Version 2.0 (the "License");
 6 |  * you may not use this file except in compliance with the License.
 7 |  * You may obtain a copy of the License at
 8 |  *
 9 |  *     https://www.apache.org/licenses/LICENSE-2.0
10 |  *
11 |  * Unless required by applicable law or agreed to in writing, software
12 |  * distributed under the License is distributed on an "AS IS" BASIS,
13 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 |  * See the License for the specific language governing permissions and
15 |  * limitations under the License.
16 |  */
17 | // [START apps_script_api_execute]
18 | /**
19 |  * Load the API and make an API call.  Display the results on the screen.
20 |  */
21 | function callScriptFunction() {
22 |   const scriptId = '';
23 | 
24 |   // Call the Apps Script API run method
25 |   //   'scriptId' is the URL parameter that states what script to run
26 |   //   'resource' describes the run request body (with the function name
27 |   //              to execute)
28 |   try {
29 |     gapi.client.script.scripts.run({
30 |       'scriptId': scriptId,
31 |       'resource': {
32 |         'function': 'getFoldersUnderRoot',
33 |       },
34 |     }).then(function(resp) {
35 |       const result = resp.result;
36 |       if (result.error && result.error.status) {
37 |         // The API encountered a problem before the script
38 |         // started executing.
39 |         appendPre('Error calling API:');
40 |         appendPre(JSON.stringify(result, null, 2));
41 |       } else if (result.error) {
42 |         // The API executed, but the script returned an error.
43 | 
44 |         // Extract the first (and only) set of error details.
45 |         // The values of this object are the script's 'errorMessage' and
46 |         // 'errorType', and an array of stack trace elements.
47 |         const error = result.error.details[0];
48 |         appendPre('Script error message: ' + error.errorMessage);
49 | 
50 |         if (error.scriptStackTraceElements) {
51 |           // There may not be a stacktrace if the script didn't start
52 |           // executing.
53 |           appendPre('Script error stacktrace:');
54 |           for (let i = 0; i < error.scriptStackTraceElements.length; i++) {
55 |             const trace = error.scriptStackTraceElements[i];
56 |             appendPre('\t' + trace.function + ':' + trace.lineNumber);
57 |           }
58 |         }
59 |       } else {
60 |         // The structure of the result will depend upon what the Apps
61 |         // Script function returns. Here, the function returns an Apps
62 |         // Script Object with String keys and values, and so the result
63 |         // is treated as a JavaScript object (folderSet).
64 | 
65 |         const folderSet = result.response.result;
66 |         if (Object.keys(folderSet).length == 0) {
67 |           appendPre('No folders returned!');
68 |         } else {
69 |           appendPre('Folders under your root folder:');
70 |           Object.keys(folderSet).forEach(function(id) {
71 |             appendPre('\t' + folderSet[id] + ' (' + id + ')');
72 |           });
73 |         }
74 |       }
75 |     });
76 |   } catch (err) {
77 |     document.getElementById('content').innerText = err.message;
78 |     return;
79 |   }
80 | }
81 | 
82 | // [END apps_script_api_execute]
83 | 


--------------------------------------------------------------------------------
/apps-script/quickstart/README.md:
--------------------------------------------------------------------------------
 1 | # Google Apps Script API Browser Quickstart
 2 | 
 3 | Complete the steps described in the [quickstart instructions](https://developers.google.com/apps-script/api/quickstart/js),
 4 | and in about five minutes you'll have a simple browser application that makes requests to the
 5 | Apps Script API.
 6 | 
 7 | ## Run
 8 | 
 9 | After following the quickstart instructions, run the sample:
10 | 
11 | ```shell
12 | python3 -m http.server 8000
13 | ```
14 | 
15 | And opening the web page:
16 | 
17 | ```shell
18 | open http://localhost:8000
19 | ```
20 | 


--------------------------------------------------------------------------------
/apps-script/quickstart/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Google Apps Script API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Google Apps Script API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
172 |     
173 |     
174 |   
175 | 
176 | 
177 | 


--------------------------------------------------------------------------------
/calendar/quickstart/README.md:
--------------------------------------------------------------------------------
 1 | # Google Calendar Web Quickstart
 2 | 
 3 | Complete the steps described in the [Google Calendar Browser Quickstart](
 4 | https://developers.google.com/calendar/quickstart/js), and in about five minutes
 5 | you'll have a simple browser application that makes requests to the Google
 6 | Calendar API.
 7 | 
 8 | ## Run
 9 | 
10 | After following the quickstart instructions, run the sample:
11 | 
12 | ```shell
13 | python3 -m http.server 8000
14 | ```
15 | 
16 | And opening the web page:
17 | 
18 | ```shell
19 | open http://localhost:8000
20 | ```
21 | 
22 | 


--------------------------------------------------------------------------------
/calendar/quickstart/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Google Calendar API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Google Calendar API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
169 |     
170 |     
171 |   
172 | 
173 | 
174 | 


--------------------------------------------------------------------------------
/classroom/quickstart/README.md:
--------------------------------------------------------------------------------
 1 | # Google Classroom Browser Quickstart
 2 | 
 3 | Complete the steps described in the [quickstart instructions](
 4 | https://developers.google.com/classroom/quickstart/js), and in about
 5 | five minutes you'll have a simple browser application that makes requests to the
 6 | classroom API.
 7 | 
 8 | ## Run
 9 | 
10 | After following the quickstart instructions, run the sample:
11 | 
12 | ```shell
13 | python3 -m http.server 8000
14 | ```
15 | 
16 | And opening the web page:
17 | 
18 | ```shell
19 | open http://localhost:8000
20 | ```
21 | 


--------------------------------------------------------------------------------
/classroom/quickstart/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Classroom API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Classroom API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
162 |     
163 |     
164 |   
165 | 
166 | 
167 | 


--------------------------------------------------------------------------------
/docs/quickstart/README.md:
--------------------------------------------------------------------------------
 1 | # Docs API Browser Quickstart
 2 | 
 3 | Complete the steps described in the [quickstart instructions](
 4 | https://developers.google.com/docs/api/quickstart/js), and in about
 5 | five minutes you'll have a simple browser application that makes requests to the
 6 | Docs API.
 7 | 
 8 | ## Run
 9 | 
10 | After following the quickstart instructions, run the sample:
11 | 
12 | ```shell
13 | python3 -m http.server 8000
14 | ```
15 | 
16 | And opening the web page:
17 | 
18 | ```shell
19 | open http://localhost:8000
20 | ```
21 | 


--------------------------------------------------------------------------------
/docs/quickstart/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Google Docs API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Google Docs API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
153 |     
154 |     
155 |   
156 | 
157 | 
158 | 


--------------------------------------------------------------------------------
/drive/picker/helloworld.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 | 
 20 |   Picker API Quickstart
 21 |   
 22 | 
 23 | 
 24 | 

Picker API API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 | 
172 | 
173 | 
174 | 
175 | 
176 | 
177 | 


--------------------------------------------------------------------------------
/drive/quickstart/README.md:
--------------------------------------------------------------------------------
 1 | # Drive API Browser Quickstart
 2 | 
 3 | Complete the steps described in the [quickstart instructions](
 4 | https://developers.google.com/drive/v3/web/quickstart/js), and in about
 5 | five minutes you'll have a simple browser application that makes requests to the
 6 | Drive API.
 7 | 
 8 | ## Run
 9 | 
10 | After following the quickstart instructions, run the sample:
11 | 
12 | ```shell
13 | python3 -m http.server 8000
14 | ```
15 | 
16 | And opening the web page:
17 | 
18 | ```shell
19 | open http://localhost:8000
20 | ```
21 | 
22 | 


--------------------------------------------------------------------------------
/drive/quickstart/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Drive API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Drive API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
161 |     
162 |     
163 |   
164 | 
165 | 
166 | 


--------------------------------------------------------------------------------
/gmail/quickstart/README.md:
--------------------------------------------------------------------------------
 1 | # Gmail API Browser Quickstart
 2 | 
 3 | Complete the steps described in the [quickstart instructions](
 4 | https://developers.google.com/gmail/api/quickstart/js), and in about
 5 | five minutes you'll have a simple browser application that makes requests to the
 6 | Gmail API.
 7 | 
 8 | ## Run
 9 | 
10 | After following the quickstart instructions, run the sample:
11 | 
12 | ```shell
13 | python3 -m http.server 8000
14 | ```
15 | 
16 | And opening the web page:
17 | 
18 | ```shell
19 | open http://localhost:8000
20 | ```
21 | 
22 | 
23 | 


--------------------------------------------------------------------------------
/gmail/quickstart/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Gmail API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Gmail API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
161 |     
162 |     
163 |   
164 | 
165 | 
166 | 


--------------------------------------------------------------------------------
/images/googlelogo_color_272x92dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleworkspace/browser-samples/5a93462bbc38fa39609cf69c6ecd28c48e4f24bb/images/googlelogo_color_272x92dp.png


--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
 1 | {
 2 |   "name": "@gsuite/samples",
 3 |   "version": "1.0.0",
 4 |   "description": "Node.js samples for [G Suite API](https://developers.google.com/gsuite/) docs.",
 5 |   "license": "MIT",
 6 |   "author": "Grant Timmerman",
 7 |   "keywords": [
 8 |     "G Suite",
 9 |     "Apps Script",
10 |     "Calendar",
11 |     "Drive",
12 |     "Sheets",
13 |     "Slides",
14 |     "API"
15 |   ],
16 |   "devDependencies": {
17 |     "eslint": "^8.14.0",
18 |     "eslint-config-google": "^0.14",
19 |     "eslint-plugin-html": "^6.2.0"
20 |   },
21 |   "scripts": {
22 |     "lint": "eslint **/*.js **/*.html",
23 |     "lint:fix": "eslint --fix **/*.js **/*.html"
24 |   },
25 |   "eslintIgnore": [
26 |     "getFoldersUnderRoot.js",
27 |     "**/node_modules/**"
28 |   ]
29 | }
30 | 


--------------------------------------------------------------------------------
/people/quickstart/README.md:
--------------------------------------------------------------------------------
 1 | # Google People API Browser Quickstart
 2 | 
 3 | Complete the steps described in the [quickstart instructions](https://developers.google.com/people/quickstart/js), and in about
 4 | five minutes you'll have a simple browser application that makes requests to the
 5 | People API.
 6 | 
 7 | ## Run
 8 | 
 9 | After following the quickstart instructions, run the sample:
10 | 
11 | ```shell
12 | python3 -m http.server 8000
13 | ```
14 | 
15 | And opening the web page:
16 | 
17 | ```shell
18 | open http://localhost:8000
19 | ```
20 | 
21 | 


--------------------------------------------------------------------------------
/people/quickstart/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     People API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

People API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
169 |     
170 |     
171 |   
172 | 
173 | 
174 | 


--------------------------------------------------------------------------------
/sheets/quickstart/README.md:
--------------------------------------------------------------------------------
 1 | # Google Sheets API Browser Quickstart
 2 | 
 3 | Complete the steps described in the [quickstart instructions](
 4 | https://developers.google.com/sheets/api/quickstart/javascript), and in about
 5 | five minutes you'll have a simple browser application that makes requests to the
 6 | Google Sheets API.
 7 | 
 8 | ## Run
 9 | 
10 | After following the quickstart instructions, run the sample:
11 | 
12 | ```shell
13 | python3 -m http.server 8000
14 | ```
15 | 
16 | And opening the web page:
17 | 
18 | ```shell
19 | open http://localhost:8000
20 | ```
21 | 
22 | 
23 | 


--------------------------------------------------------------------------------
/sheets/quickstart/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Sheets API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Sheets API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
163 |     
164 |     
165 |   
166 | 
167 | 
168 | 


--------------------------------------------------------------------------------
/sheets/snippets/README.md:
--------------------------------------------------------------------------------
 1 | # Google Sheets Browser Snippets
 2 | 
 3 | JavaScript snippets from the [Google Sheets API Guide](https://developers.google.com/sheets/api/guides/values).
 4 | 
 5 | ## Run tests
 6 | 
 7 | Run the snippet tests by starting a local web server:
 8 | 
 9 | ```shell
10 | python3 -m http.server 8000
11 | ```
12 | 
13 | And opening the web page:
14 | 
15 | ```shell
16 | open http://localhost:8000
17 | ```
18 | 


--------------------------------------------------------------------------------
/sheets/snippets/base_test.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2018 Google LLC
 2 | 
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | 
 7 | //     https://www.apache.org/licenses/LICENSE-2.0
 8 | 
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | const filesToDelete = [];
16 | function deleteFileOnCleanup(fileId) {
17 |   filesToDelete.push(fileId);
18 | }
19 | 
20 | function tearDown() {
21 |   for (let i = 0; i < filesToDelete.length; ++i) {
22 |     const presentationId = filesToDelete[i];
23 |     gapi.client.drive.files.delete({
24 |       fileId: presentationId,
25 |     });
26 |   }
27 | }
28 | 
29 | function createTestSpreadsheet(callback) {
30 |   gapi.client.sheets.spreadsheets.create({
31 |     properties: {
32 |       title: 'Test Spreadsheet',
33 |     },
34 |   }).then(function(sheet) {
35 |     deleteFileOnCleanup(sheet.result.spreadsheetId);
36 |     callback(sheet.result.spreadsheetId);
37 |   });
38 | };
39 | 
40 | function populateValues(spreadsheetId, callback) {
41 |   gapi.client.sheets.spreadsheets.batchUpdate({
42 |     spreadsheetId: spreadsheetId,
43 |     resource: {
44 |       requests: [{
45 |         repeatCell: {
46 |           range: {
47 |             sheetId: 0,
48 |             startRowIndex: 0,
49 |             endRowIndex: 10,
50 |             startColumnIndex: 0,
51 |             endColumnIndex: 10,
52 |           },
53 |           cell: {
54 |             userEnteredValue: {
55 |               stringValue: 'Hello',
56 |             },
57 |           },
58 |           fields: 'userEnteredValue',
59 |         },
60 |       }],
61 |     },
62 |   }).then((response) => {
63 |     callback(spreadsheetId);
64 |   });
65 | };
66 | 


--------------------------------------------------------------------------------
/sheets/snippets/index.html:
--------------------------------------------------------------------------------
  1 | 
 13 | 
 14 | 
 15 | 
 16 |   
 17 |     Google Sheets API Quickstart
 18 |     
 19 |     
 20 |   
 21 |   
 22 |     

Google Sheets API

23 |

Snippets - Javascript

24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 |

 33 |     
 34 |     
 35 |     
 36 |     
 37 |     
 38 |     
 39 |     
 40 |     
 41 |     
 42 | 
 43 |     
 44 |     
 45 |     
 46 |     
 47 |     
 48 |     
 49 |     
 50 |     
 51 |     
 52 |     
 53 | 
 54 |     
184 |     
185 |     
186 |   
187 | 
188 | 
189 | 


--------------------------------------------------------------------------------
/sheets/snippets/sheets_append_values.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | // [START sheets_append_values]
16 | function appendValues(spreadsheetId, range, valueInputOption, _values, callback) {
17 |   let values = [
18 |     [
19 |       // Cell values ...
20 |     ],
21 |     // Additional rows ...
22 |   ];
23 |   values = _values;
24 |   const body = {
25 |     values: values,
26 |   };
27 |   try {
28 |     gapi.client.sheets.spreadsheets.values.append({
29 |       spreadsheetId: spreadsheetId,
30 |       range: range,
31 |       valueInputOption: valueInputOption,
32 |       resource: body,
33 |     }).then((response) => {
34 |       const result = response.result;
35 |       console.log(`${result.updates.updatedCells} cells appended.`);
36 |       if (callback) callback(response);
37 |     });
38 |   } catch (err) {
39 |     document.getElementById('content').innerText = err.message;
40 |     return;
41 |   }
42 | }
43 | // [END sheets_append_values]
44 | 


--------------------------------------------------------------------------------
/sheets/snippets/sheets_batch_get_values.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START sheets_batch_get_values]
15 | function batchGetValues(spreadsheetId, _ranges, callback) {
16 |   let ranges = [
17 |     // Range names ...
18 |   ];
19 |   ranges = _ranges;
20 |   try {
21 |     gapi.client.sheets.spreadsheets.values.batchGet({
22 |       spreadsheetId: spreadsheetId,
23 |       ranges: ranges,
24 |     }).then((response) => {
25 |       const result = response.result;
26 |       console.log(`${result.valueRanges.length} ranges retrieved.`);
27 |       if (callback) callback(response);
28 |     });
29 |   } catch (err) {
30 |     document.getElementById('content').innerText = err.message;
31 |     return;
32 |   }
33 | }
34 | //  [END sheets_batch_get_values]
35 | 


--------------------------------------------------------------------------------
/sheets/snippets/sheets_batch_update.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START sheets_batch_update]
15 | function batchUpdate(spreadsheetId, title, find, replacement, callback) {
16 |   const requests = [];
17 |   // Change the spreadsheet's title.
18 |   requests.push({
19 |     updateSpreadsheetProperties: {
20 |       properties: {
21 |         title: title,
22 |       },
23 |       fields: 'title',
24 |     },
25 |   });
26 |   // Find and replace text.
27 |   requests.push({
28 |     findReplace: {
29 |       find: find,
30 |       replacement: replacement,
31 |       allSheets: true,
32 |     },
33 |   });
34 |   try {
35 |     // Add additional requests (operations) ...
36 |     const batchUpdateRequest = {requests: requests};
37 |     gapi.client.sheets.spreadsheets.batchUpdate({
38 |       spreadsheetId: spreadsheetId,
39 |       resource: batchUpdateRequest,
40 |     }).then((response) => {
41 |       const findReplaceResponse = response.result.replies[1].findReplace;
42 |       console.log(`${findReplaceResponse.occurrencesChanged} replacements made.`);
43 |       if (callback) callback(response);
44 |     });
45 |   } catch (err) {
46 |     document.getElementById('content').innerText = err.message;
47 |     return;
48 |   }
49 | }
50 | //  [END sheets_batch_update]
51 | 


--------------------------------------------------------------------------------
/sheets/snippets/sheets_batch_update_values.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START sheets_batch_update_values]
15 | function batchUpdateValues(spreadsheetId, range, valueInputOption, _values, callback) {
16 |   let values = [
17 |     [
18 |       // Cell values ...
19 |     ],
20 |     // Additional rows ...
21 |   ];
22 |   values = _values;
23 |   const data = [];
24 |   data.push({
25 |     range: range,
26 |     values: values,
27 |   });
28 |   // Additional ranges to update.
29 | 
30 |   const body = {
31 |     data: data,
32 |     valueInputOption: valueInputOption,
33 |   };
34 |   try {
35 |     gapi.client.sheets.spreadsheets.values.batchUpdate({
36 |       spreadsheetId: spreadsheetId,
37 |       resource: body,
38 |     }).then((response) => {
39 |       const result = response.result;
40 |       console.log(`${result.totalUpdatedCells} cells updated.`);
41 |       if (callback) callback(response);
42 |     });
43 |   } catch (err) {
44 |     document.getElementById('content').innerText = err.message;
45 |     return;
46 |   }
47 | }
48 | //  [END sheets_batch_update_values]
49 | 


--------------------------------------------------------------------------------
/sheets/snippets/sheets_conditional_formatting.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START sheets_conditional_formatting]
15 | function conditionalFormatting(spreadsheetId, callback) {
16 |   const myRange = {
17 |     sheetId: 0,
18 |     startRowIndex: 1,
19 |     endRowIndex: 11,
20 |     startColumnIndex: 0,
21 |     endColumnIndex: 4,
22 |   };
23 |   const requests = [{
24 |     addConditionalFormatRule: {
25 |       rule: {
26 |         ranges: [myRange],
27 |         booleanRule: {
28 |           condition: {
29 |             type: 'CUSTOM_FORMULA',
30 |             values: [{userEnteredValue: '=GT($D2,median($D$2:$D$11))'}],
31 |           },
32 |           format: {
33 |             textFormat: {foregroundColor: {red: 0.8}},
34 |           },
35 |         },
36 |       },
37 |       index: 0,
38 |     },
39 |   }, {
40 |     addConditionalFormatRule: {
41 |       rule: {
42 |         ranges: [myRange],
43 |         booleanRule: {
44 |           condition: {
45 |             type: 'CUSTOM_FORMULA',
46 |             values: [{userEnteredValue: '=LT($D2,median($D$2:$D$11))'}],
47 |           },
48 |           format: {
49 |             backgroundColor: {red: 1, green: 0.4, blue: 0.4},
50 |           },
51 |         },
52 |       },
53 |       index: 0,
54 |     },
55 |   }];
56 | 
57 |   const body = {
58 |     requests,
59 |   };
60 |   try {
61 |     gapi.client.sheets.spreadsheets.batchUpdate({
62 |       spreadsheetId: spreadsheetId,
63 |       resource: body,
64 |     }).then((response) => {
65 |       const result = response.result;
66 |       console.log(`${result.replies.length} cells updated.`);
67 |       if (callback) callback(response);
68 |     });
69 |   } catch (err) {
70 |     document.getElementById('content').innerText = err.message;
71 |     return;
72 |   }
73 | }
74 | //  [END sheets_conditional_formatting]
75 | 


--------------------------------------------------------------------------------
/sheets/snippets/sheets_create.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START sheets_create]
15 | function create(title, callback) {
16 |   try {
17 |     gapi.client.sheets.spreadsheets.create({
18 |       properties: {
19 |         title: title,
20 |       },
21 |     }).then((response) => {
22 |       if (callback) callback(response);
23 |       console.log('Spreadsheet ID: ' + response.result.spreadsheetId);
24 |     });
25 |   } catch (err) {
26 |     document.getElementById('content').innerText = err.message;
27 |     return;
28 |   }
29 | }
30 | //  [END sheets_create]
31 | 


--------------------------------------------------------------------------------
/sheets/snippets/sheets_get_values.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START sheets_get_values]
15 | function getValues(spreadsheetId, range, callback) {
16 |   try {
17 |     gapi.client.sheets.spreadsheets.values.get({
18 |       spreadsheetId: spreadsheetId,
19 |       range: range,
20 |     }).then((response) => {
21 |       const result = response.result;
22 |       const numRows = result.values ? result.values.length : 0;
23 |       console.log(`${numRows} rows retrieved.`);
24 |       if (callback) callback(response);
25 |     });
26 |   } catch (err) {
27 |     document.getElementById('content').innerText = err.message;
28 |     return;
29 |   }
30 | }
31 | // [END sheets_get_values]
32 | 


--------------------------------------------------------------------------------
/sheets/snippets/sheets_pivot_tables.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | // [START sheets_pivot_tables]
16 | function pivotTable(spreadsheetId, callback) {
17 |   // Create two sheets for our pivot table
18 |   const requests = [{
19 |     addSheet: {},
20 |   }, {
21 |     addSheet: {},
22 |   }];
23 |   const batchUpdateRequest = {requests: requests};
24 |   try {
25 |     gapi.client.sheets.spreadsheets.batchUpdate({
26 |       spreadsheetId: spreadsheetId,
27 |       resource: batchUpdateRequest,
28 |     }).then((response) => {
29 |       const sourceSheetId = response.result.replies[0].addSheet.properties.sheetId;
30 |       const targetSheetId = response.result.replies[1].addSheet.properties.sheetId;
31 | 
32 |       const requests = [{
33 |         updateCells: {
34 |           rows: {
35 |             values: [{
36 |               pivotTable: {
37 |                 source: {
38 |                   sheetId: sourceSheetId,
39 |                   startRowIndex: 0,
40 |                   startColumnIndex: 0,
41 |                   endRowIndex: 20,
42 |                   endColumnIndex: 7,
43 |                 },
44 |                 rows: [{
45 |                   sourceColumnOffset: 1,
46 |                   showTotals: true,
47 |                   sortOrder: 'ASCENDING',
48 |                 }],
49 |                 columns: [{
50 |                   sourceColumnOffset: 4,
51 |                   sortOrder: 'ASCENDING',
52 |                   showTotals: true,
53 |                 }],
54 |                 values: [{
55 |                   summarizeFunction: 'COUNTA',
56 |                   sourceColumnOffset: 4,
57 |                 }],
58 |                 valueLayout: 'HORIZONTAL',
59 |               },
60 |             },
61 |             ],
62 |           },
63 |           start: {
64 |             sheetId: targetSheetId,
65 |             rowIndex: 0,
66 |             columnIndex: 0,
67 |           },
68 |           fields: 'pivotTable',
69 |         },
70 |       }];
71 | 
72 |       const body = {
73 |         requests,
74 |       };
75 |       gapi.client.sheets.spreadsheets.batchUpdate({
76 |         spreadsheetId: spreadsheetId,
77 |         resource: body,
78 |       }).then((response) => {
79 |         if (callback) callback(response);
80 |       });
81 |     });
82 |   } catch (err) {
83 |     document.getElementById('content').innerText = err.message;
84 |     return;
85 |   }
86 | }
87 | // [END sheets_pivot_tables]
88 | 


--------------------------------------------------------------------------------
/sheets/snippets/sheets_update_values.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START sheets_update_values]
15 | function updateValues(spreadsheetId, range, valueInputOption, _values, callback) {
16 |   let values = [
17 |     [
18 |       // Cell values ...
19 |     ],
20 |     // Additional rows ...
21 |   ];
22 |   values = _values;
23 |   const body = {
24 |     values: values,
25 |   };
26 |   try {
27 |     gapi.client.sheets.spreadsheets.values.update({
28 |       spreadsheetId: spreadsheetId,
29 |       range: range,
30 |       valueInputOption: valueInputOption,
31 |       resource: body,
32 |     }).then((response) => {
33 |       const result = response.result;
34 |       console.log(`${result.updatedCells} cells updated.`);
35 |       if (callback) callback(response);
36 |     });
37 |   } catch (err) {
38 |     document.getElementById('content').innerText = err.message;
39 |     return;
40 |   }
41 | }
42 | //  [END sheets_update_values]
43 | 


--------------------------------------------------------------------------------
/sheets/snippets/snippets.js:
--------------------------------------------------------------------------------
  1 | // Copyright 2018 Google LLC
  2 | //
  3 | // Licensed under the Apache License, Version 2.0 (the "License");
  4 | // you may not use this file except in compliance with the License.
  5 | // You may obtain a copy of the License at
  6 | //
  7 | //      http://www.apache.org/licenses/LICENSE-2.0
  8 | //
  9 | // Unless required by applicable law or agreed to in writing, software
 10 | // distributed under the License is distributed on an "AS IS" BASIS,
 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12 | // See the License for the specific language governing permissions and
 13 | // limitations under the License.
 14 | 
 15 | function create(title, callback) {
 16 |   // [START sheets_create]
 17 |   gapi.client.sheets.spreadsheets.create({
 18 |     properties: {
 19 |       title: title,
 20 |     },
 21 |   }).then((response) => {
 22 |     // [START_EXCLUDE silent]
 23 |     callback(response);
 24 |     console.log('Spreadsheet ID: ' + response.result.spreadsheetId);
 25 |     // [END_EXCLUDE]
 26 |   });
 27 |   // [END sheets_create]
 28 | }
 29 | 
 30 | function batchUpdate(spreadsheetId, title, find, replacement, callback) {
 31 |   // [START sheets_batch_update]
 32 |   const requests = [];
 33 |   // Change the spreadsheet's title.
 34 |   requests.push({
 35 |     updateSpreadsheetProperties: {
 36 |       properties: {
 37 |         title: title,
 38 |       },
 39 |       fields: 'title',
 40 |     },
 41 |   });
 42 |   // Find and replace text.
 43 |   requests.push({
 44 |     findReplace: {
 45 |       find: find,
 46 |       replacement: replacement,
 47 |       allSheets: true,
 48 |     },
 49 |   });
 50 |   // Add additional requests (operations) ...
 51 | 
 52 |   const batchUpdateRequest = {requests: requests};
 53 | 
 54 |   gapi.client.sheets.spreadsheets.batchUpdate({
 55 |     spreadsheetId: spreadsheetId,
 56 |     resource: batchUpdateRequest,
 57 |   }).then((response) => {
 58 |     const findReplaceResponse = response.result.replies[1].findReplace;
 59 |     console.log(`${findReplaceResponse.occurrencesChanged} replacements made.`);
 60 |     // [START_EXCLUDE silent]
 61 |     callback(response);
 62 |     // [END_EXCLUDE]
 63 |   });
 64 |   // [END sheets_batch_update]
 65 | }
 66 | 
 67 | function getValues(spreadsheetId, range, callback) {
 68 |   // [START sheets_get_values]
 69 |   gapi.client.sheets.spreadsheets.values.get({
 70 |     spreadsheetId: spreadsheetId,
 71 |     range: range,
 72 |   }).then((response) => {
 73 |     const result = response.result;
 74 |     const numRows = result.values ? result.values.length : 0;
 75 |     console.log(`${numRows} rows retrieved.`);
 76 |     // [START_EXCLUDE silent]
 77 |     callback(response);
 78 |     // [END_EXCLUDE]
 79 |   });
 80 |   // [END sheets_get_values]
 81 | }
 82 | 
 83 | function batchGetValues(spreadsheetId, _ranges, callback) {
 84 |   // [START sheets_batch_get_values]
 85 |   let ranges = [
 86 |     // Range names ...
 87 |   ];
 88 |   // [START_EXCLUDE silent]
 89 |   ranges = _ranges;
 90 |   // [END_EXCLUDE]
 91 |   gapi.client.sheets.spreadsheets.values.batchGet({
 92 |     spreadsheetId: spreadsheetId,
 93 |     ranges: ranges,
 94 |   }).then((response) => {
 95 |     const result = response.result;
 96 |     console.log(`${result.valueRanges.length} ranges retrieved.`);
 97 |     // [START_EXCLUDE silent]
 98 |     callback(response);
 99 |     // [END_EXCLUDE]
100 |   });
101 |   // [END sheets_batch_get_values]
102 | }
103 | 
104 | function updateValues(spreadsheetId, range, valueInputOption, _values, callback) {
105 |   // [START sheets_update_values]
106 |   let values = [
107 |     [
108 |       // Cell values ...
109 |     ],
110 |     // Additional rows ...
111 |   ];
112 |   // [START_EXCLUDE silent]
113 |   values = _values;
114 |   // [END_EXCLUDE]
115 |   const body = {
116 |     values: values,
117 |   };
118 |   gapi.client.sheets.spreadsheets.values.update({
119 |     spreadsheetId: spreadsheetId,
120 |     range: range,
121 |     valueInputOption: valueInputOption,
122 |     resource: body,
123 |   }).then((response) => {
124 |     const result = response.result;
125 |     console.log(`${result.updatedCells} cells updated.`);
126 |     // [START_EXCLUDE silent]
127 |     callback(response);
128 |     // [END_EXCLUDE]
129 |   });
130 |   // [END sheets_update_values]
131 | }
132 | 
133 | function batchUpdateValues(spreadsheetId, range, valueInputOption, _values, callback) {
134 |   // [START sheets_batch_update_values]
135 |   let values = [
136 |     [
137 |       // Cell values ...
138 |     ],
139 |     // Additional rows ...
140 |   ];
141 |   // [START_EXCLUDE silent]
142 |   values = _values;
143 |   // [END_EXCLUDE]
144 |   const data = [];
145 |   data.push({
146 |     range: range,
147 |     values: values,
148 |   });
149 |   // Additional ranges to update.
150 | 
151 |   const body = {
152 |     data: data,
153 |     valueInputOption: valueInputOption,
154 |   };
155 |   gapi.client.sheets.spreadsheets.values.batchUpdate({
156 |     spreadsheetId: spreadsheetId,
157 |     resource: body,
158 |   }).then((response) => {
159 |     const result = response.result;
160 |     console.log(`${result.totalUpdatedCells} cells updated.`);
161 |     // [START_EXCLUDE silent]
162 |     callback(response);
163 |     // [END_EXCLUDE]
164 |   });
165 |   // [END sheets_batch_update_values]
166 | }
167 | 
168 | function appendValues(spreadsheetId, range, valueInputOption, _values, callback) {
169 |   // [START sheets_append_values]
170 |   let values = [
171 |     [
172 |       // Cell values ...
173 |     ],
174 |     // Additional rows ...
175 |   ];
176 |   // [START_EXCLUDE silent]
177 |   values = _values;
178 |   // [END_EXCLUDE]
179 |   const body = {
180 |     values: values,
181 |   };
182 |   gapi.client.sheets.spreadsheets.values.append({
183 |     spreadsheetId: spreadsheetId,
184 |     range: range,
185 |     valueInputOption: valueInputOption,
186 |     resource: body,
187 |   }).then((response) => {
188 |     const result = response.result;
189 |     console.log(`${result.updates.updatedCells} cells appended.`);
190 |     // [START_EXCLUDE silent]
191 |     callback(response);
192 |     // [END_EXCLUDE]
193 |   });
194 |   // [END sheets_append_values]
195 | }
196 | 
197 | 
198 | function pivotTable(spreadsheetId, callback) {
199 |   // Create two sheets for our pivot table
200 |   const requests = [{
201 |     addSheet: {},
202 |   }, {
203 |     addSheet: {},
204 |   }];
205 |   const batchUpdateRequest = {requests: requests};
206 |   gapi.client.sheets.spreadsheets.batchUpdate({
207 |     spreadsheetId: spreadsheetId,
208 |     resource: batchUpdateRequest,
209 |   }).then((response) => {
210 |     const sourceSheetId = response.result.replies[0].addSheet.properties.sheetId;
211 |     const targetSheetId = response.result.replies[1].addSheet.properties.sheetId;
212 |     // [START sheets_pivot_tables]
213 |     const requests = [{
214 |       updateCells: {
215 |         rows: {
216 |           values: [{
217 |             pivotTable: {
218 |               source: {
219 |                 sheetId: sourceSheetId,
220 |                 startRowIndex: 0,
221 |                 startColumnIndex: 0,
222 |                 endRowIndex: 20,
223 |                 endColumnIndex: 7,
224 |               },
225 |               rows: [{
226 |                 sourceColumnOffset: 1,
227 |                 showTotals: true,
228 |                 sortOrder: 'ASCENDING',
229 |               }],
230 |               columns: [{
231 |                 sourceColumnOffset: 4,
232 |                 sortOrder: 'ASCENDING',
233 |                 showTotals: true,
234 |               }],
235 |               values: [{
236 |                 summarizeFunction: 'COUNTA',
237 |                 sourceColumnOffset: 4,
238 |               }],
239 |               valueLayout: 'HORIZONTAL',
240 |             },
241 |           },
242 |           ],
243 |         },
244 |         start: {
245 |           sheetId: targetSheetId,
246 |           rowIndex: 0,
247 |           columnIndex: 0,
248 |         },
249 |         fields: 'pivotTable',
250 |       },
251 |     }];
252 | 
253 |     const body = {
254 |       requests,
255 |     };
256 |     gapi.client.sheets.spreadsheets.batchUpdate({
257 |       spreadsheetId: spreadsheetId,
258 |       resource: body,
259 |     }).then((response) => {
260 |       // [START_EXCLUDE silent]
261 |       callback(response);
262 |       // [END_EXCLUDE]
263 |     });
264 |     // [END sheets_pivot_tables]
265 |   });
266 | }
267 | 
268 | function conditionalFormatting(spreadsheetId, callback) {
269 |   // [START sheets_conditional_formatting]
270 |   const myRange = {
271 |     sheetId: 0,
272 |     startRowIndex: 1,
273 |     endRowIndex: 11,
274 |     startColumnIndex: 0,
275 |     endColumnIndex: 4,
276 |   };
277 |   const requests = [{
278 |     addConditionalFormatRule: {
279 |       rule: {
280 |         ranges: [myRange],
281 |         booleanRule: {
282 |           condition: {
283 |             type: 'CUSTOM_FORMULA',
284 |             values: [{userEnteredValue: '=GT($D2,median($D$2:$D$11))'}],
285 |           },
286 |           format: {
287 |             textFormat: {foregroundColor: {red: 0.8}},
288 |           },
289 |         },
290 |       },
291 |       index: 0,
292 |     },
293 |   }, {
294 |     addConditionalFormatRule: {
295 |       rule: {
296 |         ranges: [myRange],
297 |         booleanRule: {
298 |           condition: {
299 |             type: 'CUSTOM_FORMULA',
300 |             values: [{userEnteredValue: '=LT($D2,median($D$2:$D$11))'}],
301 |           },
302 |           format: {
303 |             backgroundColor: {red: 1, green: 0.4, blue: 0.4},
304 |           },
305 |         },
306 |       },
307 |       index: 0,
308 |     },
309 |   }];
310 | 
311 |   const body = {
312 |     requests,
313 |   };
314 |   gapi.client.sheets.spreadsheets.batchUpdate({
315 |     spreadsheetId: spreadsheetId,
316 |     resource: body,
317 |   }).then((response) => {
318 |     const result = response.result;
319 |     console.log(`${result.replies.length} cells updated.`);
320 |     // [START_EXCLUDE silent]
321 |     callback(response);
322 |     // [END_EXCLUDE]
323 |   });
324 |   // [END sheets_conditional_formatting]
325 | };
326 | 


--------------------------------------------------------------------------------
/sheets/snippets/test_append_spreadsheet_values.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testAppendSpreadsheetValues(done) {
16 |   createTestSpreadsheet(function(spreadsheetId) {
17 |     populateValues(spreadsheetId, function(spreadsheetId) {
18 |       appendValues(spreadsheetId, 'Sheet1', 'USER_ENTERED', [
19 |         ['A', 'B'],
20 |         ['C', 'D'],
21 |       ], function(response) {
22 |         assert.equal(response.result.tableRange, 'Sheet1!A1:J10');
23 |         const updates = response.result.updates;
24 |         assert.equal(updates.updatedRows, 2);
25 |         assert.equal(updates.updatedColumns, 2);
26 |         assert.equal(updates.updatedCells, 4);
27 |         done();
28 |       });
29 |     });
30 |   });
31 | }
32 | 


--------------------------------------------------------------------------------
/sheets/snippets/test_batch_get_spreadsheet_values.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testBatchGetSpreadsheetValues(done) {
16 |   createTestSpreadsheet(function(spreadsheetId) {
17 |     populateValues(spreadsheetId, function(spreadsheetId) {
18 |       batchGetValues(spreadsheetId, ['A1:A3', 'B1:C1'], function(response) {
19 |         const valueRanges = response.result.valueRanges;
20 |         assert.equal(valueRanges.length, 2);
21 |         const values = valueRanges[0].values;
22 |         assert.equal(values.length, 3);
23 |         done();
24 |       });
25 |     });
26 |   });
27 | }
28 | 


--------------------------------------------------------------------------------
/sheets/snippets/test_batch_update_spreadsheet.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testBatchUpdateSpreadsheet(done) {
16 |   createTestSpreadsheet(function(spreadsheetId) {
17 |     populateValues(spreadsheetId, function(spreadsheetId) {
18 |       batchUpdate(spreadsheetId, 'New Title', 'Hello', 'Goodbye', function(response) {
19 |         const replies = response.result.replies;
20 |         assert.equal(replies.length, 2);
21 |         const findReplaceResponse = replies[1].findReplace;
22 |         assert.equal(findReplaceResponse.occurrencesChanged, 100);
23 |         done();
24 |       });
25 |     });
26 |   });
27 | }
28 | 


--------------------------------------------------------------------------------
/sheets/snippets/test_batch_update_spreadsheet_values.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testBatchUpdateSpreadsheetValues(done) {
16 |   createTestSpreadsheet(function(spreadsheetId) {
17 |     batchUpdateValues(spreadsheetId, 'A1:B2', 'USER_ENTERED', [
18 |       ['A', 'B'],
19 |       ['C', 'D'],
20 |     ], function(responses) {
21 |       const response = responses.result.responses[0];
22 |       assert.equal(response.updatedRows, 2);
23 |       assert.equal(response.updatedColumns, 2);
24 |       assert.equal(response.updatedCells, 4);
25 |       done();
26 |     });
27 |   });
28 | }
29 | 


--------------------------------------------------------------------------------
/sheets/snippets/test_conditionally_format.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testConditionallyFormat(done) {
16 |   createTestSpreadsheet(function(spreadsheetId) {
17 |     populateValues(spreadsheetId, function(spreadsheetId) {
18 |       conditionalFormatting(spreadsheetId, function(response) {
19 |         assert.isNotNull(response.result.spreadsheetId);
20 |         assert.equal(response.result.replies.length, 2);
21 |         done();
22 |       });
23 |     });
24 |   });
25 | }
26 | 


--------------------------------------------------------------------------------
/sheets/snippets/test_create_pivot_tables.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testCreatePivotTables(done) {
16 |   createTestSpreadsheet(function(spreadsheetId) {
17 |     populateValues(spreadsheetId, function(spreadsheetId) {
18 |       pivotTable(spreadsheetId, function(response) {
19 |         assert.isNotNull(response.result);
20 |         done();
21 |       });
22 |     });
23 |   });
24 | }
25 | 


--------------------------------------------------------------------------------
/sheets/snippets/test_create_spreadsheet.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testCreateSpreadsheet(done) {
16 |   create('Title', (response) => {
17 |     console.log(`Created spreadsheet with ID: ${response.result.spreadsheetId}`);
18 |     assert.isNotNull(response.result.spreadsheetId);
19 |     done();
20 |   });
21 | }
22 | 


--------------------------------------------------------------------------------
/sheets/snippets/test_get_spreadsheet_values.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testGetSpreadsheetValues(done) {
16 |   createTestSpreadsheet(function(spreadsheetId) {
17 |     populateValues(spreadsheetId, function(spreadsheetId) {
18 |       getValues(spreadsheetId, 'A1:C2', function(response) {
19 |         const values = response.result.values;
20 |         assert.isNotNull(values);
21 |         assert.equal(values[0].length, 3);
22 |         done();
23 |       });
24 |     });
25 |   });
26 | }
27 | 


--------------------------------------------------------------------------------
/sheets/snippets/test_update_spreadsheet_values.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testUpdateSpreadsheetValues(done) {
16 |   createTestSpreadsheet(function(spreadsheetId) {
17 |     updateValues(spreadsheetId, 'A1:B2', 'USER_ENTERED', [
18 |       ['A', 'B'],
19 |       ['C', 'D'],
20 |     ], function(response) {
21 |       const result = response.result;
22 |       assert.equal(result.updatedRows, 2);
23 |       assert.equal(result.updatedColumns, 2);
24 |       assert.equal(result.updatedCells, 4);
25 |       done();
26 |     });
27 |   });
28 | }
29 | 


--------------------------------------------------------------------------------
/slides/quickstart/README.md:
--------------------------------------------------------------------------------
 1 | # Google Slides API Browser Quickstart
 2 | 
 3 | Complete the steps described in the [quickstart instructions](
 4 | https://developers.google.com/slides/quickstart/javascript), and in about five
 5 | minutes you'll have a simple browser application that makes requests to the
 6 | Google Slides API.
 7 | 
 8 | ## Run
 9 | 
10 | After following the quickstart instructions, run the sample:
11 | 
12 | ```shell
13 | python3 -m http.server 8000
14 | ```
15 | 
16 | And opening the web page:
17 | 
18 | ```shell
19 | open http://localhost:8000
20 | ```
21 | 
22 | 
23 | 


--------------------------------------------------------------------------------
/slides/quickstart/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Slides API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Slides API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
164 |     
165 |     
166 |   
167 | 
168 | 
169 | 


--------------------------------------------------------------------------------
/slides/snippets/README.md:
--------------------------------------------------------------------------------
 1 | # Google Slides Browser Snippets
 2 | 
 3 | JavaScript snippets from the [Google Slides API Guide](https://developers.google.com/slides/how-tos/presentations).
 4 | 
 5 | ## Run tests
 6 | 
 7 | Run the snippet tests by starting a local web server:
 8 | 
 9 | ```shell
10 | python3 -m http.server 8000
11 | ```
12 | 
13 | And opening the web page:
14 | 
15 | ```shell
16 | open http://localhost:8000
17 | ```
18 | 


--------------------------------------------------------------------------------
/slides/snippets/base_test.js:
--------------------------------------------------------------------------------
  1 | // Copyright 2018 Google LLC
  2 | //
  3 | // Licensed under the Apache License, Version 2.0 (the "License");
  4 | // you may not use this file except in compliance with the License.
  5 | // You may obtain a copy of the License at
  6 | //
  7 | //      http://www.apache.org/licenses/LICENSE-2.0
  8 | //
  9 | // Unless required by applicable law or agreed to in writing, software
 10 | // distributed under the License is distributed on an "AS IS" BASIS,
 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12 | // See the License for the specific language governing permissions and
 13 | // limitations under the License.
 14 | 
 15 | const filesToDelete = [];
 16 | function deleteFileOnCleanup(fileId) {
 17 |   filesToDelete.push(fileId);
 18 | }
 19 | 
 20 | function tearDown() {
 21 |   for (let i = 0; i < filesToDelete.length; ++i) {
 22 |     const presentationId = filesToDelete[i];
 23 |     gapi.client.drive.files.delete({
 24 |       fileId: presentationId,
 25 |     });
 26 |   }
 27 | }
 28 | 
 29 | function createTestPresentation(callback) {
 30 |   gapi.client.slides.presentations
 31 |       .create({
 32 |         title: 'Test Preso',
 33 |       })
 34 |       .then(function(data) {
 35 |         deleteFileOnCleanup(data.result.presentationId);
 36 |         callback(data.result.presentationId);
 37 |       });
 38 | }
 39 | 
 40 | function addSlides(presentationId, num, layout, callback) {
 41 |   const requests = [];
 42 |   const slideIds = [];
 43 |   for (let i = 0; i < num; ++i) {
 44 |     slideIds.push(`slide_${i}`);
 45 |     requests.push({
 46 |       createSlide: {
 47 |         objectId: slideIds[i],
 48 |         slideLayoutReference: {
 49 |           predefinedLayout: layout,
 50 |         },
 51 |       },
 52 |     });
 53 |   }
 54 |   const response = gapi.client.slides.presentations
 55 |       .batchUpdate({
 56 |         presentationId: presentationId,
 57 |         requests: requests,
 58 |       })
 59 |       .then((response) => {
 60 |         callback(slideIds);
 61 |       });
 62 | }
 63 | 
 64 | function createTestTextbox(presentationId, pageId, callback) {
 65 |   const boxId = 'MyTextBox_01';
 66 |   const pt350 = {
 67 |     magnitude: 350,
 68 |     unit: 'PT',
 69 |   };
 70 |   const requests = [
 71 |     {
 72 |       createShape: {
 73 |         objectId: boxId,
 74 |         shapeType: 'TEXT_BOX',
 75 |         elementProperties: {
 76 |           pageObjectId: pageId,
 77 |           size: {
 78 |             height: pt350,
 79 |             width: pt350,
 80 |           },
 81 |           transform: {
 82 |             scaleX: 1,
 83 |             scaleY: 1,
 84 |             translateX: 350,
 85 |             translateY: 100,
 86 |             unit: 'PT',
 87 |           },
 88 |         },
 89 |       },
 90 |     },
 91 |     {
 92 |       insertText: {
 93 |         objectId: boxId,
 94 |         insertionIndex: 0,
 95 |         text: 'New Box Text Inserted',
 96 |       },
 97 |     },
 98 |   ];
 99 |   const response = gapi.client.slides.presentations
100 |       .batchUpdate({
101 |         presentationId,
102 |         presentationId,
103 |         requests: requests,
104 |       })
105 |       .then((createTextboxResponse) => {
106 |         callback(createTextboxResponse.result.replies[0].createShape.objectId);
107 |       });
108 | }
109 | 
110 | function createTestSheetsChart(
111 |     presentationId,
112 |     pageId,
113 |     spreadsheetId,
114 |     sheetChartId,
115 |     callback,
116 | ) {
117 |   const chartId = 'MyChart_01';
118 |   const emu4M = {
119 |     magnitude: 4000000,
120 |     unit: 'EMU',
121 |   };
122 |   const requests = [
123 |     {
124 |       createSheetsChart: {
125 |         objectId: chartId,
126 |         spreadsheetId: spreadsheetId,
127 |         chartId: sheetChartId,
128 |         linkingMode: 'LINKED',
129 |         elementProperties: {
130 |           pageObjectId: pageId,
131 |           size: {
132 |             height: emu4M,
133 |             width: emu4M,
134 |           },
135 |           transform: {
136 |             scaleX: 1,
137 |             scaleY: 1,
138 |             translateX: 100000,
139 |             translateY: 100000,
140 |             unit: 'EMU',
141 |           },
142 |         },
143 |       },
144 |     },
145 |   ];
146 |   const response = gapi.client.slides.presentations
147 |       .batchUpdate({
148 |         presentationId,
149 |         presentationId,
150 |         requests: requests,
151 |       })
152 |       .then((createSheetsChartResponse) => {
153 |         callback(
154 |             createSheetsChartResponse.result.replies[0].createSheetsChart.objectId,
155 |         );
156 |       });
157 | }
158 | 


--------------------------------------------------------------------------------
/slides/snippets/index.html:
--------------------------------------------------------------------------------
  1 | 
 13 | 
 14 | 
 15 | 
 16 |   
 17 |     Google Slides API Quickstart
 18 |     
 19 |     
 20 |   
 21 |   
 22 |     

Google Slides API

23 |

Snippets - Javascript

24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 |

 33 |     
 34 |     
 35 |     
 36 |     
 37 |     
 38 |     
 39 |     
 40 |     
 41 |     
 42 |     
 43 |     
 44 |     
 45 |     
 46 |     
 47 |     
 48 |     
 49 |     
 50 |     
 51 |     
 52 |     
 53 |     
 54 |     
 55 |     
 56 |     
189 |     
190 |     
191 |   
192 | 
193 | 
194 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_copy_presentation.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START slides_copy_presentation]
15 | function copyPresentation(presentationId, copyTitle, callback) {
16 |   const request = {
17 |     name: copyTitle,
18 |   };
19 |   try {
20 |     gapi.client.drive.files.copy({
21 |       fileId: presentationId,
22 |       resource: request,
23 |     }).then((driveResponse) => {
24 |       const presentationCopyId = driveResponse.result.id;
25 |       if (callback) callback(presentationCopyId);
26 |       console.log('create copy_presentation with id', presentationCopyId);
27 |     });
28 |   } catch (err) {
29 |     document.getElementById('content').innerText = err.message;
30 |     return;
31 |   }
32 | }
33 | // [END slides_copy_presentation]
34 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_create_bulleted_text.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | // [START slides_create_bulleted_text]
16 | function createBulletedText(presentationId, shapeId, callback) {
17 |   // Add arrow-diamond-disc bullets to all text in the shape.
18 |   const requests = [{
19 |     createParagraphBullets: {
20 |       objectId: shapeId,
21 |       textRange: {
22 |         type: 'ALL',
23 |       },
24 |       bulletPreset: 'BULLET_ARROW_DIAMOND_DISC',
25 |     },
26 |   }];
27 |   // Execute the requests.
28 |   try {
29 |     gapi.client.slides.presentations.batchUpdate({
30 |       presentationId: presentationId,
31 |       requests: requests,
32 |     }).then((batchUpdateResponse) => {
33 |       console.log(`Added bullets to text in shape with ID: ${shapeId}`);
34 |       if (callback) callback(batchUpdateResponse.result);
35 |     });
36 |   } catch (err) {
37 |     document.getElementById('content').innerText = err.message;
38 |     return;
39 |   }
40 | }
41 | // [END slides_create_bulleted_text]
42 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_create_image.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START slides_create_image]
15 | function createImage(presentationId, pageId, IMAGE_URL, callback) {
16 |   const imageUrl = IMAGE_URL;
17 |   // Create a new image, using the supplied object ID, with content downloaded from imageUrl.
18 |   const requests = [];
19 |   const imageId = 'MyImage_02';
20 |   const emu4M = {
21 |     magnitude: 4000000,
22 |     unit: 'EMU',
23 |   };
24 |   requests.push({
25 |     createImage: {
26 |       objectId: imageId,
27 |       url: imageUrl,
28 |       elementProperties: {
29 |         pageObjectId: pageId,
30 |         size: {
31 |           height: emu4M,
32 |           width: emu4M,
33 |         },
34 |         transform: {
35 |           scaleX: 1,
36 |           scaleY: 1,
37 |           translateX: 100000,
38 |           translateY: 100000,
39 |           unit: 'EMU',
40 |         },
41 |       },
42 |     },
43 |   });
44 |   // Execute the request.
45 |   try {
46 |     gapi.client.slides.presentations.batchUpdate({
47 |       presentationId: presentationId,
48 |       requests: requests,
49 |     }).then((response) => {
50 |       const createImageResponse = response.result.replies;
51 |       console.log(`Created image with ID: ${createImageResponse[0].createImage.objectId}`);
52 |       if (callback) callback(createImageResponse);
53 |     });
54 |   } catch (err) {
55 |     document.getElementById('content').innerText = err.message;
56 |     return;
57 |   }
58 | }
59 | // [END slides_create_image]
60 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_create_presentation.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START slides_create_presentation]
15 | function createPresentation(title, callback) {
16 |   try {
17 |     gapi.client.slides.presentations.create({
18 |       title: title,
19 |     }).then((response) => {
20 |       console.log(`Created presentation with ID: ${response.result.presentationId}`);
21 |       if (callback) callback(response);
22 |     });
23 |   } catch (err) {
24 |     document.getElementById('content').innerText = err.message;
25 |     return;
26 |   }
27 | }
28 | // [END slides_create_presentation]
29 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_create_sheets_chart.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START slides_create_sheets_chart]
15 | function createSheetsChart(presentationId, pageId, shapeId, sheetChartId, callback) {
16 |   // Embed a Sheets chart (indicated by the spreadsheetId and sheetChartId) onto
17 |   // a page in the presentation. Setting the linking mode as "LINKED" allows the
18 |   // chart to be refreshed if the Sheets version is updated.
19 |   const emu4M = {
20 |     magnitude: 4000000,
21 |     unit: 'EMU',
22 |   };
23 |   const presentationChartId = 'MyEmbeddedChart';
24 |   const requests = [{
25 |     createSheetsChart: {
26 |       objectId: presentationChartId,
27 |       spreadsheetId: shapeId,
28 |       chartId: sheetChartId,
29 |       linkingMode: 'LINKED',
30 |       elementProperties: {
31 |         pageObjectId: pageId,
32 |         size: {
33 |           height: emu4M,
34 |           width: emu4M,
35 |         },
36 |         transform: {
37 |           scaleX: 1,
38 |           scaleY: 1,
39 |           translateX: 100000,
40 |           translateY: 100000,
41 |           unit: 'EMU',
42 |         },
43 |       },
44 |     },
45 |   }];
46 |   // Execute the request.
47 |   try {
48 |     gapi.client.slides.presentations.batchUpdate({
49 |       presentationId: presentationId,
50 |       requests: requests,
51 |     }).then((batchUpdateResponse) => {
52 |       console.log(`Added a linked Sheets chart with ID: ${presentationChartId}`);
53 |       if (callback) callback(batchUpdateResponse.result);
54 |     });
55 |   } catch (err) {
56 |     document.getElementById('content').innerText = err.message;
57 |     return;
58 |   }
59 | }
60 | // [END slides_create_sheets_chart]
61 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_create_slide.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START slides_create_slide]
15 | function createSlide(presentationId, pageId, callback) {
16 |   const requests = [
17 |     {
18 |       createSlide: {
19 |         objectId: pageId,
20 |         insertionIndex: '1',
21 |         slideLayoutReference: {
22 |           predefinedLayout: 'TITLE_AND_TWO_COLUMNS',
23 |         },
24 |       },
25 |     },
26 |   ];
27 |   // If you wish to populate the slide with elements, add element create requests here,
28 |   // using the pageId.
29 |   // Execute the request.
30 |   try {
31 |     gapi.client.slides.presentations
32 |         .batchUpdate({
33 |           presentationId: presentationId,
34 |           requests: requests,
35 |         })
36 |         .then((createSlideResponse) => {
37 |           const objectId =
38 |           createSlideResponse.result.replies[0].createSlide.objectId;
39 |           console.log(`Created slide with ID: ${objectId}`);
40 |           if (callback) callback(createSlideResponse);
41 |         });
42 |   } catch (err) {
43 |     document.getElementById('content').innerText = err.message;
44 |     return;
45 |   }
46 | }
47 | // [END slides_create_slide]
48 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_create_textbox_with_text.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START slides_create_textbox_with_text]
15 | function createTextboxWithText(presentationId, pageId, callback) {
16 |   // Create a new square textbox, using the supplied element ID.
17 |   const elementId = 'MyTextBox_01';
18 |   const pt350 = {
19 |     magnitude: 350,
20 |     unit: 'PT',
21 |   };
22 |   const requests = [{
23 |     createShape: {
24 |       objectId: elementId,
25 |       shapeType: 'TEXT_BOX',
26 |       elementProperties: {
27 |         pageObjectId: pageId,
28 |         size: {
29 |           height: pt350,
30 |           width: pt350,
31 |         },
32 |         transform: {
33 |           scaleX: 1,
34 |           scaleY: 1,
35 |           translateX: 350,
36 |           translateY: 100,
37 |           unit: 'PT',
38 |         },
39 |       },
40 |     },
41 |   },
42 | 
43 |   // Insert text into the box, using the supplied element ID.
44 |   {
45 |     insertText: {
46 |       objectId: elementId,
47 |       insertionIndex: 0,
48 |       text: 'New Box Text Inserted!',
49 |     },
50 |   }];
51 |   // Execute the request.
52 |   try {
53 |     gapi.client.slides.presentations.batchUpdate({
54 |       presentationId: presentationId,
55 |       requests: requests,
56 |     }).then((createTextboxWithTextResponse) => {
57 |       const createShapeResponse = createTextboxWithTextResponse.result.replies[0].createShape;
58 |       console.log(`Created textbox with ID: ${createShapeResponse.objectId}`);
59 |       if (callback) callback(createTextboxWithTextResponse.result);
60 |     });
61 |   } catch (err) {
62 |     document.getElementById('content').innerText = err.message;
63 |     return;
64 |   }
65 | }
66 | // [END slides_create_textbox_with_text]
67 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_image_merging.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START slides_image_merging]
15 | function imageMerging(
16 |     templatePresentationId,
17 |     imageUrl,
18 |     customerName,
19 |     callback,
20 | ) {
21 |   const logoUrl = imageUrl;
22 |   const customerGraphicUrl = imageUrl;
23 | 
24 |   // Duplicate the template presentation using the Drive API.
25 |   const copyTitle = customerName + ' presentation';
26 |   try {
27 |     gapi.client.drive.files
28 |         .copy({
29 |           fileId: templatePresentationId,
30 |           resource: {
31 |             name: copyTitle,
32 |           },
33 |         })
34 |         .then((driveResponse) => {
35 |           const presentationCopyId = driveResponse.result.id;
36 | 
37 |           // Create the image merge (replaceAllShapesWithImage) requests.
38 |           const requests = [
39 |             {
40 |               replaceAllShapesWithImage: {
41 |                 imageUrl: logoUrl,
42 |                 replaceMethod: 'CENTER_INSIDE',
43 |                 containsText: {
44 |                   text: '{{company-logo}}',
45 |                   matchCase: true,
46 |                 },
47 |               },
48 |             },
49 |             {
50 |               replaceAllShapesWithImage: {
51 |                 imageUrl: customerGraphicUrl,
52 |                 replaceMethod: 'CENTER_INSIDE',
53 |                 containsText: {
54 |                   text: '{{customer-graphic}}',
55 |                   matchCase: true,
56 |                 },
57 |               },
58 |             },
59 |           ];
60 |           // Execute the requests for this presentation.
61 |           gapi.client.slides.presentations
62 |               .batchUpdate({
63 |                 presentationId: presentationCopyId,
64 |                 requests: requests,
65 |               })
66 |               .then((batchUpdateResponse) => {
67 |                 let numReplacements = 0;
68 |                 for (
69 |                   let i = 0;
70 |                   i < batchUpdateResponse.result.replies.length;
71 |                   ++i
72 |                 ) {
73 |                   numReplacements +=
74 |                 batchUpdateResponse.result.replies[i].replaceAllShapesWithImage
75 |                     .occurrencesChanged;
76 |                 }
77 |                 console.log(
78 |                     `Created merged presentation with ID: ${presentationCopyId}`,
79 |                 );
80 |                 console.log(`Replaced ${numReplacements} shapes with images.`);
81 |                 if (callback) callback(batchUpdateResponse.result);
82 |               });
83 |         });
84 |   } catch (err) {
85 |     document.getElementById('content').innerText = err.message;
86 |     return;
87 |   }
88 | }
89 | // [END slides_image_merging]
90 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_refresh_sheets_chart.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | // [START slides_refresh_sheets_chart]
16 | function refreshSheetsChart(presentationId, presentationChartId, callback) {
17 |   const requests = [{
18 |     refreshSheetsChart: {
19 |       objectId: presentationChartId,
20 |     },
21 |   }];
22 |   // Execute the request.
23 |   try {
24 |     gapi.client.slides.presentations.batchUpdate({
25 |       presentationId: presentationId,
26 |       requests: requests,
27 |     }).then((batchUpdateResponse) => {
28 |       console.log(`Refreshed a linked Sheets chart with ID: ${presentationChartId}`);
29 |       if (callback) callback(batchUpdateResponse.result);
30 |     });
31 |   } catch (err) {
32 |     document.getElementById('content').innerText = err.message;
33 |     return;
34 |   }
35 | }
36 | // [END slides_refresh_sheets_chart]
37 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_simple_text_replace.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START slides_simple_text_replace]
15 | function simpleTextReplace(presentationId, shapeId, replacementText, callback) {
16 |   // Remove existing text in the shape, then insert new text.
17 |   const requests = [{
18 |     deleteText: {
19 |       objectId: shapeId,
20 |       textRange: {
21 |         type: 'ALL',
22 |       },
23 |     },
24 |   }, {
25 |     insertText: {
26 |       objectId: shapeId,
27 |       insertionIndex: 0,
28 |       text: replacementText,
29 |     },
30 |   }];
31 |   // Execute the requests.
32 |   try {
33 |     gapi.client.slides.presentations.batchUpdate({
34 |       presentationId: presentationId,
35 |       requests: requests,
36 |     }).then((batchUpdateResponse) => {
37 |       console.log(`Replaced text in shape with ID: ${shapeId}`);
38 |       if (callback) callback(batchUpdateResponse.result);
39 |     });
40 |   } catch (err) {
41 |     document.getElementById('content').innerText = err.message;
42 |     return;
43 |   }
44 | }
45 | // [END slides_simple_text_replace]
46 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_text_merging.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | // [START slides_text_merging]
15 | function textMerging(templatePresentationId, dataSpreadsheetId, callback) {
16 |   // Use the Sheets API to load data, one record per row.
17 |   const responses = [];
18 |   const dataRangeNotation = 'Customers!A2:M6';
19 |   try {
20 |     gapi.client.sheets.spreadsheets.values.get({
21 |       spreadsheetId: dataSpreadsheetId,
22 |       range: dataRangeNotation,
23 |     }).then((sheetsResponse) => {
24 |       const values = sheetsResponse.result.values;
25 |       // For each record, create a new merged presentation.
26 |       for (let i = 0; i < values.length; ++i) {
27 |         const row = values[i];
28 |         const customerName = row[2]; // name in column 3
29 |         const caseDescription = row[5]; // case description in column 6
30 |         const totalPortfolio = row[11]; // total portfolio in column 12
31 | 
32 |         // Duplicate the template presentation using the Drive API.
33 |         const copyTitle = customerName + ' presentation';
34 |         const request = {
35 |           name: copyTitle,
36 |         };
37 |         gapi.client.drive.files.copy({
38 |           fileId: templatePresentationId,
39 |           requests: request,
40 |         }).then((driveResponse) => {
41 |           const presentationCopyId = driveResponse.result.id;
42 | 
43 |           // Create the text merge (replaceAllText) requests for this presentation.
44 |           const requests = [{
45 |             replaceAllText: {
46 |               containsText: {
47 |                 text: '{{customer-name}}',
48 |                 matchCase: true,
49 |               },
50 |               replaceText: customerName,
51 |             },
52 |           }, {
53 |             replaceAllText: {
54 |               containsText: {
55 |                 text: '{{case-description}}',
56 |                 matchCase: true,
57 |               },
58 |               replaceText: caseDescription,
59 |             },
60 |           }, {
61 |             replaceAllText: {
62 |               containsText: {
63 |                 text: '{{total-portfolio}}',
64 |                 matchCase: true,
65 |               },
66 |               replaceText: totalPortfolio,
67 |             },
68 |           }];
69 | 
70 |           // Execute the requests for this presentation.
71 |           gapi.client.slides.presentations.batchUpdate({
72 |             presentationId: presentationCopyId,
73 |             requests: requests,
74 |           }).then((batchUpdateResponse) => {
75 |             const result = batchUpdateResponse.result;
76 |             responses.push(result.replies);
77 |             // Count the total number of replacements made.
78 |             let numReplacements = 0;
79 |             for (let i = 0; i < result.replies.length; ++i) {
80 |               numReplacements += result.replies[i].replaceAllText.occurrencesChanged;
81 |             }
82 |             console.log(`Created presentation for ${customerName} with ID: ${presentationCopyId}`);
83 |             console.log(`Replaced ${numReplacements} text instances`);
84 |             if (responses.length === values.length) { // callback for the last value
85 |               if (callback) callback(responses);
86 |             }
87 |           });
88 |         });
89 |       }
90 |     });
91 |   } catch (err) {
92 |     document.getElementById('content').innerText = err.message;
93 |     return;
94 |   }
95 | }
96 | // [END slides_text_merging]
97 | 


--------------------------------------------------------------------------------
/slides/snippets/slides_text_style_update.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | // [START slides_text_style_update]
16 | function textStyleUpdate(presentationId, shapeId, callback) {
17 |   // Update the text style so that the first 5 characters are bolded
18 |   // and italicized, the next 5 are displayed in blue 14 pt Times
19 |   // New Roman font, and the next 5 are hyperlinked.
20 |   const requests = [{
21 |     updateTextStyle: {
22 |       objectId: shapeId,
23 |       textRange: {
24 |         type: 'FIXED_RANGE',
25 |         startIndex: 0,
26 |         endIndex: 5,
27 |       },
28 |       style: {
29 |         bold: true,
30 |         italic: true,
31 |       },
32 |       fields: 'bold,italic',
33 |     },
34 |   }, {
35 |     updateTextStyle: {
36 |       objectId: shapeId,
37 |       textRange: {
38 |         type: 'FIXED_RANGE',
39 |         startIndex: 5,
40 |         endIndex: 10,
41 |       },
42 |       style: {
43 |         fontFamily: 'Times New Roman',
44 |         fontSize: {
45 |           magnitude: 14,
46 |           unit: 'PT',
47 |         },
48 |         foregroundColor: {
49 |           opaqueColor: {
50 |             rgbColor: {
51 |               blue: 1.0,
52 |               green: 0.0,
53 |               red: 0.0,
54 |             },
55 |           },
56 |         },
57 |       },
58 |       fields: 'foregroundColor,fontFamily,fontSize',
59 |     },
60 |   }, {
61 |     updateTextStyle: {
62 |       objectId: shapeId,
63 |       textRange: {
64 |         type: 'FIXED_RANGE',
65 |         startIndex: 10,
66 |         endIndex: 15,
67 |       },
68 |       style: {
69 |         link: {
70 |           url: 'www.example.com',
71 |         },
72 |       },
73 |       fields: 'link',
74 |     },
75 |   }];
76 |   // Execute the requests.
77 |   try {
78 |     gapi.client.slides.presentations.batchUpdate({
79 |       presentationId: presentationId,
80 |       requests: requests,
81 |     }).then((batchUpdateResponse) => {
82 |       console.log(`Updated the text style for shape with ID: ${shapeId}`);
83 |       if (callback) callback(batchUpdateResponse.result);
84 |     });
85 |   } catch (err) {
86 |     document.getElementById('content').innerText = err.message;
87 |     return;
88 |   }
89 | }
90 | // [END slides_text_style_update]
91 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_copy_presentation.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | function testCopyPresentation(done) {
15 |   createTestPresentation(function(presentationId) {
16 |     copyPresentation(presentationId, 'My Duplicate Presentation', function(copyId) {
17 |       assert.isNotNull(copyId);
18 |       done();
19 |       // deleteFileOnCleanup(copyId);
20 |     });
21 |   });
22 | }
23 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_create_bulleted_text.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testCreateBulletedText(done) {
16 |   createTestPresentation(function(presentationId) {
17 |     addSlides(presentationId, 1, 'BLANK', function(pageIds) {
18 |       const pageId = pageIds[0];
19 |       createTestTextbox(presentationId, pageId, function(boxId) {
20 |         createBulletedText(presentationId, boxId, function(response) {
21 |           assert.equal(1, response.replies.length);
22 |           done();
23 |         });
24 |       });
25 |     });
26 |   });
27 | }
28 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_create_image.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testCreateImage(done) {
16 |   createTestPresentation(function(presentationId) {
17 |     addSlides(presentationId, 1, 'BLANK', function(ids) {
18 |       const pageId = ids[0];
19 |       const IMAGE_URL =
20 |         'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
21 |       createImage(presentationId, pageId, IMAGE_URL, function(response) {
22 |         assert.equal(1, response.length);
23 |         const imageId = response[0].createImage.objectId;
24 |         assert.isNotNull(imageId);
25 |         done();
26 |       });
27 |     });
28 |   });
29 | }
30 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_create_presentation.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testCreatePresentation(done) {
16 |   createPresentation('Title', function(presentation) {
17 |     assert.isNotNull(presentation);
18 |     done();
19 |     // deleteFileOnCleanup(presentation.presentationId)
20 |   });
21 | }
22 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_create_sheets_chart.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testCreateSheetsChart(done) {
16 |   createTestPresentation(function(presentationId) {
17 |     addSlides(presentationId, 1, 'BLANK', function(pageIds) {
18 |       const pageId = pageIds[0];
19 |       createSheetsChart(presentationId, pageId, DATA_SPREADSHEET_ID, CHART_ID, function(response) {
20 |         assert.equal(1, response.replies.length);
21 |         const chartId = response.replies[0].createSheetsChart.objectId;
22 |         assert.isNotNull(chartId);
23 |         done();
24 |       });
25 |     });
26 |   });
27 | }
28 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_create_slide.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testCreateSlide(done) {
16 |   createTestPresentation(function(presentationId) {
17 |     addSlides(presentationId, 3, 'TITLE_AND_TWO_COLUMNS', function(ids) {
18 |       const pageId = 'my_page_id';
19 |       createSlide(presentationId, pageId, function(response) {
20 |         assert.equal(pageId, response.result.replies[0].createSlide.objectId);
21 |         done();
22 |       });
23 |     });
24 |   });
25 | }
26 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_create_textbox_with_text.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testCreateTextboxWithText(done) {
16 |   createTestPresentation(function(presentationId) {
17 |     addSlides(presentationId, 1, 'BLANK', function(ids) {
18 |       const pageId = ids[0];
19 |       createTextboxWithText(presentationId, pageId, function(response) {
20 |         assert.equal(2, response.replies.length);
21 |         const boxId = response.replies[0].createShape.objectId;
22 |         assert.isNotNull(boxId);
23 |         done();
24 |       });
25 |     });
26 |   });
27 | }
28 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_image_merging.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testImageMerging(done) {
16 |   const TEMPLATE_PRESENTATION_ID =
17 |     '1TWayqVbNxZ0ZjmfBg5nVhBDWSnQi7lgeglDDfIe41Sw';
18 |   const IMAGE_URL =
19 |     'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
20 |   const CUSTOMER_NAME = 'Fake Customer';
21 |   imageMerging(
22 |       TEMPLATE_PRESENTATION_ID,
23 |       IMAGE_URL,
24 |       CUSTOMER_NAME,
25 |       function(response) {
26 |         const presentationId = response.presentationId;
27 |         assert.isNotNull(presentationId);
28 | 
29 |         assert.equal(2, response.replies.length);
30 |         let numReplacements = 0;
31 |         for (let i = 0; i < response.replies.length; ++i) {
32 |           numReplacements +=
33 |           response.replies[i].replaceAllShapesWithImage.occurrencesChanged;
34 |         }
35 |         done();
36 |       },
37 |   );
38 | }
39 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_refresh_sheets_chart.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testRefreshSheetsChart(done) {
16 |   createTestPresentation(function(presentationId) {
17 |     addSlides(presentationId, 1, 'BLANK', function(pageIds) {
18 |       const pageId = pageIds[0];
19 |       createTestSheetsChart(
20 |           presentationId,
21 |           pageId,
22 |           DATA_SPREADSHEET_ID,
23 |           CHART_ID,
24 |           function(sheetChartId) {
25 |             refreshSheetsChart(presentationId, sheetChartId, function(response) {
26 |               assert.equal(1, response.replies.length);
27 |               done();
28 |             });
29 |           },
30 |       );
31 |     });
32 |   });
33 | }
34 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_simple_text_replace.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testSimpleTextReplace(done) {
16 |   createTestPresentation(function(presentationId) {
17 |     addSlides(presentationId, 1, 'BLANK', function(pageIds) {
18 |       const pageId = pageIds[0];
19 |       createTestTextbox(presentationId, pageId, function(boxId) {
20 |         simpleTextReplace(presentationId, boxId, 'MY NEW TEXT', function(response) {
21 |           assert.equal(2, response.replies.length);
22 |           done();
23 |         });
24 |       });
25 |     });
26 |   });
27 | }
28 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_text_merging.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testTextMerging(done) {
16 |   const TEMPLATE_PRESENTATION_ID = '1dsYAXBA6ms6eOK-fe3ai95Wa6vUR8mMrPT4Jb0B9Wfk';
17 |   const DATA_SPREADSHEET_ID = '1eaI4xAqR2SpC3Ysf7ExOE0JBtXUkZ5YMIYUZ3sPx9_w';
18 |   textMerging(TEMPLATE_PRESENTATION_ID, DATA_SPREADSHEET_ID, function(responses) {
19 |     assert.equal(5, responses.length);
20 |     responses.forEach(function(response) {
21 |       let numReplacements = 0;
22 |       for (let i = 0; i < response.length; ++i) {
23 |         numReplacements += response[i].replaceAllText.occurrencesChanged;
24 |       }
25 |     });
26 |     done();
27 |   });
28 | }
29 | 


--------------------------------------------------------------------------------
/slides/snippets/test_slides_text_style_update.js:
--------------------------------------------------------------------------------
 1 | // Copyright 2022 Google LLC
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | 
15 | function testTextStyleUpdate(done) {
16 |   createTestPresentation(function(presentationId) {
17 |     addSlides(presentationId, 1, 'BLANK', function(pageIds) {
18 |       const pageId = pageIds[0];
19 |       createTestTextbox(presentationId, pageId, function(boxId) {
20 |         textStyleUpdate(presentationId, boxId, function(response) {
21 |           assert.equal(3, response.replies.length);
22 |           done();
23 |         });
24 |       });
25 |     });
26 |   });
27 | }
28 | 


--------------------------------------------------------------------------------
/tasks/quickstart/README.md:
--------------------------------------------------------------------------------
 1 | # Google Tasks API Browser Quickstart
 2 | 
 3 | Complete the steps described in the [quickstart instructions](
 4 | https://developers.google.com/google-apps/tasks/quickstart/js), and in about five
 5 | minutes you'll have a simple browser application that makes requests to the
 6 | Google Tasks API.
 7 | 
 8 | ## Run
 9 | 
10 | After following the quickstart instructions, run the sample:
11 | 
12 | ```shell
13 | python3 -m http.server 8000
14 | ```
15 | 
16 | And opening the web page:
17 | 
18 | ```shell
19 | open http://localhost:8000
20 | ```
21 | 
22 | 
23 | 


--------------------------------------------------------------------------------
/tasks/quickstart/index.html:
--------------------------------------------------------------------------------
  1 | 
 16 | 
 17 | 
 18 | 
 19 |   
 20 |     Tasks API Quickstart
 21 |     
 22 |   
 23 |   
 24 |     

Tasks API Quickstart

25 | 26 | 27 | 28 | 29 | 30 |

 31 | 
 32 |     
160 |     
161 |     
162 |   
163 | 
164 | 
165 | 


--------------------------------------------------------------------------------