Switching branches via nodejs

Hey hey :slight_smile:

I’m currently looking into nodejs and calling various api’s from those. I wanted to see if I can switch branches this way. It kinda works like this:

let accessToken = "XXXXXXXXXXXXXXXX";
let req = request({
  uri: `https://playcanvas.com/api/branches/${branchId}/checkout`,
  method: 'POST',
  headers: {
    "Authorization": `Bearer ${accessToken}`,
req.then((resp) => {
  console.log(`Switching to PC branch: ${branchId}`);
}, (error) => {
  console.log(`Error: ${error.statusCode}`);
  console.log(`       ${error.error}`);

Note that the accessToken is the one I get when I open the inspector and type in config.accessToken. It changes at least everytime I log out, likely even more often. If I replace it with an API Token created on my account, I get an error 403 “Unauthorized”.

So I’m wondering why I can’t use my api token for this request, or if there is a way to get the current accessToken. I don’t want to update my accessToken manually everyday :wink:


@yaustar can you maybe help me with this, is this something that is possible? Or am I on a wrong track here, trying to use the built-in VCS remotely?

@vaios might be able to help

Vaios will be able to explain more about whether this is possible. As the endpoints are considered non-public, the use case with the Editor may be more specific.

What’s the use case of using VCS remotely? There may be another way to get the same result.

I’m exploring the idea of writing a script to work with both Git and the built-in VCS of Playcanvas simultaneously, like creating and switching branches, creating checkpoints/pushing commits, merging branches, etc. via node.

I’m setting our project up based on whydoidoit’s webpack plugin and trying to build on it.

Just spoke with Vaios, those REST endpoints aren’t public API so that’s pretty much why the API Token doesn’t work with it.

We do have a request to expose the API for public use here: https://github.com/playcanvas/editor/issues/498

But hasn’t been looked at yet.

Yeah, those endpoints would be a big help. Do you have any idea or rough estimate if and when someone is gonna take a look at this? Or should I put this work on hold for now?

I would have it on hold unfortunately unless you are okay using the access token. Having the endpoints public is not something that has been discussed yet beyond having the ticket.

Got it. Using the accessToken is not viable, since I have not found a way to properly get it except manually opening the inspector and copying the config.accessToken. So I will have another go at this once more of the API is public.

Thanks anyway for your help :wink: