プロジェクト管理

Apps Script API を使用すると、アプリで Apps Script プロジェクトを作成および変更できます。このページの例は、API を使用した一般的なプロジェクト管理操作の方法を示しています。

注: Apps Script API は、使用前に有効にする必要があります。

以下の例では、プレースホルダ scriptId を使用して、スクリプトのプロジェクト ID を提供する場所を示しています。スクリプト ID を確認する手順は次のとおりです。

  1. Apps Script プロジェクトで、左上のプロジェクト設定アイコン をクリックします。
  2. [スクリプト ID] の横にある [コピー] をクリックします。

新しい Apps Script プロジェクトを作成する

次の projects.create リクエストは、新しいスタンドアロン スクリプトを作成します。

POST https://scriptmanagement.googleapis.com/v1/projects/
{
  "title": "My Script"
}

プロジェクトのメタデータを取得する

次の projects.get リクエストは、スクリプトのプロジェクトのメタデータを取得します。

GET https://scriptmanagement.googleapis.com/v1/projects/scriptId

レスポンスは、次のようなオブジェクトで構成されます。

{
  "scriptId": "scriptId",
  "title": "My Title",
  "parentId": "parentId",
  "projectOrigin": "APPS_SCRIPT_IDE",
  "cloudProject": "cloudProject",
  "encryptedCloudProjectToken": "token",
  "securityZone": "STANDARD",
  "createTime": "2017-10-02T15:01:23.045123456Z",
  "updateTime": "2017-10-02T15:01:23.045123456Z",
  "creator": { "name": "Grant" },
  "lastModifyUser": { "name": "Grant" },
}

プロジェクト ファイルを取得する

次の projects.getContent リクエストは、各スクリプト ファイルのコードソースとメタデータを含むスクリプト プロジェクトのコンテンツを取得します。

GET https://scriptmanagement.googleapis.com/v1/projects/scriptId/content

レスポンスは、次のような Content オブジェクトで構成されます。

{
  "scriptId": "scriptId",
  "files": [{
    "name": "My Script",
    "type": "SERVER_JS",
    "source": "function hello(){\nconsole.log('Hello world');}",
    "lastModifyUser": {
      "name": "Grant",
      "email": "grant@example.com",
    },
    "createTime": "2017-10-02T15:01:23.045123456Z",
    "updateTime": "2017-10-02T15:01:23.045123456Z",
    "functionSet": {
      "values": [
        "name": "helloWorld"
      ]
    }
  }, {
    "name": "appsscript",
    "type": "JSON",
    "source": "{\"timeZone\":\"America/New_York\",\"exceptionLogging\":\"CLOUD\"}",
    "lastModifyUser": {
      "name": "Grant",
      "email": "grant@example.com",
    },
    "createTime": "2017-10-02T15:01:23.045123456Z",
    "updateTime": "2017-10-02T15:01:23.045123456Z"
  }]
}

プロジェクト ファイルを更新する

次の projects.updateContent リクエストは、指定されたスクリプト プロジェクトのコンテンツを更新します。このコンテンツは HEAD バージョンとして保存され、API 実行可能プロジェクトとしてスクリプトが実行されると使用されます。

PUT https://scriptmanagement.googleapis.com/v1/projects/scriptID/content
{
  "files": [{
    "name": "index",
    "type": "HTML",
    "source": "<html> <header><title>HTML Page</title></header> <body> My HTML </body> </html>"
  }, {
    "name": "My Script",
    "type": "SERVER_JS",
    "source": "function hello(){\nconsole.log('Hello world');}",
  }, {
    "name": "appsscript",
    "type": "JSON",
    "source": "{\"timeZone\":\"America/New_York\",\"exceptionLogging\":\"CLOUD\"}",
    "lastModifyUser": {
      "name": "Grant",
      "email": "grant@example.com",
    },
    "createTime": "2017-10-02T15:01:23.045123456Z",
    "updateTime": "2017-10-02T15:01:23.045123456Z"
  }]
}

レスポンスは、次のような Content オブジェクトで構成されます。

{
  "scriptId": "scriptId",
  "files": [{
    "name": "index",
    "type": "HTML",
    "source": "<html> <header><title>HTML Page</title></header> <body> My HTML </body> </html>",
    "lastModifyUser": {
      "name": "Grant",
      "email": "grant@example.com",
    },
    "createTime": "2017-10-02T15:01:23.045123456Z",
    "updateTime": "2017-10-02T15:01:23.045123456Z"
  }, {
    "name": "My Script",
    "type": "SERVER_JS",
    "source": "function hello(){\nconsole.log('Hello world');}",
    "lastModifyUser": {
      "name": "Grant",
      "email": "grant@example.com",
    },
    "createTime": "2017-10-02T15:01:23.045123456Z",
    "updateTime": "2017-10-02T15:01:23.045123456Z",
    "functionSet": {
      "values": [
        "name": "helloWorld"
      ]
    }
  }, {
    "name": "appsscript",
    "type": "JSON",
    "source": "{\"timeZone\":\"America/New_York\",\"exceptionLogging\":\"CLOUD\"}",
    "lastModifyUser": {
      "name": "Grant",
      "email": "grant@example.com",
    },
    "createTime": "2017-10-02T15:01:23.045123456Z",
    "updateTime": "2017-10-02T15:01:23.045123456Z"
  }]
}