I can use Rest Api to create deployment by xmlString?

hi guys:
i want to update process definition in web.
now i can get xml string, but i don’t know I can use rest api(POST /deployment/create) create a next version process definition?
Or I must be use Java API??

Camunda engine creates new version automaticlly if new model differs from old model.
Ordinary you can manually delete old model and deploy new model through modeller or some script.

Here is java script to attach new uploaded model file for deploying:

  const ProcessKey = req.params.key;   // get ProcessModel from key + attached file from param upload

  var filepath = '';
  var filename = '';
  var newpath = '';
  var form = new formidable.IncomingForm();
  form.keepExtensions = true;     //keep file extension

  form.parse(req, function(err, fields, files) {
    filepath = files.upload.path;
    filename = files.upload.name;
    newpath = '/tmp/' + filename;
    fs.renameSync(filepath, newpath);

    // emulate protocol of camunda modeller to keep old version if no changes in model
    const formData = new FormData();
    formData.append("upload", fs.createReadStream(newpath), filename);
    formData.append("deployment-name", filename.split('.')[0]);
    formData.append("deploy-changed-only", "true");
    formData.append("deployment-source", "Camunda Modeler");

    axios.post(Camundaurl + '/deployment/create', formData, { headers: formData.getHeaders(), httpAgent: httpagent, httpsAgent: httpsagent, timeout: 20000, auth: authCamunda })
    .then(response => {
      const result = response.data;

      fs.unlinkSync(newpath);
      res.status(200).end(JSON.stringify({result: result}));
    })

bash script to upload models

for filename in container/*.bpmn; do
   model=$(cat $filename |grep '  <bpmn:process id="' | cut -d'"' -f 2)
   upload='upload=@"./'$filename'"'
   curl -k -H "Content-Type: multipart/form-data" -X POST -F $upload \
      https://localhost:$GATE_PORT/api/$engine/deployment/$model/create $auth
done
1 Like

thanks
I think maybe my headers setting is wrong
it’s my code it can work and no need to set headers

uploadProcess(){
const _this = this
let fileStringArray = [_this.xmlData]
let fileName = ‘text.bpmn’
let blobAttrs = {type:‘xml’}
let file = new File(fileStringArray, fileName, blobAttrs)
let formData = new FormData()
formData.append(“upload”, file, file.name);
this.AXIOS
.post(‘http://localhost:8083/engine-rest/deployment/create’,
formData)
.then(function(response){
console.log(‘success’,response.data)
})
.catch(function(err){
console.log(‘err’,err)
})
},