Crear caso con api rest


Hola a todos.
quiero crea un caso con la api rest.
Primero me logueo ok con http://localhost:8080/bonita/loginservice y obtengo la cookies

Luego trato de crea el caso con un  POST a la url
http://localhost:8080/bonita/API/bpm/case

usando postman. Me devuelve un status code 401 no autorizado.
Este es el codigo de postman 

var axios = require('axios');
var data = JSON.stringify({
  "processDefinitionId": "7612481195189194033",
  "variables": [
    {
      "name": "prestationContract",
      "value": [
        {
          "name": "montantAvance",
          "value": "150"
        },
        {
          "name": "modePerception",
          "value": "Virement"
        }
      ]
    }
  ]
});

var config = {
  method: 'post',
  url: 'http://localhost:8080/bonita/API/bpm/case',
  headers: { 
    'Content-Type': 'application/json', 
    'Cookie': 'bonita.tenant=1; BOS_Locale=es; JSESSIONID=2B622A17A403683551A58FF87AC47CB3; X-Bonita-API-Token=ccf7c15f-d8ec-4a2c-a0e8-c87e4dd28673'
  },
  data : data
};
¿alguna ayuda disponible ?
 

Hola weglineduardo,

He checado la documentación y había un error en un link que no llevaba al lugar indicado para tu caso. Lo estamos corrigiendo.

Hay que hacer referencia a esta página: https://documentation.bonitasoft.com/bonita/2022.2/api/actors-process-co...

  • Usa POST /API/bpm/process/:processId/instantiation
  • Asegúrate que estos 2 headers son enviados  JSESSIONID y X-Bonita-API-Token 

Lo he intentado con postman y funciona.

¡Espero que esto te ayude!

saludos

Ok, te falta que estos 2 headers sean enviados JSESSIONID y X-Bonita-API-Token, no sólo en la coookie:

headers: {

'Content-Type': 'application/json',

'Cookie': 'bonita.tenant=1; BOS_Locale=es; Cookie_1=value', 

'JSESSIONID':'283B51C193EB8F1FE4C663BDB6C69884',

'X-Bonita-API-Token':'f83758a0-3335-4565-b7c8-b7be746af75d'}

Así me ha funcionado con postman

Podrías intentarlo y decirme si funciona, por favor?

I see it in your headers but if I'm not mistaken they're inside the 'Cookie' header:

headers: {

'Content-Type': 'application/json',

'Cookie': 'bonita.tenant=1; BOS_Locale=es; Cookie_1=value; JSESSIONID=2C0B8720109952A807DCD0F81AC9E7DE; X-Bonita-API-Token=a956dfc5-9147-4d8a-8131-805004164c07'

}

My recommendation is to send them outside of 'Cookie', as 2 separate headers like this:

headers: {

'Content-Type': 'application/json',

'Cookie': 'bonita.tenant=1; BOS_Locale=es; Cookie_1=value',

'JSESSIONID':'2C0B8720109952A807DCD0F81AC9E7DE',

'X-Bonita-API-Token':'a956dfc5-9147-4d8a-8131-805004164c07'

}

On my side this is working with walter.bates profile and postman

Hello. I solved them with your instructions. good job, thanks

Hello.
I worked with your recommendation and it did not work
Install pretty studio 2022.2 because the link you recommended was for that version.
With this I make sure that the installation is clean, without permission errors.

I do this.
1)

I get the process id
get 
http://localhost:63066/bonita/API/bpm/process?c=10&p=0

 {
        "displayDescription": "",
        "deploymentDate": "2022-10-25 19:36:23.335",
        "displayName": "Incidente",
        "name": "Incidente",
        "description": "",
        "deployedBy": "4",
        "id": "5063742355450000882",
        "activationState": "ENABLED",
        "version": "1.0",
        "configurationState": "RESOLVED",
        "last_update_date": "2022-10-25 19:36:23.702",
        "actorinitiatorid": "125"
    }
    
2)I make a post

http://localhost:63066/bonita/API/bpm/process/5063742355450000882/instantiation

