Why?
When users sign up to Bluesky, they choose a “handle”: their username, effectively, by which other users will recognise them. However, Bluesky users can change their handle, so accounts are assigned a persistent “decentralised id” that uniquely identifies the account, even if the handle is changed.
Bluesky API requests usually prefer the DID to the handle, so knowing a user’s DID (usually your own!) is useful.
How?
Add this function to the Apps Script Editor. Call it in the editor window (change return to Logger.log()) or output the return value to a cell on a Sheet.
function getDid(handle) {
const API_URL = "https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle";
const url = encodeURI(API_URL + "?handle=" + handle);
const params = {
"method" : "get"
};
const response = UrlFetchApp.fetch(url, params);
return did = JSON.parse(response.getContentText()).did;
}
