start a case with REST API

Hi,
I’m trying to start a case with REST API (RestSharp) from an asp Website but I have an exception that I don’t really understand.
This is my code :

req = new RestRequest("loginservice", Method.POST); req.AddParameter("username", tbx_username.Text); req.AddParameter("password", tbx_password.Text); req.AddParameter("redirect", "false"); response = client.Execute(req);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {

                if (response.Cookies.Count == 1)
                {

                    Session["Cookie"] = response.Cookies[0];
                    Session["Role"] = 0;
                    Session["Username"] = tbx_username.Text;
                   

                    //Instanciation d'un workflow
                    object json = new
                    {
                        processDefinitionId = 0
                    };
                    JsonConvert.SerializeObject(json);

                    req = new RestRequest("API/bpm/case/", Method.POST);
                    req.AddCookie(response.Cookies[0].Name, response.Cookies[0].Value);
                    req.AddHeader("Content-Type", "application/json");
                    req.RequestFormat = DataFormat.Json;
                    req.AddBody(json);

}
}

The connexion works perfectly, I get the cookie and give it to the request.
Anyone can help me ?

This is my exception :

{“exception”:“class java.lang.NullPointerException”,“message”:“”,“stacktrace”:[“org.bonitasoft.web.rest.server.datastore.bpm.cases.CaseSarter.(CaseSarter.java:50)”,“org.bonitasoft.web.rest.server.datastore.bpm.cases.CaseDatastore.add(CaseDatastore.java:143)”,“org.bonitasoft.web.rest.server.api.bpm.cases.APICase.add(APICase.java:51)”,“org.bonitasoft.web.rest.server.api.bpm.cases.APICase.add(APICase.java:42)”,“org.bonitasoft.web.rest.server.framework.API.runAdd(API.java:157)”,“org.bonitasoft.web.rest.server.framework.APIServletCall.doPost(APIServletCall.java:188)”,“org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.doPost(ToolkitHttpServlet.java:188)”,“javax.servlet.http.HttpServlet.service(HttpServlet.java:643)”,“org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.service(ToolkitHttpServlet.java:75)”,“javax.servlet.http.HttpServlet.service(HttpServlet.java:723)”,“org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.service(ToolkitHttpServlet.java:226)”,“org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)”,“org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)”,“org.bonitasoft.console.common.server.login.filter.AbstractAuthorizationFilter.doFilter(AbstractAuthorizationFilter.java:60)”,“org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)”,“org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)”,“org.bonitasoft.console.common.server.login.filter.AbstractAuthorizationFilter.doFilter(AbstractAuthorizationFilter.java:60)”,“org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)”,“org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)”,“org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)”,“org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)”,“org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)”,“org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)”,“org.bonitasoft.console.security.SessionFixationValve.invoke(SessionFixationValve.java:77)”,“org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)”,“org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)”,“org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)”,“org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)”,“org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)”,“java.lang.Thread.run(Thread.java:744)”]}

Cheers :slight_smile:

Bonjour Fabien,

Je vous propose de regarder les exemples fournis dans la documentation en ligne :
http://documentation.bonitasoft.com/web-rest-api-examples-0#list_deployed
et de vérifier l’id du processus que vous souhaitez démarrer avec l’appel :
→ get deployed process
http://localhost:8080/bonita/API/bpm/process?p=0&c=10

Il vous retournera un id, et c’est cet id que vous allez utiliser dans votre startcase/code.

Par ailleurs si vous jetez un coup d’oeil à la BDD BonitaBPM table PROCESS_DEFINITION, il faut utiliser la data PROCESSID et non pas la data ID.

Tenez moi au courant.

Cordialement,
LL

Bonjour LL,
C’était en effet un problème d’id, je vous remercie de votre aide.
Fabien