Create a Target Project to Execute with the Apps Script API

Before you can begin the Android or iOS quickstarts, you need a target Apps Script project. The mobile quickstart code executes a function in this project remotely, and receives a response back.

Follow these steps to create a simple script project and enable it for API access.

Step 1: Create the script

New editor

  1. Create a new script project.
  2. At the top, click Untitled Project to rename the script. Name the script "Apps Script API Quickstart Target" and click Rename.
  3. Replace the contents of the Code.gs file with the following:

    apps-script/execute/target.js
    /**
     * Return the set of folder names contained in the user's root folder as an
     * object (with folder IDs as keys).
     * @return {Object} A set of folder names keyed by folder ID.
     */
    function getFoldersUnderRoot() {
      var root = DriveApp.getRootFolder();
      var folders = root.getFolders();
      var folderSet = {};
      while (folders.hasNext()) {
        var folder = folders.next();
        folderSet[folder.getId()] = folder.getName();
      }
      return folderSet;
    }
  4. At the top, click Save .

Legacy editor

  1. Create a new script project.
  2. Click on the "Untitled Project" title to rename the script. Name the script "Apps Script API Quickstart Target" and click OK.
  3. Replace the contents of the Code.gs file with the following:

    apps-script/execute/target.js
    /**
     * Return the set of folder names contained in the user's root folder as an
     * object (with folder IDs as keys).
     * @return {Object} A set of folder names keyed by folder ID.
     */
    function getFoldersUnderRoot() {
      var root = DriveApp.getRootFolder();
      var folders = root.getFolders();
      var folderSet = {};
      while (folders.hasNext()) {
        var folder = folders.next();
        folderSet[folder.getId()] = folder.getName();
      }
      return folderSet;
    }
  4. Save the project by selecting File > Save.

Step 2: Switch to a user-managed Google Cloud Platform project

Your Apps Script project is automatically associated with a default Apps Script-managed Google Cloud Platform (GCP) project. To deploy the script for API execution, you need to switch its association to a standard, user-managed GCP project.

  1. In the Cloud Console, go to the Manage resources page.
  2. At the top, click Create Project.
  3. Enter a project name, choose the parent organization, and select a location folder.
  4. Click Create.
  5. In the dialog that appears after the project is created, click Select project.
  6. On the project dashboard page under Project info, copy the project number.

To switch your Apps Script's GCP project association, you need to configure the GCP project's OAuth consent screen.

  1. From the GCP project dashboard page, click Navigation menu > APIs & Services > OAuth consent screen.
  2. For the purposes of this quickstart, under User type, click External. If you're building an app for only your organization, you can select Internal.
  3. Click Create.
  4. Under App information in the App name field, enter "Apps Script API Quickstart Target."
  5. In the required email fields under User support email and Developer contact information, enter your email. For the purposes of this quickstart, you can leave the other optional fields blank. When you build an app for real-world use, fill out all of the consent screen fields accordingly.
  6. Click Save and Continue. For the purposes of this quickstart, you can keep clicking Save and Continue until you reach the Summary page. When you build an app for real-world use, fill out all of the pages accordingly.

Step 4: Deploy the script for execution

Now that you've set up your standard GCP project, switch your Apps Script project's GCP poject association to use the standard user-managed project and deploy the script.

New editor

  1. In the Apps script project, at the left, click Project settings .
  2. Under "Google Cloud Platform (GCP) Project," click Change project.
  3. In the "GCP project number" field, paste the standard GCP project number you copied in step 2.
  4. Click Set project.
  5. At the top right, click Deploy > New Deployment.
  6. In the dialog that opens, click Enable deployment types > API Executable.
  7. Under "Description" enter "Target-v1."
  8. Click Deploy.

Legacy editor

  1. In the code editor, select Publish > Deploy as API executable.
  2. In the dialog that opens, leave the Version as "New" and enter "Target-v1" into the text box. Click Deploy.

Step 5: Choose a quickstart

Each of these quickstarts use the Apps Script API to execute the script you just created: