From e894dc4aaa96d97bbc455b0cbbb47c4bc3c79631 Mon Sep 17 00:00:00 2001 From: Brice Vandeputte Date: Fri, 31 May 2024 20:47:26 +0200 Subject: [PATCH] Fix #152 http reference introduction add BskyAgent basic example --- docs/api/at-protocol-xrpc-api.info.mdx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/api/at-protocol-xrpc-api.info.mdx b/docs/api/at-protocol-xrpc-api.info.mdx index 5989d6650..7ae35690f 100644 --- a/docs/api/at-protocol-xrpc-api.info.mdx +++ b/docs/api/at-protocol-xrpc-api.info.mdx @@ -27,7 +27,25 @@ import Export from "@theme/ApiExplorer/Export"; -This section contains HTTP API reference docs for Bluesky and AT Protocol lexicons. Generate a bearer token to test API calls directly from the docs. +This section contains HTTP API reference docs for Bluesky and AT Protocol lexicons. + +You could generate a bearer token to test API calls directly from the docs. + +You could also use `BskyAgent` directly. In this is an example, `BskyAgent` instance will call actor `getPreferences` api : + +```javascript +import process from "node:process"; +import {BskyAgent} from '@atproto/api'; +const {"BLUESKY_USERNAME": identifier, "BLUESKY_PASSWORD": password} = process.env;// creds from env +const agent = new BskyAgent({"service": "https://api.bsky.social"}) +await agent.login({identifier, password}); + +// api call +const response = await agent.api.app.bsky.actor.getPreferences(); + +const {preferences} = response.data +console.log(`${identifier}'s preferences:\n` + JSON.stringify(preferences, null, 2)); +```