[HTTP-POST] How to send data to the BDM using (Web-)REST-API?

Hello there dear Bonita-Community

My question regarding the implementation is whether it is possible to update a form, without explicitly fill out
the particular form. As described in the documentation, it is possible to access the Business Process
Model (bpm) and the Business Data Model (bdm) with the (Web-)REST-API. But i don’t get how to update the specifically defined “attributes” in the bdm.

Is this possible?

Let me give you an example. I will take the process example “Simple Travel Request”. When you import the process and run it out of Bonita BPM (v7.3.3), you’ll see the “Submit Travel Request”-Report, which a user has to fill out.

Now, what I want, is to fill out the the “Submit Travel Request”-Form/Report in an external web application.
I want to use the REST-API and specifically the PUT/POST-Methods to update (or deliver data) to the defined
business data model attributes (or business process model).

So far I can get the information with a simple GET-Request, after a user filled out the original bonita-formular and submitted the data. But I don’t get it done, that I can send a POST/PUT-Methode as a first step.

Do you have any ideas how to tackle the described problem? Is it even possible?

Thank you very much and with best regards,
Steven Ba

Hi,

Currently it’s not possible, the BDM only can be modified via Engine API and Process. If you want to do this via REST API you have to make a REST API Extension that handles the data for storing, updating or deleting.

With the process data it is possible, you have to use the caseVariable or activityVariable API for update the values. (See more here: http://documentation.bonitasoft.com/?page=bpm-api#toc15)

I hope it helps.

Bye.

You Need to do following steps:

  1. Login to rest api
    http://localhost:8080/bonita/loginservice

pass following data in body as x-www-form-unlencoded
User Name: xxxx
password: xxxx
redirect: false

  1. Following api will give you process id
    http://localhost:8080/bonita/API/bpm/process?p=0&c=10

“id”: “8770717603204425918”,
“displayDescription”: “”,
“deploymentDate”: “2016-11-22 08:55:14.541”,

  1. Use this api to instantiate the process, user the process id from above api
    http://localhost:8080/bonita/API/bpm/process/8770717603204425918/instantiation

pass json data on body
{
“yourDataObject” : {
“OwnerDetails” : {
“FirstName” : “Test”,
“LastName” : “Test”,
“DOB” : null
}
}

Hey,

thanks for your input!

Ok, the Business Process Model would have been my next guess.
I tried to figure out where and how these variables (caseVariable, activityVariable) are located and saved, but i have not found anything yet.

If it is not too much asked: can you explain where I can find them (like are these the business variables within the pool variables or are those the “process instantiation inputs”?) ?

Last but not least (I don’t want to look too greedy): Basically it is possible to make an external website, where a user has to fill out a form, send these input-datas via REST-API to Bonita BPM as a case- or activityVariable and then process it further with Bonita?

Really, really appreciate your input. Thank very much!

Hi,

For explaining simple, you have to follow these steps:

  1. Design a BDM for storing your data
  2. Make in Bonita a process that handles the data submited by the user throught the external app. Define the form instantiation contract with the inputs that will be submited by the user. Contract values must be mapped with the BDM you defined.
  3. Make your external app and build it for it can send to the Bonita Server a JSON with the same structure as the contract.
  4. Test it :wink:

With that steps you are not storing with the REST API directly, we made a process that handles the data.

Bye.

once again: thank you.

If I understand you correctly, I already have done these steps. In the above mentioned tutorial (simple travel request) I created a bdm (com.company.model.TravelRequest) and added the attributes to variables.
After that I tried to update the variables like the documentation described it:
/API/bdm/businessData/:businessDataType/:persistenceId/:attributeName

All I got is: localhost:8080/bonita/API/bdm/businessData/com.company.model.TravelRequest/2/numberOfNights [HTTP/1.1 403 Forbidden 0ms]

Oke, I tried the last hours to do what you mentioned.

Actually I don’t know what I am missing here. I filled out the form as a bonita process and the data is visible in the portal, so these simple get-requests should work.

If this case is not going to work, would it be an alternative to firstly send the formular-data to a database and Bonita BPM will get it from the database to process it?

For the purpose of clarification: I don’t want to add/deploy an (external) application within the bonita portal.
It is really an external website.


Contract input:
def travelRequestVar = new com.company.model.TravelRequest()
travelRequestVar.userId = travelRequestInput.userId.toLong()
travelRequestVar.departureDate = travelRequestInput.departureDate
travelRequestVar.numberOfNights = travelRequestInput.numberOfNights
travelRequestVar.hotelNeeded = travelRequestInput.hotelNeeded
travelRequestVar.destination = travelRequestInput.destination
travelRequestVar.reason = travelRequestInput.reason
travelRequestVar.status = travelRequestInput.status
travelRequestVar.refusalReason = travelRequestInput.refusalReason
return travelRequestVar


UI Designer, formInput JSON-definition:
{
“travelRequestInput” : {
“departureDate” : null,
“numberOfNights” : null,
“hotelNeeded” : false,
“destination” : “”,
“reason” : “”
}
}

THANK YOU.

Hi,

Well, if you got a 403 maybe you are not logged in for doing REST queries, try first: http://localhost:8080/bonita/loginservice?username=yourUser&password=yourPassword

And, the BDM variables cannot be accesible from the caseVariable API, you have to use something as the first url that you tried.

Bye, I hope it helps.

For clarification, this url http://localhost:8080/bonita/loginservice?username=yourUser&password=yourPassword always returns 200, it does not matter if you can or cannot login (the response is the Bonita Login page or the Bonita Portal main page).

You’ll know if you cannot login when you can find this text on your response: “Unable to log in. Please check your username and password.”, it’s a little tricky but it works ;).

Bye.

hey.

Thank you.

The login worked fine for me. I am using the ngBonita-Library with a bonitaAuthentication-method.

Hi kiran,

first of all: thank you very much for your time and help.

Your advice works - till now - fine for me. It did not cross my mind to use this specific ID.
Regarding this id, how is this generated? Do I always have to request this (http://localhost:8080/bonita/API/bpm/proces$
api beforehand, readout the specific id and then instantiate the process via http://localhost:8080/bonita/API/bpm/proce$
After the instantiation I’d like to use the userTaskId and update a specific attribute/variable.
I know that it is possible to update the variable and it works, but currently I have to do this manual.
Is there an option to read out the userTaskId and update it with a payload?
Do you have any idea regarding this?

Anyway: thank you very much, this helped me a lot!

best regards,
steve

Hi Steve,

The New Process ID will be generated whenever you deploy the new version of process to the portal.

It is also possible to update a task but I have not done it. This page will explain you how to do it.

http://documentation.bonitasoft.com/?page=bpm-api