Hello everyone,
I’m testing the REST API on a public project and I have run into some issues when trying to PUT an existing asset. Following the documentation Assets - Update asset in the User Manual and the example given in this forum post, I have created this request code:
//Headers definition: Authorization token is needed to use the Playcanvas API
let myHeaders = new Headers({
"Authorization": `Bearer ${this.apiToken}`
});
var data_to_save = { "testValue" : "nothing" };
let jsonBlob = new Blob([JSON.stringify(data_to_save)], { type: 'application/json' });
//Write data on JSON Back Up
let formData = new FormData();
formData.append("branchId", this.branchID);
formData.append("file", jsonBlob, {
filename: "SecurityBackup.json",
contentType: "application/json"
});
let myReq = new Request(`https://playcanvas.com/api/assets/${this.jsonDataID}`);
await fetch(myReq, {
headers: myHeaders,
method: 'PUT',
body: formData
}).then(function(response){
console.log(response);
});
But it throws a forbidden 403 error despite being a public project, I guess it has to do with the format of the request.
I would appreciate any help.