dave
September 21, 2016, 9:53am
1
Today we’re launching the first version of the PlayCanvas REST API.
The REST API is available to all Organization account holders and allows developers to automate processes to help them with their development. For example, you can use the API to create a daily build of your application and download it via a build server. In the future we’ll be expanding the API with additional features like access to assets and more.
You can read more about the API in the documentation .
Let us know below with your thoughts on how you’re using the API and what features you’d like to see in the future.
2 Likes
Hello,
my name is Filip from Productmadness London,
I am trying to automate our deployments to production via the API,
I hit a brick wall when trying to get the job status. However i am able to trigger the process and get the job id like :
{ status: 'running',
messages: [],
created_at: '2018-09-07T16:04:49.517000',
modified_at: '2018-09-07T16:04:49.517000',
data:
{ concatenate: true,
branch_id: '4d735ab2-22f2-47bf-aa6c-8decc8989200',
target: 'web',
owner_id: 99654,
scenes: [ 'AAA' ],
project_id: BBB,
name: 'PROJECT_NAME' },
id: ID_INT }
but then :
var options = {
method: "GET",
url: ' https://playcanvas.com/api/jobs/:' + job_id,
headers: {
Authorization: 'Bearer ' + "cleared"
},
body: {
id: job_id
},
json: true
};
this gives me internal server error 500
any help is appreciated
yaustar
September 12, 2018, 5:05pm
3
I believe you are missing the content type in the headers. Below is the script I use to automate builds:
import sys
import requests
import time
import subprocess
import os
import shutil
import zipfile
import io
import re
FNULL = open(os.devnull, 'w')
build_path = '../build'
export_url = 'https://playcanvas.com/api/apps/download'
job_url_template = 'https://playcanvas.com/api/jobs/{}'
headers = {
'Authorization':'Bearer 9384529034892fsdn',
'Content-Type':'application/json'
}
data = '{"project_id":543988, "name":"Top Down Shooter Experiment", "scripts_concatenate":true, "scenes":[598304] }'
job_poll_interval_secs = 1
job_id = -1
download_url = ''
# Request the download of the project
print('Requesting project download job')
r = requests.post(export_url, headers=headers, data=data)
if r.status_code == 201:
json = r.json()
status = json['status']
if status == 'running':
job_id = json['id']
elif status == 'complete':
download_url = json['url']
else:
sys.exit(1)
else:
print('Error: {}'.format(r.status_code))
sys.exit(1)
if len(download_url) == 0:
print('Waiting for job to complete')
# Poll job till its complete
job_url = job_url_template.format(str(job_id))
job_finished = False
while not job_finished:
r = requests.get(job_url, headers=headers)
if r.status_code == 200:
json = r.json()
status = json['status']
if status == 'complete':
download_url = json['data']['download_url']
job_finished = True
elif status == 'running':
print('Still waiting')
time.sleep(job_poll_interval_secs)
else:
sys.exit(1)
else:
sys.exit(1)
# Remove all files from the snapshot directory
print('Clearing snapshot directory')
shutil.rmtree(build_path)
os.mkdir(build_path)
# Download zip from JSON response
print('Download archive from {}'.format(download_url))
r = requests.get(download_url)
z = zipfile.ZipFile(io.BytesIO(r.content))
# Unzip the archive
print('Unzipping archive')
z.extractall(build_path)
dave
September 13, 2018, 12:04am
4
You need to remove the : in job id URL
Use https://playcanvas.com/api/jobs/1234
Not https://playcanvas.com/api/jobs/:1234
1 Like
Thanks it worked, i had type json which was wrong, with id in the body.
Yes it is. I’ve since written some node.js tools that does something similar: https://github.com/playcanvas/playcanvas-rest-api-tools