Pengelolaan Proyek

Apps Script API memungkinkan Anda membuat dan mengubah project Apps Script dari aplikasi Anda. Contoh di halaman ini menggambarkan cara beberapa operasi pengelolaan project umum dapat dilakukan dengan API.

CATATAN: Apps Script API harus diaktifkan sebelum digunakan.

Dalam contoh ini, placeholder scriptId digunakan untuk menunjukkan tempat Anda memberikan project ID skrip. Ikuti langkah-langkah berikut untuk menemukan ID skrip:

  1. Pada project Apps Script, di kiri atas, klik Setelan Project .
  2. Di samping "ID Skrip", klik Salin.

Membuat project Apps Script baru

Permintaan projects.create berikut akan membuat skrip mandiri baru.

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

Mengambil metadata project

Permintaan projects.get berikut mendapatkan metadata project skrip.

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

Respons terdiri dari objek seperti yang satu ini:

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

Mengambil file project

Permintaan projects.getContent berikut mendapatkan konten project skrip, termasuk sumber kode dan metadata untuk setiap file skrip.

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

Respons terdiri dari objek Content seperti yang satu ini:

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

Memperbarui file project

Permintaan projects.updateContent berikut mengupdate konten project skrip yang ditentukan. Konten ini disimpan sebagai versi HEAD, dan digunakan saat skrip dieksekusi sebagai project API yang dapat dieksekusi.

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

Respons terdiri dari objek Content seperti yang satu ini:

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