example
Here is an example of the use of lexicons.
option
# reverse
curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=${handle}&collection=app.bsky.feed.post&reverse=true"
login
handle=yui.syui.ai
pass=xxx
curl -sL -X POST -H "Content-Type: application/json" \
-d "{\"identifier\":\"$handle\",\"password\":\"$pass\"}" \
https://bsky.social/xrpc/com.atproto.server.createSession
# token
token=`curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$pass\"}" https://bsky.social/xrpc/com.atproto.server.createSession|jq -r .accessJwt`
# did
did=`curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$pass\"}" https://bsky.social/xrpc/com.atproto.server.createSession|jq -r .did`
# profile
curl -sL -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
"https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=${handle}"
# notify
curl -sL -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
https://bsky.social/xrpc/app.bsky.notification.listNotifications
post
col=app.bsky.feed.post
created_at=`date --iso-8601=seconds`
json="{
\"repo\": \"$handle\",
\"did\": \"$did\",
\"collection\": \"$col\",
\"record\": {
\"text\": \"hello world\",
\"createdAt\": \"$created_at\"
}
}"
# post
curl -sL -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-d "$json" \
https://bsky.social/xrpc/com.atproto.repo.createRecord
mention
example.json
{
"did": "did:plc:4hqjfn7m6n5hno3doamuhgef",
"repo": "yui.syui.ai",
"collection": "app.bsky.feed.post",
"record": {
"text": "test",
"$type": "app.bsky.feed.post",
"createdAt": "2023-07-20T13:05:45+09:00",
"facets": [
{
"$type": "app.bsky.richtext.facet",
"index": {
"byteEnd": 13,
"byteStart": 0
},
"features": [
{
"did": "did:plc:4hqjfn7m6n5hno3doamuhgef",
"$type": "app.bsky.richtext.facet#mention"
}
]
}
]
}
}
# mention
col=app.bsky.feed.post
handle_m=yui.syui.ai
did_m=`curl -sL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $token" "https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=${handle_m}"|jq -r .did`
at=@${handle_m}
s=0
e=`echo $at|wc -c`
json="{
\"did\": \"$did\",
\"repo\": \"$handle\",
\"collection\": \"$col\",
\"record\": {
\"text\": \"$text\",
\"\$type\": \"app.bsky.feed.post\",
\"createdAt\": \"$created_at\",
\"facets\": [
{
\"\$type\": \"app.bsky.richtext.facet\",
\"index\": {
\"byteEnd\": $e,
\"byteStart\": $s
},\"features\": [
{
\"did\": \"$did_m\",
\"\$type\": \"app.bsky.richtext.facet#mention\"
}
]
}
]
}
}"
curl -sL -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-d "$json" \
https://bsky.social/xrpc/com.atproto.repo.createRecord
output
{"uri":"at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.post/3k2wkbvcasf24","cid":"bafyreiecswq5qhk7f4xxztevzbfynocsgmjrmr3hwqoluhhzvqgowalivi"}
reply
example.json
{
"repo": "yui.syui.ai",
"did": "did:plc:4hqjfn7m6n5hno3doamuhgef",
"collection": "app.bsky.feed.post",
"record": {
"text": "reply",
"createdAt": "2023-07-20T13:05:45+09:00",
"reply": {
"root": {
"cid": "bafyreiecswq5qhk7f4xxztevzbfynocsgmjrmr3hwqoluhhzvqgowalivi",
"uri": "at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.post/3k2wkbvcasf24"
},
"parent": {
"cid": "bafyreiecswq5qhk7f4xxztevzbfynocsgmjrmr3hwqoluhhzvqgowalivi",
"uri": "at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.post/3k2wkbvcasf24"
}
}
}
}
# reply
col=app.bsky.feed.post
uri=at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.post/3k2wkbvcasf24
cid=bafyreiecswq5qhk7f4xxztevzbfynocsgmjrmr3hwqoluhhzvqgowalivi
json="{
\"repo\": \"$handle\",
\"did\": \"$did\",
\"collection\": \"$col\",
\"record\": {
\"text\": \"reply\",
\"createdAt\": \"$created_at\",
\"reply\": {
\"root\": {
\"cid\": \"$cid\",
\"uri\": \"$uri\"
},
\"parent\": {
\"cid\": \"$cid\",
\"uri\": \"$uri\"
}
}
}
}"
curl -sL -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-d "$json" \
https://bsky.social/xrpc/com.atproto.repo.createRecord
like
# reply
col=app.bsky.feed.like
uri=at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.post/3k2wkbvcasf24
cid=bafyreiecswq5qhk7f4xxztevzbfynocsgmjrmr3hwqoluhhzvqgowalivi
json="{
\"repo\": \"$handle\",
\"did\": \"$did\",
\"collection\": \"$col\",
\"record\": {
\"createdAt\": \"$created_at\",
\"subject\": {
\"cid\": \"$cid\",
\"uri\": \"$uri\"
}
}
}"
curl -sL -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-d "$json" \
https://bsky.social/xrpc/com.atproto.repo.createRecord
follow
col=app.bsky.graph.follow
handle_m=yui.syui.ai
did_m=`curl -sL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $token" "https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=${handle_m}"|jq -r .did`
json="{
\"repo\": \"$handle\",
\"did\": \"$did\",
\"collection\": \"$col\",
\"record\": {
\"createdAt\": \"$created_at\",
\"subject\": \"$did_m\"
}
}"
curl -sL -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-d "$json" \
https://bsky.social/xrpc/com.atproto.repo.createRecord
unfollow
$ curl -sL -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
"https://bsky.social/xrpc/app.bsky.graph.getFollowers?actor=${handle}&cursor=${cursor}" \
|jq -r ".cursor"
1688489398761::bafyreieie7opxd5mojipvk3xe3h65u3qvpungskqxamldepctfbd6xhdcu
cursor=1688489398761::bafyreieie7opxd5mojipvk3xe3h65u3qvpungskqxamldepctfbd6xhdcu
$ curl -sL -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
"https://bsky.social/xrpc/app.bsky.graph.getFollowers?actor=${handle}&cursor=${cursor}" \
|jq -r ".followers|.[0].viewer.followedBy"
at://did:plc:uqzpqmrjnptsxezjx4xuh2mn/app.bsky.graph.follow/3k2wkjr6cnj2x
col=app.bsky.graph.follow
rkey=at://did:plc:uqzpqmrjnptsxezjx4xuh2mn/app.bsky.graph.follow/3k2wkjr6cnj2x
handle_m=yui.syui.ai
did_m=`curl -sL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $token" "https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=${handle_m}"|jq -r .did`
json="{
\"repo\": \"$handle\",
\"did\": \"$did\",
\"collection\": \"$col\",
\"rkey\":\"$rkey\",
\"record\": {
\"createdAt\": \"$created_at\",
\"subject\": \"$did_m\"
}
}"
curl -sL -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-d "$json" \
https://bsky.social/xrpc/com.atproto.repo.deleteRecord