プロジェクト管理

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",
  "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"
  }]
}