How to initialize complex business variables via REST API?

Hi,

I have one BDM "ServiceRequest"defined with 4 properties: accountID (String), requestDescription (Text), raisedBy (String) and raisedDate (Date).

In my process, I defined a pool level business variables with name “serviceRequest” which type is above BDM. And also I defined a contract at pool level call “serviceRequestInput”. Of course serviceRequest gets default values from serviceRequestInput.

When I start this process using Instantiation form which is created manually, it works fine, which means serviceRequest will be set with values from serviceRequestInput.

However, when I try to call REST API (POST to “/API/bpm/case”)to start process with below request body, it throws exceptions:
{ "processDefinitionId": "5768318148310067370", "variables": [ { "name": "serviceRequestInput", "value": { "accountID" : "abcd", "requestDescription" : "xyx", "raisedBy" : "abcd" } } ] }

The exceptions are:
2016-02-29 18:18:43.467 +0800 org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet catchAllExceptions 严重: The API "bpm#case" has encountered an unknown error org.bonitasoft.web.toolkit.client.common.exception.api.APIException: The API "bpm#case" has encountered an unknown error at org.bonitasoft.web.rest.server.datastore.bpm.cases.CaseSarter.getDataDefinitionByName(CaseSarter.java:104) at org.bonitasoft.web.rest.server.datastore.bpm.cases.CaseSarter.buildVariablesMap(CaseSarter.java:82) at org.bonitasoft.web.rest.server.datastore.bpm.cases.CaseSarter.getVariables(CaseSarter.java:74) at org.bonitasoft.web.rest.server.datastore.bpm.cases.CaseSarter.start(CaseSarter.java:61) at org.bonitasoft.web.rest.server.datastore.bpm.cases.CaseDatastore.add(CaseDatastore.java:166) at org.bonitasoft.web.rest.server.api.bpm.cases.APICase.add(APICase.java:53) at org.bonitasoft.web.rest.server.api.bpm.cases.APICase.add(APICase.java:44) at org.bonitasoft.web.rest.server.framework.API.runAdd(API.java:156) at org.bonitasoft.web.rest.server.framework.APIServletCall.doPost(APIServletCall.java:213) at org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.doPost(ToolkitHttpServlet.java:188) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.service(ToolkitHttpServlet.java:75) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.service(ToolkitHttpServlet.java:226) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.bonitasoft.console.common.server.login.filter.AbstractAuthorizationFilter.doFilter(AbstractAuthorizationFilter.java:60) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)

May I know what would be right format to call this REST API?

(I am on Bonita 7.1)

Hi,
AFAIK, because you are attempting to start the process with a BDM object, you need to call: http://IP:8080/bonita/API/bpm/process/{ProcessId}/instantiation

The JSON payload should look something like:

`{  
   "ServiceRequestInput":{  
      "accountID" : "abcd",
"requestDescription" : "xyx",
"raisedBy" : "abcd"
   }
}`

hope that helps,
Tom

Which means setting BDM variables only can be done post case has been created?

Because the scope of variables is not specific to “Process Variables” in the document to create a case, it confuse me. I thought Business Variables also can be done in same way until I read the source codes and realize that case create piece of codes only check on Process Variables.

Hi
to star a case with instantiation contract or variables
you should use the api process instantiation not the api create a case

“Start a process using an instantiation contract”
http://documentation.bonitasoft.com/bpm-api-849#process

it is work fine i have used it

best regards
Aymen