{
    "searchIndex5Label": "",
    "searchIndex3Value": "",
    "searchIndex4Value": "",
    "searchIndex2Label": "",
    "searchIndex1Value": "",
    "searchIndex3Label": "",
    "startedBySubstitute": "4",
    "searchIndex5Value": "",
    "searchIndex2Value": "",
    "state": "started",
    "searchIndex1Label": "",
    "started_by": "4",
    "searchIndex4Label": ""
}

401 Unauthorized

and cookies are sent

headers: { 
    'Content-Type': 'application/json', 
    'Cookie': 'bonita.tenant=1; BOS_Locale=es; Cookie_1=value; JSESSIONID=283B51C193EB8F1FE4C663BDB6C69884; X-Bonita-API-Token=f83758a0-3335-4565-b7c8-b7be746af75d'
  },


3) I bring the things created with the bpm and the processDefinitionId is correct.
    
http://localhost:63066/bonita/API/bpm/case/

[
    {
        "end_date": "",
        "searchIndex5Label": "",
        "processDefinitionId": "5063742355450000882",
        "searchIndex3Value": "",
        "searchIndex4Value": "",
        "searchIndex2Label": "",
        "start": "2022-10-25 19:37:08.419",
        "searchIndex1Value": "",
        "searchIndex3Label": "",
        "startedBySubstitute": "4",
        "searchIndex5Value": "",
        "searchIndex2Value": "",
        "rootCaseId": "8",
        "id": "8",
        "state": "started",
        "searchIndex1Label": "",
        "started_by": "4",
        "searchIndex4Label": "",
        "last_update_date": "2022-10-25 19:37:08.419"
    },
    {
        "end_date": "",
        "searchIndex5Label": "",
        "processDefinitionId": "5063742355450000882",
        "searchIndex3Value": "",
        "searchIndex4Value": "",
        "searchIndex2Label": "",
        "start": "2022-10-25 19:53:59.399",
        "searchIndex1Value": "",
        "searchIndex3Label": "",
        "startedBySubstitute": "4",
        "searchIndex5Value": "",
        "searchIndex2Value": "",
        "rootCaseId": "9",
        "id": "9",
        "state": "started",
        "searchIndex1Label": "",
        "started_by": "4",
        "searchIndex4Label": "",
        "last_update_date": "2022-10-25 19:53:59.399"
    }
]

please can you share the custom-permissions-mapping.properties , resources-permissions-mapping-custom.properties and compound-permissions-mapping-custom.properties files of your
installation so I verify the permissions you have?

According to the documentation here https://documentation.bonitasoft.com/bonita/2022.1/identity/rest-api-authorization#static_authorization they are needed to use the rest api

Send to this email please weglineduardo@hotmail.com

Hello. I sent them too. I mentioned those two only because you told me above that I should not forget to send them. Postman sends them. i have this in postman

var axios = require('axios');

var data = JSON.stringify({

  "searchIndex5Label": "",

  "searchIndex3Value": "",

  "searchIndex4Value": "",

  "searchIndex2Label": "",

  "searchIndex1Value": "",

  "searchIndex3Label": "",

  "startedBySubstitute": "4",

  "searchIndex5Value": "",

  "searchIndex2Value": "",

  "state": "started",

  "searchIndex1Label": "",

  "started_by": "4",

  "searchIndex4Label": ""

});

 

var config = {

  method: 'post',

  url: 'http://localhost:63066/bonita/API/bpm/process/5712791836604956850/instantiation',

  headers: { 

    'Content-Type': 'application/json', 

    'Cookie': 'bonita.tenant=1; BOS_Locale=es; Cookie_1=value; JSESSIONID=2C0B8720109952A807DCD0F81AC9E7DE; X-Bonita-API-Token=a956dfc5-9147-4d8a-8131-805004164c07'

  },

  data : data

};

 

axios(config)

.then(function (response) {

  console.log(JSON.stringify(response.data));

})

.catch(function (error) {

  console.log(error);

});

401 Unauthorized

 

It does not work. Just tried again.

do you have any other solution?
Isn't it something like this? >>   https://documentation.bonitasoft.com/bonita/2022.1/identity/rest-api-authorization#static_authorization 

thanks for your help
Cheers

 

Great! I'll mark it as the answer