Skip to content

Instantly share code, notes, and snippets.

@mrmemes-eth
Created October 15, 2020 14:19
Show Gist options
  • Save mrmemes-eth/9274686f4acaf0cd46c1b866c3ad43b4 to your computer and use it in GitHub Desktop.
Save mrmemes-eth/9274686f4acaf0cd46c1b866c3ad43b4 to your computer and use it in GitHub Desktop.
Programatically export and/or delete Heroku dataclips
#!/usr/bin/env bash
# there were a handful of clips that I didn't want to delete versus hundreds that I did,
# so I just removed the UUIDs of the clips I wanted to keep from uuids.txt by hand
cat uuids.txt | while read uuid
do
curl \
-H "authorization: Bearer $(heroku auth:token)" \
-H "content-type: application/json" \
-d '{"query":"mutation DeleteDataclip($clipId: ID!) { deleteClip(clipId: $clipId) }","variables":{"clipId":"'$uuid'"}}' \
https://data-api.heroku.com/graphql
done
#!/usr/bin/env sh
# dump a JSON file with a UUID, title and the most recent SQL for every clip
curl \
-H "authorization: Bearer $(heroku auth:token)" \
-H "content-type: application/json" \
-d '{ "query": "query { listClips { id title versions(limit: 1) { sql } } }" }' \
https://data-api.heroku.com/graphql \
> clips.json
# also munge the output JSON into a text list of just UUIDs for additional manipulation
less clips.json|\
python -m json.tool|\ # get attributes on their own lines
grep \"id\"|\ # filter for just the lines with UUIDs
awk '{print substr($2,2,length($2)-3)}'\ # awk out just the UUID
>uuids.txt
@mrmemes-eth
Copy link
Author

It goes without saying that this is neither a sanctioned usage nor a stable API, so it may break without warning. C'est la vie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment