Exporting all projects

#1

Hi, as described via Twitter earlier I’m looking for an efficient to download all my work locally. I understand it might not run but I’d appreciate having at least a way to do so because “things happen”.

I already exported few projects to Github or manually downloading the tar.gz file but since I have ~100 projects I’m looking for a solution, even if via a script relying on the API and maybe a token, everything I built here.

Thanks in advance, Fabien

#2

Hey @Utopiah, welcome to the Glitch forum!

This is a really good question, and one I haven’t seen asked here. It’s not terribly complicated, but enough so that it’s probably not great to explain in 280 character bites.

The central API call you’ll need is a GET in this format

https://api.glitch.com/project/download/?authorization={OWNER_TOKEN}&projectId={PROJECT_ID}

You can get your own “persistent” token by open up your browser’s developer tools from an Editor window and examining localStorage.cachedUser. The property you want from there is persistentToken. You should also make note of your user id (id).

To get your project list you can then call the users API with your user id and token:

https://api.glitch.com/users/{USER_ID}?authorization={TOKEN}

That response will include all your undeleted projects. If you’re doing this in a console you can then pipe it to jq -r '.projects[].id' to get a list of all of your project ids.

From there you can loop over the results and call the download endpoint for each project to get its download. It might be useful to rename the archives as they’re downloaded, so you could use jq -r '.projects[]| "\(.id) \(.domain)"' as the jq command to get a list of project ids and names, and the use the name for each as the output filename.

I hope this helps, and let me know if i need to clarify anything.

1 Like
#3

Here is a little Gist to facilitate the process https://gist.github.com/Utopiah/7306915027821217035e412ec8ce2f2d

1 Like