After a quick reading to the AT’s documentation, I wanted to quickly interact with “BlueSky” and of course “see” the AT protocol, so I remembered a tweet(?) screenshot that Kelsey shared… To be honest, I was looking for the “curl” command…But I got even more with Felicita’s script. Kudos to her!!!
I tested it, it partially worked for me:
- it downloaded my user’s feed.
- But it failed to post “Hello World”. I got the following error:
{
"error": "InvalidRequest",
"message": "Invalid app.bsky.feed.post record: Record/createdAt must be an iso8601 formatted datetime"
}
Anyway, since I was lazy to “Google/ChatGTP” it, I just removed the part that I suspect was causing the problem. (date +%Y-%m-%dT%H:%M:%S instead of the original date +%Y-%m-%dT%H:%M:%S.%3NZ)
#!/bin/bash
# This script resolves a DID, retrieves an API key,
# and posts a "Hello, world" message to the user's feed.
# Resolve DID for handle
HANDLE='alexrabocse.me'
DID_URL="https://bsky.social/xrpc/com.atproto.identity.resolveHandle"
export DID=$(curl -G \
--data-urlencode "handle=$HANDLE" \
"$DID_URL" | jq -r .did)
# Get an app password from here: https://staging.bsky.app/settings/app-passwords
export APP_PASSWORD=my-fake-password
# Get API key with the app password
API_KEY_URL='https://bsky.social/xrpc/com.atproto.server.createSession'
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)
# Post "Hello, world" to your feed
POST_FEED_URL='https://bsky.social/xrpc/com.atproto.repo.createRecord'
POST_RECORD="{ \"collection\": \"app.bsky.feed.post\", \"repo\": \"${DID}\", \"record\": { \"text\": \"Hello, world\", \"createdAt\": \"$(date +%Y-%m-%dT%H:%M:%S)\", \"\$type\": \"app.bsky.feed.post\" } }"
curl -X POST \
-H "Authorization: Bearer ${API_KEY}" \
-H 'Content-Type: application/json' \
-d "$POST_RECORD" \
"$POST_FEED_URL" | jq -r
After that, I could post my Hello world. :)
I think this example is enough for me to start to play more in the future.
Again, kudos to Felicitas. :)