sidebar_position |
---|
1 |
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Make your first post to the Bluesky app via the API in under 5 minutes.
Choose the SDK you want to work with. Below, we use TypeScript and Python. You can follow the instructions for the community-maintained atproto.dart package here.
Install [@atproto/api](https://www.npmjs.com/package/@atproto/api) using your preferred package manager.```
yarn add @atproto/api
```
```
pip install atproto
```
</TabItem>
Create an authentication session with your username and password.
```typescript import { BskyAgent } from '@atproto/api'const agent = new BskyAgent({
service: 'https://bsky.social'
})
await agent.login({
identifier: 'handle.example.com',
password: 'hunter2'
})
```
```bash
curl -X POST $PDSHOST/xrpc/com.atproto.server.createSession \
-H "Content-Type: application/json" \
-d '{"identifier": "'"$BLUESKY_HANDLE"'", "password": "'"$BLUESKY_PASSWORD"'"}'
```
client = Client()
client.login('handle.example.com', 'hunter2')
```
</TabItem>
The com.atproto.server.createSession
API endpoint returns a session object containing two API tokens:
accessJwt
: an access token which is used to authenticate requests but expires after a few minutesrefreshJwt
: a refresh token which lasts longer and is used only to update the session with a new access token
Now you can create a post by sending a POST request to the createRecord endpoint.
```typescript await agent.post({ text: 'Hello world! I posted this via the API.', createdAt: new Date().toISOString() }) ``` Replace `$BLUESKY_HANDLE` with your handle, `$PDSHOST` with your PDS host (including `https://`), and and `$ACCESS_JWT` with the JWT in the response from createSession.```bash
curl -X POST $PDSHOST/xrpc/com.atproto.repo.createRecord \
-H "Authorization: Bearer $ACCESS_JWT" \
-H "Content-Type: application/json" \
-d "{\"repo\": \"$BLUESKY_HANDLE\", \"collection\": \"app.bsky.feed.post\", \"record\": {\"text\": \"Hello world! I posted this via the API.\", \"createdAt\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}}"
```
This will return an object containing the post's URI and a CID (a hash of the content).
```json { "uri": "at://did:plc:abc123..../app.bsky.feed.post/xyz...", "cid": "abc..." } ``` ```json { "uri": "at://did:plc:abc123..../app.bsky.feed.post/xyz...", "cid": "abc..." } ``` ```python post.uri # at://did:plc:abc123..../app.bsky.feed.post/xyz... post.cid # abc... ```Check out your profile to see the post you just created!
- Jump to one of the Starter Templates:
- Continue reading Tutorials to learn more.