Using the REST api is it possible to update an asset only on a specific branch? The asset is only uploaded on the master branch when we try.
I use a POST request to upload my compiled typescript to a script asset. However if we’re two programmers on the same project we’re constantly overwriting each other.
If we branch out and each programmer only updates their script on their own branch we could get around this, but I can’t get it to work. The script asset is always updated on the master branch. I’ve tried adding ?branchId=… or add branchId to a form. My code looks like:
var filePath = 'build_settings.json';
fs.writeFileSync(filePath, JSON.stringify(settings));
//Upload new data
var updateBuildSettings = request({
uri: 'https://playcanvas.com/api/assets',///' + configuration.buildSettingsAssetId + "?branchId=e9150c63-9a1f-4c33-b95d-10647ed855e1",
method: 'POST',
headers: {
"Authorization": `Bearer ${configuration.bearer}`
},
});
let form = updateBuildSettings.form();
form.append("project", "" + configuration.projectId)
form.append("name", "" + filePath);
form.append("preload", "true");
form.append("type", "json");
form.append("asset", "" + configuration.assetId);
form.append("branchId", "e9150c63-9a1f-4c33-b95d-10647ed855e1");
form.append("file", JSON.stringify(settings), {
filename: filePath,
contentType: "application/json"
});
Or appending it to the URL instead:
var updateBuildSettings = request({
uri: 'https://playcanvas.com/api/assets/' + configuration.buildSettingsAssetId + "?branchId=e9150c63-9a1f-4c33-b95d-10647ed855e1",
method: 'POST',
headers: {
"Authorization": `Bearer ${configuration.bearer}`
},
});
let form = updateBuildSettings.form();
form.append("project", "" + configuration.projectId)
form.append("name", "" + filePath);
form.append("preload", "true");
form.append("type", "json");
form.append("asset", "" + configuration.assetId);
//form.append("branchId", "e9150c63-9a1f-4c33-b95d-10647ed855e1");
form.append("file", JSON.stringify(settings), {
filename: filePath,
contentType: "application/json"
});
The code above is for a JSON file but I get same results with a script asset.
We’ll probably do a workaround and use different assets on different branches, but that’s a bit of a hassle when we need to merge.