Hello all,
I try to start a process instance leveraging rest api. My need is to make a post request from my js code. For example, when a button is clicked in my website, I want in the backend to start a new process instance. My problem is that I can start a new instance with POSTMAN but when I try it with my simple js code I get an error in my console:“CORS policy - No ‘Access-Control-Allow-Origin’ header is present on the requested resource”. Any ideas about how I can fix it?
Thank you in advance.
elem.addEventListener("click",createInstance,false);
const endpoint="http://localhost:8080/engine-rest/process-definition/key/TEST3/start";
var data={
"variables": {
"aVariable" : {
"value" : "aStringValue",
"type": "String"
},
"anotherVariable" : {
"value" : true,
"type": "Boolean"
}
},
"businessKey" : "myBusinessKey"
};
var js=JSON.stringify(data);
function createJoke(){
fetch(endpoint,{
method:"POST",
body:js,
headers:{
"Content-type":"application/json"
}
})
.then(response=>{
if(response.ok){
return response.json();
}else{
throw new Error("Could not reach the website's endpoint");
}
})
.then(json=>{
console.log(json);
})
.catch(err=> console.error(err));
}