Skip to content

Instantly share code, notes, and snippets.

Last active September 11, 2023 17:30
  • Star 19 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Bluesky/AT Protocol: cURL API Interaction Cheatsheet
# This script resolves a DID, retrieves an API key, fetches a user's feed,
# and posts a "Hello, world" message to the user's feed.
# Resolve DID for handle
export DID=$(curl -G \
--data-urlencode "handle=$HANDLE" \
"$DID_URL" | jq -r .did)
# Get an app password from here:
export APP_PASSWORD=myapppassword
# Get API key with the app password
POST_DATA="{ \"identifier\": \"${DID}\", \"password\": \"${APP_PASSWORD}\" }"
export API_KEY=$(curl -X POST \
-H 'Content-Type: application/json' \
-d "$POST_DATA" \
"$API_KEY_URL" | jq -r .accessJwt)
# Get a user's feed
curl -G \
-H "Authorization: Bearer ${API_KEY}" \
--data-urlencode "actor=$ACTOR" \
--data-urlencode "limit=$LIMIT" \
"$FEED_URL" | jq -r .feed # Or if you want to return only a user's own posts: jq '.feed | .[] | select((.post.record."$type" == "") and (.post.record.reply.parent? | not) and (.reason? | not)) | {text: .post.record.text, createdAt: .post.record.createdAt, replyCount: .post.replyCount, repostCount: .post.repostCount, likeCount: .post.likeCount, author: {handle:, displayName:, avatar:}}'
# Post "Hello, world" to your feed
POST_RECORD="{ \"collection\": \"\", \"repo\": \"${DID}\", \"record\": { \"text\": \"Hello, world\", \"createdAt\": \"$(date +%Y-%m-%dT%H:%M:%S.%3NZ)\", \"\$type\": \"\" } }"
curl -X POST \
-H "Authorization: Bearer ${API_KEY}" \
-H 'Content-Type: application/json' \
"$POST_FEED_URL" | jq -r
Copy link

Thanks, your examples were very helpful :)

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