Discuss Scratch

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:
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)
})
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:
https://api.scratch.mit.edu
Going 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=trending
MODE 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!

Last edited by kaj (Tomorrow 00:00:00)
✰✩✭✴★--Explosion--★✴✭✩✰
Forum helper | boy | platformers | 14yrs | guitar | website


TheColaber
Scratcher
500+ posts

Scratch 3.0 API Dictionary (WIP - HELP NEEDED)

--Explosion-- wrote:

Wow! Thanks SO much for making this!
It's incomplete now. You have any question and or how to do something?

Pufferfish_Test
Scratcher
500+ posts

Scratch 3.0 API Dictionary (WIP - HELP NEEDED)

You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.
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"))
^^^ untested but should work

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:
  1. This dude's not a gerbil, he's a pufferfish/human/bison/whatever other organism/inanimate object you mistakenly believe I am.
  2. Why am I reading this????????
  3. I'm hungry
The first one is INCORRECT, and I'm going to have to ask you not to spread that false rumour.
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)

Pufferfish_Test wrote:

You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.
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"))
^^^ untested but should work
I'm getting an error on that…
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)

TheColaber wrote:

Pufferfish_Test wrote:

You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.
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"))
^^^ untested but should work
I'm getting an error on that…
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?
Use
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)

A-E- wrote:

TheColaber wrote:

Pufferfish_Test wrote:

You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.
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"))
^^^ untested but should work
I'm getting an error on that…
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?
Use
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)
})
Awesome! Is there anyway to make it simply return the data instead of having to use the then method?

Jeffalo
Scratcher
1000+ posts

Scratch 3.0 API Dictionary (WIP - HELP NEEDED)

TheColaber wrote:

A-E- wrote:

TheColaber wrote:

Pufferfish_Test wrote:

You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.
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"))
^^^ untested but should work
I'm getting an error on that…
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?
Use
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)
})
Awesome! Is there anyway to make it simply return the data instead of having to use the then method?
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch probably has it.

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.

my website: jeffalo.net | ocular: scratch forum search













Sheep_maker
Scratcher
1000+ posts

Scratch 3.0 API Dictionary (WIP - HELP NEEDED)

Pufferfish_Test wrote:

You should use fetch rather than xmlHttpRequest - xmlHttpRequest is now outdated.
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"))
^^^ untested but should work
.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)
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; }
TheColaber
Scratcher
500+ posts

Scratch 3.0 API Dictionary (WIP - HELP NEEDED)

Is there anyway to make it so simple, that you can just:
console.log(getFromAPI("https://api.scratch.mit.edu/health"))
I want it so the function can return the data… IDK if that's possible though…

A-E-
Scratcher
100+ posts

Scratch 3.0 API Dictionary (WIP - HELP NEEDED)

TheColaber wrote:

Is there anyway to make it so simple, that you can just:
console.log(getFromAPI("https://api.scratch.mit.edu/health"))
I want it so the function can return the data… IDK if that's possible though…
yes, you can
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

95045290 wrote:

https://cors-anywhere.herokuapp.com/ shouldn't be used anymore.

see me here where I make nono word and other junk

Please set a status at Ocular by clicking the below image, to make @Jeffalo happy! #OcularStatusesTo1k

left scratch



































































































































































found me!
Pufferfish_Test
Scratcher
500+ posts

Scratch 3.0 API Dictionary (WIP - HELP NEEDED)

RedGuy7 wrote:

why

95045290 wrote:

https://cors-anywhere.herokuapp.com/ shouldn't be used anymore.
See https://github.com/Rob–W/cors-anywhere/issues/301

that issue wrote:

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:
  1. This dude's not a gerbil, he's a pufferfish/human/bison/whatever other organism/inanimate object you mistakenly believe I am.
  2. Why am I reading this????????
  3. I'm hungry
The first one is INCORRECT, and I'm going to have to ask you not to spread that false rumour.
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.

Powered by DjangoBB