Skip to content Skip to sidebar Skip to footer

How Do You Check If A Scratch Project Is Shared By Its Id?

I don't expect many people to know this, but is there a way to check if a Scratch project ID is of a project that is shared? For instance, the project ID 3 is an actual project, bu

Solution 1:

I searched the wiki article about the Scratch API, but that didn't help. The only useful endpoint mentioned there would require you to know the owner of the project.

By experimenting, I found these end points to work.

The first one returns HTTP 404 (not found), the second one HTTP 200 (OK) plus details about the project.

Notes:

  • I don't think there is a way to tell the difference between a non-shared project and a nonexistent project; they both yield 404.
  • I don't think you can directly access these endpoints from JavaScript running in a web browser, due to same-origin policy. On your own browser, you could temporarily turn that off. For a more structural solution, use a CORS proxy.

Below is a JavaScript sample that tests a single project ID for existence. It uses yacdn.org, one of the many free CORS proxies.

This is just a proof of concept. I cannot guarantee it will work for mass querying; many free proxies will throttle your traffic. It's probably better to host your own proxy.

functionTestProjectId() {
    const id = document.getElementById('projectId').value;
    const url = 'https://yacdn.org/proxy/https://api.scratch.mit.edu/projects/' + id;
    fetch(url, {method: 'HEAD'})
        .then(response => { document.getElementById('answer').innerHTML = response.ok; });
}
<inputtype="text"id="projectId"value="399293697" /><buttononclick="TestProjectId()">Test it!</button><divid="answer">(answer will appear here)</div>

Post a Comment for "How Do You Check If A Scratch Project Is Shared By Its Id?"