프로젝트 관리

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