Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
- TheColaber
- Scratcher
500+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
Scratch API Dictionary (WIP) - v0.0.8 - Added More Text in About
About
I just wanted to keep this up here just in case people like me wanted to learn about Scratch's API to use a little JavaScript or another language and get data from it. This Dictionary will be broken up in parts to help keep everything organized for you. NOTE: That this is mainly based on the Scratch Wiki's format.
When opening these URLs, replace the parts that are surrounded in brackets and are in written in capitals, e.g. ‘{USERNAME}’, if there is any. Some of these URLs could only be accessed when one is logged in, as they return personal data which is invisible to other users. Some APIs may not be documented here; this may be intended, for some APIs are more dangerous than the others when abused. Some of these URLs require different request methods; you browser uses GET when you load a page. Data is returned in either HTML or JSON depending on the command.
Some of these could be workarounds for some suggestions, or solve problems when computer programs are used to harvest mass data. Others are good for satisfying curious Scratchers. The Scratch Team disallows programs that requests APIs massively (e.g. a program that adds hundreds of random projects per second to a studio), because they slow the servers down. They have removed many of their old API's that actually change data, like an API for following an unfollowing a user.
Did you know that https://scratchnotifier.cf/ and https://scratchstats.com/ uses Scratch's API to get it's data? That's how great and powerful they are!
Please Note that some information on the wiki about Scratch's API is missing or doesn't work currently.
Setup!
Best to probably have a JSON formatter. Most likely, when viewing scratch's API, It won't be a formatted JSON. (removed by moderator - please don't post links to extensions)
Next, make sure to have a file editor like Atom and create a file with the file-type of your choice. Here's the code for the following languages to get the api for most websites:
Javascipt:
The first parameter for the function is the website to the api you are going to. The second parameter is a callback in which the first parameter is data it got back.
api.scratch.mit.edu Interface
The api.scratch.mit.edu interface is the latest revision of the Scratch API. It can be used to return various types of data regarding the Scratch website. This API can be accessed via the following URL:
Use /health for getting the status of the website. This is good to check before doing anything with the API to check if the website is even up.
Use /news for getting information regarding the “Scratch News” section of the homepage.
Use /proxy/featured for getting information regarding the projects currently visible on the front page of the website.
Use /users/{USERNAME} for getting information about the specified user.
Use /users/{USERNAME}/favorites for getting an array of details regarding the projects that a given user has favourited.
Use /users/{USERNAME}/followers for getting an array of a user's most recent followers. This will at most return 20 items.
Use /users/{USERNAME}/following for getting an array of the users that the specified user has most recently followed. This will at most return 20 items.
Use /users/{USERNAME}/messages/count for the number of unread messages a user currently has. VERY Accurate!
Use /users/{USERNAME}/projects for the information regarding the projects that a given user has shared. This will at most return 20 items.
Use /users/{USERNAME}/messages/count for the number of unread messages a user currently has. VERY Accurate!
Use /projects/{PROJECT_ID} for information relevant to the given project.
Use /studios/{STUDIO_ID} for the information relevant to the given studio.
Use /explore/projects/?mode={MODE} for the information of projects from the Explore Page relevant to the given mode.
Use /explore/studios/?mode={MODE} for the information of studios from the Explore Page relevant to the given mode.
Use /search/studios/?mode={MODE} for the information of projects from the search Page relevant to the given mode.
Use /search/projects/?mode={MODE} for the information of studios from the search Page relevant to the given mode.
Use /projects/{PROJECT_ID}/remixes for the information of studios from the search Page relevant to the given mode.
Extras
________________________________________________________________________
For API URLs that only return 20 items, you can use ?offset and/or ?limit to get different or less results. ‘Limit’ can, at max, be set to 20. ‘Offset’ can be greater than 20, however. To use both, you can do this example:
For the API URLs that contain search or explore, you can use ?q to search for a tag or name. For explore, using ‘q’ will search for a tag. For search, it will search for a tittle. Here is an example:
Sources:
https://en.scratch-wiki.info/wiki/Scratch_API
http://towerofnix.github.io/scratch-api-unofficial-docs/api/
https://scratchdb.lefty.one/
Help Needed!
About
I just wanted to keep this up here just in case people like me wanted to learn about Scratch's API to use a little JavaScript or another language and get data from it. This Dictionary will be broken up in parts to help keep everything organized for you. NOTE: That this is mainly based on the Scratch Wiki's format.
When opening these URLs, replace the parts that are surrounded in brackets and are in written in capitals, e.g. ‘{USERNAME}’, if there is any. Some of these URLs could only be accessed when one is logged in, as they return personal data which is invisible to other users. Some APIs may not be documented here; this may be intended, for some APIs are more dangerous than the others when abused. Some of these URLs require different request methods; you browser uses GET when you load a page. Data is returned in either HTML or JSON depending on the command.
Some of these could be workarounds for some suggestions, or solve problems when computer programs are used to harvest mass data. Others are good for satisfying curious Scratchers. The Scratch Team disallows programs that requests APIs massively (e.g. a program that adds hundreds of random projects per second to a studio), because they slow the servers down. They have removed many of their old API's that actually change data, like an API for following an unfollowing a user.
Did you know that https://scratchnotifier.cf/ and https://scratchstats.com/ uses Scratch's API to get it's data? That's how great and powerful they are!
Please Note that some information on the wiki about Scratch's API is missing or doesn't work currently.
Setup!
Best to probably have a JSON formatter. Most likely, when viewing scratch's API, It won't be a formatted JSON. (removed by moderator - please don't post links to extensions)
Next, make sure to have a file editor like Atom and create a file with the file-type of your choice. Here's the code for the following languages to get the api for most websites:
Javascipt:
function getFromAPI(api, callback) { var request = new XMLHttpRequest(); request.open('GET', "https://cors-anywhere.herokuapp.com/" + api, true); request.responseType = 'text'; request.onload = function () { if (request.readyState === request.DONE) { if (request.status === 200) { callback(JSON.parse(request.response)); } } }; request.send(null); } // Example getFromAPI("https://api.scratch.mit.edu/health", function(data) { console.log(data) })
api.scratch.mit.edu Interface
The api.scratch.mit.edu interface is the latest revision of the Scratch API. It can be used to return various types of data regarding the Scratch website. This API can be accessed via the following URL:
https://api.scratch.mit.eduGoing Directly to this site won't be useful without a root, but just know that this will be the start to most of the roots said below.
Use /health for getting the status of the website. This is good to check before doing anything with the API to check if the website is even up.
https://api.scratch.mit.edu/health
Use /news for getting information regarding the “Scratch News” section of the homepage.
https://api.scratch.mit.edu/news
Use /proxy/featured for getting information regarding the projects currently visible on the front page of the website.
https://api.scratch.mit.edu/proxy/featured
Use /users/{USERNAME} for getting information about the specified user.
https://api.scratch.mit.edu/users/TheColaber
Use /users/{USERNAME}/favorites for getting an array of details regarding the projects that a given user has favourited.
https://api.scratch.mit.edu/users/TheColaber/favorites
Use /users/{USERNAME}/followers for getting an array of a user's most recent followers. This will at most return 20 items.
https://api.scratch.mit.edu/users/TheColaber/followers
Use /users/{USERNAME}/following for getting an array of the users that the specified user has most recently followed. This will at most return 20 items.
https://api.scratch.mit.edu/users/TheColaber/following
Use /users/{USERNAME}/messages/count for the number of unread messages a user currently has. VERY Accurate!
https://api.scratch.mit.edu/users/griffpatch/messages/count
Use /users/{USERNAME}/projects for the information regarding the projects that a given user has shared. This will at most return 20 items.
https://api.scratch.mit.edu/users/TheColaber/projects
Use /users/{USERNAME}/messages/count for the number of unread messages a user currently has. VERY Accurate!
https://api.scratch.mit.edu/users/TheColaber/messages/count
Use /projects/{PROJECT_ID} for information relevant to the given project.
https://api.scratch.mit.edu/projects/421093937/
Use /studios/{STUDIO_ID} for the information relevant to the given studio.
https://api.scratch.mit.edu/studios/26970890/
Use /explore/projects/?mode={MODE} for the information of projects from the Explore Page relevant to the given mode.
https://api.scratch.mit.edu/explore/projects/?mode=trendingMODE can I either be popular, trending, recent. But it defaults to popular.
Use /explore/studios/?mode={MODE} for the information of studios from the Explore Page relevant to the given mode.
https://api.scratch.mit.edu/explore/studios/?mode=trending
Use /search/studios/?mode={MODE} for the information of projects from the search Page relevant to the given mode.
https://api.scratch.mit.edu/search/projects/?mode=trending**This is incomplete. See item #2 of ‘Extras’ Below. Adding that will make this complete.
Use /search/projects/?mode={MODE} for the information of studios from the search Page relevant to the given mode.
https://api.scratch.mit.edu/search/projects/?mode=trending**This is incomplete. See item #2 of ‘Extras’ Below. Adding that will make this complete.
Use /projects/{PROJECT_ID}/remixes for the information of studios from the search Page relevant to the given mode.
https://api.scratch.mit.edu/projects/389464290/remixes
Extras
________________________________________________________________________
For API URLs that only return 20 items, you can use ?offset and/or ?limit to get different or less results. ‘Limit’ can, at max, be set to 20. ‘Offset’ can be greater than 20, however. To use both, you can do this example:
https://api.scratch.mit.edu/users/TheColaber/followers?offset=20&limit=5________________________________________________________________________
For the API URLs that contain search or explore, you can use ?q to search for a tag or name. For explore, using ‘q’ will search for a tag. For search, it will search for a tittle. Here is an example:
https://api.scratch.mit.edu/search/projects/?mode=trending&q=pie________________________________________________________________________
Sources:
https://en.scratch-wiki.info/wiki/Scratch_API
http://towerofnix.github.io/scratch-api-unofficial-docs/api/
https://scratchdb.lefty.one/
Help Needed!
- More getFromApi functions in different languages
- More scratch api sources needed (Don't list any from what I have in the sources section above)
- API Urls
- Any Ideas?
Last edited by Paddle2See (Oct. 26, 2020 09:13:42)
- --Explosion--
- Scratcher
1000+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
Wow! Thanks SO much for making this!
- Pufferfish_Test
- Scratcher
500+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.
^^^ untested but should work
function getFromAPI(api) { fetch(api,).then {res => res.text;}.then {return JSON.parse(data);}.catch (err) {console.log(err);} } // Example console.log(getFromAPI("https://api.scratch.mit.edu/health"))
This is my signature, and appears below eeevvvveeerrrryyy post I write
Try out Ocular
Good evening. I am a gerbil. Are you a gerbil? I know I am. Gerbils are possibly the most important beings in the universe; they are super intelligent and they eat carrots so we don't have to.
If you are reading this, you're probably thinking one of 3 things:
- This dude's not a gerbil, he's a pufferfish/human/bison/whatever other organism/inanimate object you mistakenly believe I am.
- Why am I reading this????????
- I'm hungry
The second one is a valid question, and one that has no satisfactory answer other than that you're really ,really, really bored.
As for the 3rd one - so am I. You're not alone.
- TheColaber
- Scratcher
500+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
I'm getting an error on that… You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.^^^ untested but should workfunction getFromAPI(api) { fetch(api,).then {res => res.text;}.then {return JSON.parse(data);}.catch (err) {console.log(err);} } // Example console.log(getFromAPI("https://api.scratch.mit.edu/health"))
Uncaught SyntaxError: Unexpected token ‘{’It shows that the problem is here: fetch(api,).then {res => res.text;}
I've tried to fix it but I just kept getting more errors… can you test it out?
Last edited by TheColaber (Sept. 16, 2020 13:09:11)
- A-E-
- Scratcher
100+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
UseI'm getting an error on that… You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.^^^ untested but should workfunction getFromAPI(api) { fetch(api,).then {res => res.text;}.then {return JSON.parse(data);}.catch (err) {console.log(err);} } // Example console.log(getFromAPI("https://api.scratch.mit.edu/health"))Uncaught SyntaxError: Unexpected token ‘{’It shows that the problem is here: fetch(api,).then {res => res.text;}
I've tried to fix it but I just kept getting more errors… can you test it out?
async function getFromAPI(api) { return await (await fetch("https://cors-anywhere.herokuapp.com/" + api)).json() } getFromAPI("https://api.scratch.mit.edu/health").then(function(data) { console.log(data) })
- TheColaber
- Scratcher
500+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
Awesome! Is there anyway to make it simply return the data instead of having to use the then method?UseI'm getting an error on that… You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.^^^ untested but should workfunction getFromAPI(api) { fetch(api,).then {res => res.text;}.then {return JSON.parse(data);}.catch (err) {console.log(err);} } // Example console.log(getFromAPI("https://api.scratch.mit.edu/health"))Uncaught SyntaxError: Unexpected token ‘{’It shows that the problem is here: fetch(api,).then {res => res.text;}
I've tried to fix it but I just kept getting more errors… can you test it out?async function getFromAPI(api) { return await (await fetch("https://cors-anywhere.herokuapp.com/" + api)).json() } getFromAPI("https://api.scratch.mit.edu/health").then(function(data) { console.log(data) })
- Jeffalo
- Scratcher
1000+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch probably has it.Awesome! Is there anyway to make it simply return the data instead of having to use the then method?UseI'm getting an error on that… You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.^^^ untested but should workfunction getFromAPI(api) { fetch(api,).then {res => res.text;}.then {return JSON.parse(data);}.catch (err) {console.log(err);} } // Example console.log(getFromAPI("https://api.scratch.mit.edu/health"))Uncaught SyntaxError: Unexpected token ‘{’It shows that the problem is here: fetch(api,).then {res => res.text;}
I've tried to fix it but I just kept getting more errors… can you test it out?async function getFromAPI(api) { return await (await fetch("https://cors-anywhere.herokuapp.com/" + api)).json() } getFromAPI("https://api.scratch.mit.edu/health").then(function(data) { console.log(data) })
anyways, nice guide!
disclaimer: sometimes my posts are pretty critical of the scratch team (especially my older ones), but i really do scratch & scratch team. jvvg made a short essay thing about the scratch team, which is a pretty good read, if you want a different perspective for the scratch team's actions.
- Sheep_maker
- Scratcher
1000+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
.then and .catch are methods that take functions; they aren't special blocks in JS (also, you need to return the Promise, and .then or await it; Response.text is a method, not a property) You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.^^^ untested but should workfunction getFromAPI(api) { fetch(api,).then {res => res.text;}.then {return JSON.parse(data);}.catch (err) {console.log(err);} } // Example console.log(getFromAPI("https://api.scratch.mit.edu/health"))
function getFromAPI(api) { return fetch(api,).then(res => res.text()).then(data => {return JSON.parse(data);}).catch((err) => {console.log(err);}); } // Example getFromAPI("https://api.scratch.mit.edu/health").then(data => {console.log(data);});
- Sheep_maker This is a kumquat-free signature. :P
This is my signature. It appears below all my posts. Discuss it on my profile, not the forums. Here's how to make your own.
.postsignature { overflow: auto; } .scratchblocks { overflow-x: auto; overflow-y: hidden; }
- A-E-
- Scratcher
100+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
yes, you can Is there anyway to make it so simple, that you can just:I want it so the function can return the data… IDK if that's possible though…console.log(getFromAPI("https://api.scratch.mit.edu/health"))
async function getFromAPI(api) { return await (await fetch("https://cors-anywhere.herokuapp.com/" + api)).json() } (async()=>{ console.log(await getFromAPI("https://api.scratch.mit.edu/health")) })();
- 95045290
- Scratcher
70 posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
https://cors-anywhere.herokuapp.com/ shouldn't be used anymore.
Hi, This is a place where a signature goes.
function goDown(){ highlightSignature(0, "auto"); //highlight some part of signature var keys = ["cotrol", "shift", "downArrow"]; pressKeys(keys); }
when [year v] changes::hat events
if<(current [year v])=[2020]> then {
set [my virus v] to (create [virus v] shape:[round and spiky v] name:[corona virus v]::#7c0)
spread (my virus) using [people v]::#7c0
}else if<(current [year v])=(2021)> then{
remove (my virus) from [people v]::#7c0
}::control
- A list
List item
You didn't need to scroll all the way down here.
- RedGuy7
- Scratcher
1000+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
why
https://cors-anywhere.herokuapp.com/ shouldn't be used anymore.
- Pufferfish_Test
- Scratcher
500+ posts
Scratch 3.0 API Dictionary (WIP - HELP NEEDED)
See whyhttps://github.com/Rob–W/cors-anywhere/issues/301https://cors-anywhere.herokuapp.com/ shouldn't be used anymore.
The demo server of CORS Anywhere (cors-anywhere.herokuapp.com) is meant to be a demo of this project. But abuse has become so common that the platform where the demo is hosted (Heroku) has asked me to shut down the server, despite efforts to counter the abuse (rate limits in #45 and #164, and blocking other forms of requests). Downtime becomes increasingly frequent (e.g. recently #300, #299, #295, #294, #287) due to abuse and its popularity.
To counter this, I will make the following changes:
The rate limit will decrease from 200 (#164) per hour to 50 per hour.
By January 31st, 2021, cors-anywhere.herokuapp.com will stop serving as an open proxy.
From February 1st. 2021, cors-anywhere.herokuapp.com will only serve requests after the visitor has completed a challenge: The user (developer) must visit a page at cors-anywhere.herokuapp.com to temporarily unlock the demo for their browser. This allows developers to try out the functionality, to help with deciding on self-hosting or looking for alternatives.
What should current users of CORS Anywhere do in response to this announcement?
If possible, try to avoid the need for a proxy at all. CORS Anywhere works by combining proxy functionality with CORS. You may not need proxy functionality, if the web service that you are trying to access already supports CORS. This is the preferred solution because it is faster and more reliable. For development, you can also consider the use of browser extensions that automatically enables CORS for certain websites.
If your use of CORS Anywhere is infrequent, then the exception from step 3 above will allow you to continue as before. The only difference is that you need to explicitly opt in before access is temporarily allowed. If you'd like to not have these restrictions, then you should self-host CORS Anywhere.
For an example of self-hosting, see https://github.com/Rob–W/cors-anywhere#demo-server . There are also many questions and answers about hosting on the issue tracker here (https://github.com/Rob–W/cors-anywhere/issues). If you have questions, please search for existing issues first before opening a new issue.
This is my signature, and appears below eeevvvveeerrrryyy post I write
Try out Ocular
Good evening. I am a gerbil. Are you a gerbil? I know I am. Gerbils are possibly the most important beings in the universe; they are super intelligent and they eat carrots so we don't have to.
If you are reading this, you're probably thinking one of 3 things:
- This dude's not a gerbil, he's a pufferfish/human/bison/whatever other organism/inanimate object you mistakenly believe I am.
- Why am I reading this????????
- I'm hungry
The second one is a valid question, and one that has no satisfactory answer other than that you're really ,really, really bored.
As for the 3rd one - so am I. You're not alone.
- Discussion Forums
- » Advanced Topics
- » Scratch 3.0 API Dictionary (WIP - HELP NEEDED)