Discuss Scratch

god286
Scratcher
1000+ posts

How to change title with API?

I have code here:
async setTitle(value: string) {
    const setFetch = await fetch(`https://api.scratch.mit.edu/projects/${this.id}`, {
      method: "PUT",
      body: JSON.stringify({
        title: value
      }),
      headers: {
        "x-csrftoken": this.session.csrfToken,
        "X-Token": this.session.token,
        "x-requested-with": "XMLHttpRequest",
        Cookie: "scratchcsrftoken=" + this.session.csrfToken + ";scratchlanguage=en;scratchsessionsid=" + this.session.token + ";",
        referer: `https://scratch.mit.edu/projects/${this.id}/`,
        "User-Agent": UserAgent,
        accept: "application/json",
        "Content-Type": "application/json"
      }
    })
    if (!setFetch.ok) {
      throw new Error(`Error in setting title. ${await setFetch.text()}`)
    }
}
It gives 403 Unauthorised though?
I took code from scratchclient

Last edited by god286 (Jan. 25, 2022 04:21:34)


Here are some of my followers!

I joined: 5 years, 9 months, 24 days ago (31/03/2018)
I have: 479 followers
In total, I have attained: 1,403 loves, 1,145 favourites, and 33,731 views.
Fun Fact: If my account continued to gain followers at a similar rate to right now, in 14,210 years I would reach the number of followers griffpatch has today! Try to imagine how many followers he would have then!
Thank you everyone!
Script created by god286.
-EmeraldThunder-
Scratcher
1000+ posts

How to change title with API?

Are you sure your code to log you in is correct?

Nothing here.
god286
Scratcher
1000+ posts

How to change title with API?

-EmeraldThunder- wrote:

Are you sure your code to log you in is correct?
yes I am sure, I got a CSRF Token and Token back, but I checked network logs, it doesn't seem to need CSRF token, and X-Token is something different? Where do I get that X-Token??

Last edited by god286 (Jan. 25, 2022 06:35:31)


Here are some of my followers!

I joined: 5 years, 9 months, 24 days ago (31/03/2018)
I have: 479 followers
In total, I have attained: 1,403 loves, 1,145 favourites, and 33,731 views.
Fun Fact: If my account continued to gain followers at a similar rate to right now, in 14,210 years I would reach the number of followers griffpatch has today! Try to imagine how many followers he would have then!
Thank you everyone!
Script created by god286.
god286
Scratcher
1000+ posts

How to change title with API?

OK can someone please explain to me where that X-Token comes from in the request to https://api.scratch.mit.edu/projects/ID ??? I have no idea…

Here are some of my followers!

I joined: 5 years, 9 months, 24 days ago (31/03/2018)
I have: 479 followers
In total, I have attained: 1,403 loves, 1,145 favourites, and 33,731 views.
Fun Fact: If my account continued to gain followers at a similar rate to right now, in 14,210 years I would reach the number of followers griffpatch has today! Try to imagine how many followers he would have then!
Thank you everyone!
Script created by god286.
Maximouse
Scratcher
1000+ posts

How to change title with API?

god286 wrote:

OK can someone please explain to me where that X-Token comes from in the request to https://api.scratch.mit.edu/projects/ID ??? I have no idea…
You need to request https://scratch.mit.edu/session/ with the scratchsessionid cookie to get the token.


This is Maximouse's signature. Learn more about signatures.
god286
Scratcher
1000+ posts

How to change title with API?

Maximouse wrote:

god286 wrote:

OK can someone please explain to me where that X-Token comes from in the request to https://api.scratch.mit.edu/projects/ID ??? I have no idea…
You need to request https://scratch.mit.edu/session/ with the scratchsessionid cookie to get the token.
Thank you so much!!

Here are some of my followers!

I joined: 5 years, 9 months, 24 days ago (31/03/2018)
I have: 479 followers
In total, I have attained: 1,403 loves, 1,145 favourites, and 33,731 views.
Fun Fact: If my account continued to gain followers at a similar rate to right now, in 14,210 years I would reach the number of followers griffpatch has today! Try to imagine how many followers he would have then!
Thank you everyone!
Script created by god286.

Powered by DjangoBB