Package Download

Hey, I wondered if there was a method to download a projects zip file via a web-request. I would like to automate the deployment of my package to a web-server. My project is private, so it would need a key to be sent via a secure request.

Ideally I could make some kind of request such as (pseudo code):

http.setHeaders(<credentials>);
http.sendRequest("https://playcanvas.com/projects/<username>/<project>/").then((response) => {
    if (response.success) {
        <response.body> contains zip file
    }
});

I guess this is not an already available function, is there some recommendation of how achieve something similar or how others are approaching this?

Thanks for any info!

You can use our REST API. Check out details here

http://developer.playcanvas.com/en/user-manual/api/

and here

http://developer.playcanvas.com/en/user-manual/api/download-app/

Great thanks, somehow I totally couldn’t find that page :slight_smile:

It looks like only the organisation owner can create an access token, I don’t suppose there are plans to make that available to project admins also (within an organisation) with the token specific to the project?

Only the Organization owner or an Organization administrator can generate tokens. Project admins are not necessarily related to the Organization account itself so there are no plans to do something like that. You could ask the owner of the organization to generate a token for you or make you an administrator of the organization.

Yes, sure, I will ask the organisation owner, it just means I have a third-party to wait on (especially as some* organisation owners don’t really know what an access token is ;)). Not a huge issue just an extra step. It would be nice for admins to be able to create project-specific access tokens, not organisation wide ones. But I guess you are validating the organisation on the request, so it wouldn’t be a trivial change. I have a request in with our owner though.

Thanks again.

*This is a generalisation and in no means is intended to imply all organisation owners or even my own!

I have this working now thanks, for reference I’ve created a github repository that contains a gulp file (for use with Nodejs https://nodejs.org/ and Gulp http://gulpjs.com) with a basic implementation downloading the packaged zip file from PlayCanvas using the REST API. I’ve basically just brain dumped the code, so it’s a little raw right now and will be improved over time (certainly error management can be improved). But, I’ve made it available should anyone find it useful.

Thanks again

1 Like

Nice one.

Btw, you could do here: https://github.com/nfactorial/playcanvas-download/blob/master/gulpfile.js#L146-L157

const file = fs.createWriteStream('./' + CREDENTIALS.packageName);
file.on('finish', cb);
var request = https.request(options, (response) => {
    response.pipe(file);
});

Ahh yes, I did try and pipe it but it didn’t seem to work. After I changed to the current format, I found out the download was getting an XML error from s3 due to including the authorization header. I forgot to switch back to pipe after I fixed it. Thanks! I’ll update the code.

1 Like