scratch-api-unofficial-docs icon indicating copy to clipboard operation
scratch-api-unofficial-docs copied to clipboard

Add studio (view/modify) API

Open towerofnix opened this issue 6 years ago • 6 comments

See LLK/scratch-www#1985. This is probably a big one!

  • [x] (GET) /projects/<id>/studios
  • [x] (GET) /users/<username>/studios/curate
  • [ ] (POST) /studios/<id>/project/<id> (add to studio; requires auth)
  • [ ] (DELETE) /studios/<id>/project/<id> (remove from studio; requires auth)

towerofnix avatar Jul 21 '18 02:07 towerofnix

By the way, it's not <id> for some of these, but instead <username>.

My theory was that endpoints that are sent an authentication token will return extra data for the Scratch Team. I find this not as likely anymore, though -- so it might be that the implementation in the linked issue is wrong. (Or a bug in the API!). Either way, devs might want to know.

joker314 avatar Jul 26 '18 09:07 joker314

My guess is that you need authentication to join a studio, but not to view your (or anyone's) studio list. So either the PR writer (@benjiwheeler, pinging you) or internal documentation for scratch-api made a mistake and thought authentication was needed either way.

Anyways, it makes sense that you can view a list of which studios a user is curating without being authenticated; that's one of the rows on any profile page ("Studios I Curate").

towerofnix avatar Jul 26 '18 11:07 towerofnix

There exists a risk that ST employees are instructed not to interact with repositories of others (especially of kids), it might be a good idea to track this in the pull request rather than here -- especially since all the ST devs will be watching?

joker314 avatar Jul 26 '18 15:07 joker314

Oh, good point. I just didn't want to look like I was intruding on the discussion of a PR I'm unrelated to.

towerofnix avatar Jul 26 '18 18:07 towerofnix

@joker314 Update - see https://github.com/LLK/scratch-www/pull/1985/commits/a60da11f8ae2069dd36e4d42e0001cbd93af78b7 - indeed, that was just a mistake in the PR code. Getting the curated studios list doesn't require auth.

towerofnix avatar Jul 26 '18 23:07 towerofnix

Latter two endpoints won't work until preview page is out. Test code:

async function go() {
  const projectID = 248475643
  const studioID = 5542140

  const token = await fetch('/session', {headers: {'X-Requested-With': 'XMLHttpRequest'}}).then(res => res.json()).then(data => data.user.token)

  const res = await fetch(`https://api.scratch.mit.edu/studios/${studioID}/${projectID}?x-token=${token}`, {method: 'POST'})

  console.log(res)
}
go().catch(err => console.error(err))

towerofnix avatar Oct 10 '18 20:10 towerofnix