Discuss Scratch

ProfessorThickhead
Scratcher
100+ posts

Is there a way to see your messages through the API?

I know you can see your message count, but I was wondering if you can see the actual content of your messages. I tried https://api.scratch.mit.edu/users/ProfessorThickhead/messages, but it yields no satisfactory results:
{"code":"Unauthorized","message":""}
Do you need a token or something, or is there another link? Is it possible at all?
Thanks!
-I wanted to sign this with my name and then realized that I was on Scratch and it would be a reportable offense of the CGs
Clippy-Cat
Scratcher
66 posts

Is there a way to see your messages through the API?

Scratch uses an X-Token to make sure all requests are coming from a trustworthy source. This token can be found by going to /session, and viewing the page source, it will be under user/token.

Once you have this token, make sure to send it in a header named X-Token. Here's how that would be done in JavaScript

fetch("https://api.scratch.mit.edu/users/<your-username>/messages",
  {
    headers: {
      "X-Token": "Your-Token"
    }
  }
)

A lot of info taken from the Unofficial Scratch API docs. Specifically the pages about users and authentication.

Also: Just a reminder that topics about internal workings of Scratch, or external usage of internal works of Scratch, belong in Advanced Topics.

Last edited by Clippy-Cat (Sept. 17, 2023 20:57:48)

ajskateboarder
Scratcher
1000+ posts

Is there a way to see your messages through the API?

I don't think a token is used for grabbing user messages. You might need to use a session ID

wrong, whoopsies

Last edited by ajskateboarder (Sept. 17, 2023 20:52:12)

cosmosaura
Scratch Team
1000+ posts

Is there a way to see your messages through the API?

I'll move this over to the Advanced Topics section for you - that's a better fit for this kind of topic

Powered by DjangoBB