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: https://www.googleapis.com/auth/drive.scripts

For updating a file you will "PUT" the updated JSON to: https://www.googleapis.com/upload/drive/v2/files/{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 = https://www.e-learn.cn/content/wangluowenzhang/"https://www.googleapis.com/upload/drive/v2/files/"+scriptId; var parameters = { method : 'PUT', headers : {'Authorization': 'Bearer '+ tokenWithProperScope, payload : JSON.stringify(scriptFiles), contentType:'application/vnd.google-apps.script+json', 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: https://developers.google.com/apps-script/import-export


Set the mimetype as application/vnd.google-apps.script


  • Docker container for google cloudML on compute engine - authenticating for mounting bucket
  • Youtube upload API and cordova / phonegap
  • Sencha Touch 2.1 native (android) app not getting json from remote (it works on PC)
  • Update SQL MS Access 2010
  • Transpose table then set and rename index
  • ConfigurationBuilder not working in azure function
  • Is it safe to drop the -webkit vendor prefix from the css3 border-radius yet?
  • Cannot page through all results using nextPageToken on YouTube search API v3
  • Unable to play media with vlc ocx
  • Are there any side effects from calling SQLAlchemy flush() within code?
  • perl, mysql - fasting way to upload a csv file into mysql?
  • android google indoor map
  • How to revert to previous XCode version?
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • azure media services - The request body is too large and exceeds the maximum permissible limit
  • Play WS (2.2.1): post/put large request
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • Read a local file using javascript
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Java: can you cast Class into a specific interface?
  • Paperclip, set path outside of rails root folder
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Installing Hadoop, Java Exception about illegal characters at index 7?
  • Different response to non-authenticated users and AJAX calls
  • Optimizing database types to compact database (SQLite)
  • RectangularRangeIndicator format like triangular using dojo
  • AES padding and writing the ciphertext to a disk file
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • Updating server-side rendering client-side
  • Cross-Platform Protobuf Serialization
  • How to extract text from Word files using C#?
  • Do I've to free mysql result after storing it?
  • How to get next/previous record number?
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Confusion with PayPal's monthly billing cycle
  • Revoking OAuth Access Token Results in 404 Not Found
  • coudnt use logback because of log4j
  • Turn off referential integrity in Derby? is it possible?
  • Is it possible to post an object from jquery to bottle.py?
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass