Import Google app script project from JSON file

In Google Drive, it's possible to download an app script project as a .json file.

When such file is imported back to a Google Drive it's not properly associated with Google Script editor app.

Is there any way to do it properly?


Importing and exporting of Apps Script files requires the use of the import/export API.

To modify an existing script you will need to have a Oauth2 token with the scope of:

For updating a file you will "PUT" the updated JSON to:{FileId}

The Apps Script file looks like

{ files: [ { name:{fileName}, type:{server_js or html }, source:{source code for this file}, id:{Autogenerated. Omit this key for a new file, or leave value unmodified for an updated file}, }, {...} ] }

To add a file: Add an object to the files array with the keys name, type, source

To modify a file: Modify the values of name, type, or source of the file object but do not modify the id.

When you PUT the file back make sure you put the entire files array with your modifications, not just the new file object.

To make the modification in GAS itself would look like:

var scriptFiles = JSON.parse(downloadedJSONFile); scriptFiles.files.push({"name":fileName,"type":fileType,"source":source}); var url =""+scriptId; var parameters = { method : 'PUT', headers : {'Authorization': 'Bearer '+ tokenWithProperScope, payload : JSON.stringify(scriptFiles), contentType:'application/', muteHttpExceptions:true}; var response = UrlFetchApp.fetch(url,parameters);

You will get a response code of 200 for a successful change. The response text will include the entire new JSON files with the assigned id to the file you added.

Fine more at:


Set the mimetype as application/

人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:Import Google app script project from JSON file