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