ה-Apps Script API מאפשר ליצור ולשנות פרויקטים ב-Apps Script מהאפליקציה. הדוגמאות בדף הזה מראות איך ניתן לבצע כמה פעולות נפוצות של ניהול פרויקטים ב-API.
הערה: ממשק ה-API של Apps Script חייב להפעיל לפני השימוש.
בדוגמאות האלה, ה-placeholders scriptId מציינים איפה מציינים את מזהה הפרויקט של הסקריפט. כדי לאתר את מזהה הסקריפט, פועלים לפי השלבים הבאים:
- בפרויקט Apps Script, בפינה הימנית העליונה, לוחצים על הגדרות הפרויקט .
- לצד "Script 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
התשובה מורכבת מאובייקט תוכן, כמו זה:
{ "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" }] }
התשובה מורכבת מאובייקט תוכן, כמו זה:
{ "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" }] }