プロジェクト管理

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