Getting started
Install
s-api4js needs Node 18 or newer (it uses the built-in global fetch). Its only
runtime dependency is tough-cookie.
To edit projects you'll usually also want scratch4js:
Your first call (no login)
Everything hangs off a ScratchSession. Construct one and read public data right
away:
The session groups the API into four resources — users, projects, studios
and search — plus the site-level helpers health(), news() and featured().
See Public data for the full list.
Logging in
ScratchSession.login performs the CSRF + session handshake and returns a
ready, authenticated session:
Once logged in, the project-editing methods unlock — download, save,
share, setTitle, and so on. See Authentication
and Editing projects.
Read them from the environment (or a secrets manager), never hard-code them:
Handling errors
Any non-2xx response throws a ScratchAPIError carrying the status, url,
method and parsed body:
Next steps
- Public data — the read-only endpoints.
- Editing projects — download → edit → save → publish.
- Reference — every method and the endpoints it hits.