專案管理
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
您可以使用 Apps Script API,從應用程式建立及修改 Apps Script 專案。本頁的範例說明如何透過 API 執行一些常見的專案管理作業。
注意:您必須先啟用 Apps Script API,才能使用這項服務。
在這些範例中,預留位置 scriptId 用於指出您提供指令碼專案 ID 的位置。請按照下列步驟找出指令碼 ID:
- 在 Apps Script 專案中,按一下左上方的「專案設定」圖示 settings。
- 按一下「指令碼 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"
}]
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eThe Apps Script API enables programmatic creation and management of Apps Script projects, including tasks like creating new projects, retrieving project metadata, and updating project files.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the Apps Script API, ensure it's enabled in your Google Account settings.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve a script project's unique ID from the Project Settings in the Apps Script editor.\u003c/p\u003e\n"],["\u003cp\u003eThe API provides methods for accessing and modifying the content of script projects, such as source code and metadata for individual files within the project.\u003c/p\u003e\n"],["\u003cp\u003eUpdating project files through the API sets the updated content as the HEAD version, which is used for API execution.\u003c/p\u003e\n"]]],[],null,["# Project Management\n\nThe Apps Script API allows you to create and modify Apps Script projects\nfrom your app. The examples on this page illustrate how some common project\nmanagement operations can be achieved with the API.\n\nNOTE: The Apps Script API must be [enabled](https://script.google.com/home/usersettings)\nbefore usage.\n\nIn these examples, the placeholders \u003cvar translate=\"no\"\u003escriptId\u003c/var\u003e\nis used to indicate where you would provide the script project ID. Follow the\nsteps below to find the script ID:\n\n1. In the Apps Script project, at the top left, click **Project Settings** settings.\n2. Next to \"Script ID,\" click **Copy**.\n\nCreate a new Apps Script project\n--------------------------------\n\nThe following [projects.create](https://developers.google.com/apps-script/api/reference/rest/v1/projects/create)\nrequest creates a new [standalone script](https://developers.google.com/apps-script/guides/standalone). \n\n```\nPOST https://scriptmanagement.googleapis.com/v1/projects/\n``` \n\n```text\n{\n \"title\": \"My Script\"\n}\n```\n\nRetrieve project metadata\n-------------------------\n\nThe following [projects.get](https://developers.google.com/apps-script/api/reference/rest/v1/projects/get)\nrequest gets the script [project's metadata](https://developers.google.com/apps-script/api/reference/rest/v1/projects#Project). \n\n```\nGET https://scriptmanagement.googleapis.com/v1/projects/scriptId\n```\n\nThe response consists of an [object](https://developers.google.com/apps-script/api/reference/rest/v1/projects#Project)\nsuch as this one: \n\n```text\n{\n \"scriptId\": \"scriptId\",\n \"title\": \"My Title\",\n \"parentId\": \"parentId\",\n \"createTime\": \"2017-10-02T15:01:23.045123456Z\",\n \"updateTime\": \"2017-10-02T15:01:23.045123456Z\",\n \"creator\": { \"name\": \"Grant\" },\n \"lastModifyUser\": { \"name\": \"Grant\" },\n}\n```\n\nRetrieve project files\n----------------------\n\nThe following [projects.getContent](https://developers.google.com/apps-script/api/reference/rest/v1/projects/getContent)\nrequest gets the content of the script project, including the code source and\nmetadata for each script file. \n\n```\nGET https://scriptmanagement.googleapis.com/v1/projects/scriptId/content\n```\n\nThe response consists of a [Content](https://developers.google.com/apps-script/api/reference/rest/v1/projects/getContent#response-body)\nobject such as this one: \n\n```carbon\n{\n \"scriptId\": \"scriptId\",\n \"files\": [{\n \"name\": \"My Script\",\n \"type\": \"SERVER_JS\",\n \"source\": \"function hello(){\\nconsole.log('Hello world');}\",\n \"lastModifyUser\": {\n \"name\": \"Grant\",\n \"email\": \"grant@example.com\",\n },\n \"createTime\": \"2017-10-02T15:01:23.045123456Z\",\n \"updateTime\": \"2017-10-02T15:01:23.045123456Z\",\n \"functionSet\": {\n \"values\": [\n \"name\": \"helloWorld\"\n ]\n }\n }, {\n \"name\": \"appsscript\",\n \"type\": \"JSON\",\n \"source\": \"{\\\"timeZone\\\":\\\"America/New_York\\\",\\\"exceptionLogging\\\":\\\"CLOUD\\\"}\",\n \"lastModifyUser\": {\n \"name\": \"Grant\",\n \"email\": \"grant@example.com\",\n },\n \"createTime\": \"2017-10-02T15:01:23.045123456Z\",\n \"updateTime\": \"2017-10-02T15:01:23.045123456Z\"\n }]\n}\n```\n\nUpdate project files\n--------------------\n\nThe following [projects.updateContent](https://developers.google.com/apps-script/api/reference/rest/v1/projects/updateContent)\nrequest updates the content of the specified script project. This content is\nstored as the HEAD version, and is used when the script is executed as an API\nexecutable project. \n\n```\nPUT https://scriptmanagement.googleapis.com/v1/projects/scriptID/content\n``` \n\n```carbon\n{\n \"files\": [{\n \"name\": \"index\",\n \"type\": \"HTML\",\n \"source\": \"\u003chtml\u003e \u003cheader\u003e\u003ctitle\u003eHTML Page\u003c/title\u003e\u003c/header\u003e \u003cbody\u003e My HTML \u003c/body\u003e \u003c/html\u003e\"\n }, {\n \"name\": \"My Script\",\n \"type\": \"SERVER_JS\",\n \"source\": \"function hello(){\\nconsole.log('Hello world');}\",\n }, {\n \"name\": \"appsscript\",\n \"type\": \"JSON\",\n \"source\": \"{\\\"timeZone\\\":\\\"America/New_York\\\",\\\"exceptionLogging\\\":\\\"CLOUD\\\"}\",\n \"lastModifyUser\": {\n \"name\": \"Grant\",\n \"email\": \"grant@example.com\",\n },\n \"createTime\": \"2017-10-02T15:01:23.045123456Z\",\n \"updateTime\": \"2017-10-02T15:01:23.045123456Z\"\n }]\n}\n```\n\nThe response consists of a [Content](https://developers.google.com/apps-script/api/reference/rest/v1/projects/getContent#response-body)\nobject such as this one: \n\n```carbon\n{\n \"scriptId\": \"scriptId\",\n \"files\": [{\n \"name\": \"index\",\n \"type\": \"HTML\",\n \"source\": \"\u003chtml\u003e \u003cheader\u003e\u003ctitle\u003eHTML Page\u003c/title\u003e\u003c/header\u003e \u003cbody\u003e My HTML \u003c/body\u003e \u003c/html\u003e\",\n \"lastModifyUser\": {\n \"name\": \"Grant\",\n \"email\": \"grant@example.com\",\n },\n \"createTime\": \"2017-10-02T15:01:23.045123456Z\",\n \"updateTime\": \"2017-10-02T15:01:23.045123456Z\"\n }, {\n \"name\": \"My Script\",\n \"type\": \"SERVER_JS\",\n \"source\": \"function hello(){\\nconsole.log('Hello world');}\",\n \"lastModifyUser\": {\n \"name\": \"Grant\",\n \"email\": \"grant@example.com\",\n },\n \"createTime\": \"2017-10-02T15:01:23.045123456Z\",\n \"updateTime\": \"2017-10-02T15:01:23.045123456Z\",\n \"functionSet\": {\n \"values\": [\n \"name\": \"helloWorld\"\n ]\n }\n }, {\n \"name\": \"appsscript\",\n \"type\": \"JSON\",\n \"source\": \"{\\\"timeZone\\\":\\\"America/New_York\\\",\\\"exceptionLogging\\\":\\\"CLOUD\\\"}\",\n \"lastModifyUser\": {\n \"name\": \"Grant\",\n \"email\": \"grant@example.com\",\n },\n \"createTime\": \"2017-10-02T15:01:23.045123456Z\",\n \"updateTime\": \"2017-10-02T15:01:23.045123456Z\"\n }]\n}\n```"]]