bluesky-social / atproto

Social networking technology created by Bluesky
Other
6.17k stars 432 forks source link

app.bsky.graph.listitem record creation not working as documented? #2730

Closed StuBilli closed 1 month ago

StuBilli commented 1 month ago

Describe the bug

I'm trying (and failing) to add a new member to a list I have created. If I post a record creation request to https://public.api.bsky.app/xrpc/com.atproto.repo.createRecord I get "405 Method Not Allowed". However, if I instead post the same request to https://bsky.social/xrpc/com.atproto.repo.createRecord it works (ie a record is created)...but then the new member doesn't show up on the list, e.g. in the Bluesky app.

Similarly, if I send a GET request for the same list to https://public.api.bsky.app/xrpc/app.bsky.graph.getList the response comes back with items:[] (even though the list has over 100 members when viewed in the Bluesky app), whereas if I send it to https://bsky.social/xrpc/app.bsky.graph.getList it returns a response.items with the single member that I added via the bsky.social request above.

I don't understand the difference between the two domains sufficiently to understand what's going on, but I suspect (?) the failure/success is because I'm getting my accessJwt token using a request to https://bsky.social/xrpc/com.atproto.server.createSession. However, requests for a token send to https://public.api.bsky.app/xrpc/com.atproto.server.createSession also return a "405 Method Not Allowed" error, so I'm not sure how to solve this??

Public documentation:

These all point to using public.api.bsky.app, not bsky.social, including for the token.

To Reproduce

Steps to reproduce the behavior:

I'm just using a url fetch request within a Google Apps Script.

Token request:

const url = "https://bsky.social/xrpc/com.atproto.server.createSession";  // public.api.bsky.app results in 405 error
const params = {
  "contentType": "application/json",
  "method" : "post",
  "payload" : JSON.stringify({"identifier": "did:plc:4iq3wprtkim2tmlzabsj3dfo", "password": MY_APP_PASSWORD})
};
const response = UrlFetchApp.fetch(url, params);
return JSON.parse(response.getContentText()).accessJwt;

Add list record request:

const url = 'https://bsky.social/xrpc/com.atproto.repo.createRecord'; // This creates a record, but not in correct place, public.api.bsky.app gives 405 error
const body = {
  "repo": "did:plc:4iq3wprtkim2tmlzabsj3dfo",
  "collection": "app.bsky.graph.listitem",
  "record": {
    "$type": "app.bsky.graph.listitem",
    "subject": DID_OF_ANY_USER,
    "list": "at://did:plc:4iq3wprtkim2tmlzabsj3dfo/app.bsky.list/3kzghwrh2wy25",
    "createdAt": new Date().toISOString()
  }
};
const params = {
  "contentType": "application/json",
  "headers": {"Authorization": "Bearer " + TOKEN_FROM_ABOVE},
  "method": "post",
  "payload": JSON.stringify(body),
  "muteHttpExceptions": true
};
const response = UrlFetchApp.fetch(url, params);

Expected behavior

The documentation says requests to public.api.bsky.app will create a record.

Details

Additional context

Other requests work as expected. For instance, I can post using https://bsky.social/xrpc/com.atproto.repo.createRecord and retrieve my posts using https://bsky.social/xrpc/app.bsky.feed.getAuthorFeed. So I assumed I should just use bsky.social for all, but where is the list record going...as it isn't visible in the Bluesky app the way the script-generated post is...

StuBilli commented 1 month ago

Traced it to the name of the list -- should be app.bsky.graph.list not app.bsky.list. Didn't realise, as it was returning a partial response.