Discuss Scratch
- TheGamer-
- Scratcher
100+ posts
New(er) API documentation
I've been trying to find some documentation for the new(er) api (api.scratch…), but what I could find didn't have many of the features of the old one shown (ie posting comments, following etc). Is there a topic for this somewhere or have they just not been migrated (yet?). Sorry if I've just managed to miss it somehow
232323.XFTQ.2011 | XqzkBEpogUjTtMDjTEyI
- NitroCipher
- Scratcher
500+ posts
New(er) API documentation
@_nix Is there any way to read/write data to/from the backpack?
I hope my post helped you in some way! Post count: 500+
Current project: [s3Blocks: scratchblocks rewritten for Scratch 3.0] ::#4b4a60 //https://scratch.mit.edu/discuss/topic/290031/ Basically done!This is my signature identifier “aWFtbml0cm9jaXBoZXI=”
- herohamp
- Scratcher
1000+ posts
New(er) API documentation
Just self host crossorigin.me, or use Do the new APIs have CORS? The scratchblocks generator is sad http://crossorigin.mooredrive.pw/
- jokebookservice1
- Scratcher
1000+ posts
New(er) API documentation
Not with the new API, I don't think… but you can use the old API. @_nix Is there any way to read/write data to/from the backpack?
GET https://scratch.mit.edu/internalapi/USERNAME/get/
with session cookie
and
POST https://scratch.mit.edu/internalapi/USERNAME/set/
with X-CSRFToken and session cookie and JSON payload as body
- NitroCipher
- Scratcher
500+ posts
New(er) API documentation
Not with the new API, I don't think… but you can use the old API. @_nix Is there any way to read/write data to/from the backpack?GET https://scratch.mit.edu/internalapi/USERNAME/get/
with session cookie
andPOST https://scratch.mit.edu/internalapi/USERNAME/set/
with X-CSRFToken and session cookie and JSON payload as body
I cant seem to get this to work. How could i accomplish this with javascript?
Last edited by NitroCipher (Dec. 11, 2017 20:48:02)
I hope my post helped you in some way! Post count: 500+
Current project: [s3Blocks: scratchblocks rewritten for Scratch 3.0] ::#4b4a60 //https://scratch.mit.edu/discuss/topic/290031/ Basically done!This is my signature identifier “aWFtbml0cm9jaXBoZXI=”
- jokebookservice1
- Scratcher
1000+ posts
New(er) API documentation
Which one are you using, get or set? What code are you currently trying? Where are you running the code?
- NitroCipher
- Scratcher
500+ posts
New(er) API documentation
Which one are you using, get or set? What code are you currently trying? Where are you running the code?
alert("test"); $.get("https://scratch.mit.edu/internalapi/NitroCipher/get/", function(data, status){ alert("Data: " + data + "\nStatus: " + status); }); alert("test2");
I have a button event that triggers this in a userscript. Both alerts surrounding the get function properly.
I hope my post helped you in some way! Post count: 500+
Current project: [s3Blocks: scratchblocks rewritten for Scratch 3.0] ::#4b4a60 //https://scratch.mit.edu/discuss/topic/290031/ Basically done!This is my signature identifier “aWFtbml0cm9jaXBoZXI=”
- jokebookservice1
- Scratcher
1000+ posts
New(er) API documentation
Excuse me, that was a mistake on my part
The get request is actually
The get request is actually
GET https://scratch.mit.edu/internalapi/backpack/NitroCipher/get/
- NitroCipher
- Scratcher
500+ posts
New(er) API documentation
Excuse me, that was a mistake on my part
The get request is actuallyGET https://scratch.mit.edu/internalapi/backpack/NitroCipher/get/
How would I add this:
{"type": "script", "name": "Exported from Resurgence", "scripts": [[["procDef", "color %c", ["color"], [""], false]]]}
I hope my post helped you in some way! Post count: 500+
Current project: [s3Blocks: scratchblocks rewritten for Scratch 3.0] ::#4b4a60 //https://scratch.mit.edu/discuss/topic/290031/ Basically done!This is my signature identifier “aWFtbml0cm9jaXBoZXI=”
- jokebookservice1
- Scratcher
1000+ posts
New(er) API documentation
Okay, so you'll want to extract the CSRF middleware token. You can find it in document.cookie, and do some RegExes or something to extract it.
The body you will want is your JSON.
You will need to add this header
And that should work.
POST https://scratch.mit.edu/internalapi/backpack/NitroCipher/set/
The body you will want is your JSON.
You will need to add this header
X-CSRFToken: TOKENHERE
And that should work.
- NitroCipher
- Scratcher
500+ posts
New(er) API documentation
Okay, so you'll want to extract the CSRF middleware token. You can find it in document.cookie, and do some RegExes or something to extract it.POST https://scratch.mit.edu/internalapi/backpack/NitroCipher/set/
The body you will want is your JSON.
You will need to add this headerX-CSRFToken: TOKENHERE
And that should work.
How would all of this look in JS? (I am a noob dev)
I hope my post helped you in some way! Post count: 500+
Current project: [s3Blocks: scratchblocks rewritten for Scratch 3.0] ::#4b4a60 //https://scratch.mit.edu/discuss/topic/290031/ Basically done!This is my signature identifier “aWFtbml0cm9jaXBoZXI=”
- NitroCipher
- Scratcher
500+ posts
New(er) API documentation
How would all of this look in JS? (I am a noob dev)
Halp
I hope my post helped you in some way! Post count: 500+
Current project: [s3Blocks: scratchblocks rewritten for Scratch 3.0] ::#4b4a60 //https://scratch.mit.edu/discuss/topic/290031/ Basically done!This is my signature identifier “aWFtbml0cm9jaXBoZXI=”
- jokebookservice1
- Scratcher
1000+ posts
New(er) API documentation
Another mistake from me.. you're supposed to use the CDN server for setting. I'm unsure, but I think the following should work.
I'm basing all this from https://github.com/trumank/scratch-api/blob/master/scratchapi.js
$.ajax({
url: "https://cdn.scratch.mit.edu/internalapi/backpack/NitroCipher/set/",
headers: {
"X-CSRFToken": document.cookie.match(/scratchcsrftoken=([^;]+)/)[1]
},
data: JSON.stringify({"type": "script", "name": "Exported from Resurgence", "scripts": [[["procDef", "color %c", ["color"], [""], false]]]})
})
I'm basing all this from https://github.com/trumank/scratch-api/blob/master/scratchapi.js
- NitroCipher
- Scratcher
500+ posts
New(er) API documentation
Another mistake from me.. you're supposed to use the CDN server for setting. I'm unsure, but I think the following should work.$.ajax({
url: "https://cdn.scratch.mit.edu/internalapi/backpack/NitroCipher/set/",
headers: {
"X-CSRFToken": document.cookie.match(/scratchcsrftoken=([^;]+)/)[1]
},
data: JSON.stringify({"type": "script", "name": "Exported from Resurgence", "scripts": [[["procDef", "color %c", ["color"], [""], false]]]})
})
I'm basing all this from https://github.com/trumank/scratch-api/blob/master/scratchapi.js
Will this add it to the backpack? Or replace the current backpack data?
I hope my post helped you in some way! Post count: 500+
Current project: [s3Blocks: scratchblocks rewritten for Scratch 3.0] ::#4b4a60 //https://scratch.mit.edu/discuss/topic/290031/ Basically done!This is my signature identifier “aWFtbml0cm9jaXBoZXI=”
- MathWizz
- Scratcher
100+ posts
New(er) API documentation
Uh, it shouldn't be sending a request to the CDN server. I have no idea how that happened. It works though so I'm not gonna change it right now. Another mistake from me.. you're supposed to use the CDN server for setting. I'm unsure, but I think the following should work.$.ajax({
url: "https://cdn.scratch.mit.edu/internalapi/backpack/NitroCipher/set/",
headers: {
"X-CSRFToken": document.cookie.match(/scratchcsrftoken=([^;]+)/)[1]
},
data: JSON.stringify({"type": "script", "name": "Exported from Resurgence", "scripts": [[["procDef", "color %c", ["color"], [""], false]]]})
})
I'm basing all this from https://github.com/trumank/scratch-api/blob/master/scratchapi.js
It will replace the entire backpack. Will this add it to the backpack? Or replace the current backpack data?
running Chromium 42.0.2311.90 with Flash Player 15.0.0.189 on Arch Linux 3.19.5-1-ck
MathWizz — JsScratch && sb.js & Amber (coming soon! maybe)
- NitroCipher
- Scratcher
500+ posts
New(er) API documentation
Uh, it shouldn't be sending a request to the CDN server. I have no idea how that happened. It works though so I'm not gonna change it right now. Another mistake from me.. you're supposed to use the CDN server for setting. I'm unsure, but I think the following should work.$.ajax({
url: "https://cdn.scratch.mit.edu/internalapi/backpack/NitroCipher/set/",
headers: {
"X-CSRFToken": document.cookie.match(/scratchcsrftoken=([^;]+)/)[1]
},
data: JSON.stringify({"type": "script", "name": "Exported from Resurgence", "scripts": [[["procDef", "color %c", ["color"], [""], false]]]})
})
I'm basing all this from https://github.com/trumank/scratch-api/blob/master/scratchapi.jsIt will replace the entire backpack. Will this add it to the backpack? Or replace the current backpack data?
I can't seem to get it to post
I hope my post helped you in some way! Post count: 500+
Current project: [s3Blocks: scratchblocks rewritten for Scratch 3.0] ::#4b4a60 //https://scratch.mit.edu/discuss/topic/290031/ Basically done!This is my signature identifier “aWFtbml0cm9jaXBoZXI=”
- jokebookservice1
- Scratcher
1000+ posts
New(er) API documentation
Whoops! You need to stringify an array containing the backpack, I think; and not the individual item. Perhaps that's the reason why it's not working?
However, I'm interested what you mean by “won't post”. Do you mean it returns a status code other than 200; or literally a POST request isn't being made. If the latter, is another verb being used, or is no request being sent at all?
However, I'm interested what you mean by “won't post”. Do you mean it returns a status code other than 200; or literally a POST request isn't being made. If the latter, is another verb being used, or is no request being sent at all?