# 500 error from "create case" REST API call

**URL:** <https://community.ofelia.com/t/500-error-from-create-case-rest-api-call/4399>\
**Category:** Q&A\
**Created:** [14 April 2014 17:33 UTC](https://community.ofelia.com/t/500-error-from-create-case-rest-api-call/4399 "2014-04-14T17:33:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sean.mclemon](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@sean.mclemon](https://community.ofelia.com/u/sean.mclemon)\
**Post date:** [14 April 2014 17:33 UTC](https://community.ofelia.com/t/500-error-from-create-case-rest-api-call/4399/1 "2014-04-14T17:33:59Z")

</div>

Having read [this quick guide](http://documentation.bonitasoft.com/web-rest-api-examples#start_case) I’ve created a simple process and deployed it locally using the Bonita UI version 6.2.5 - I can login, create a new case of my process navigating to localhost:8080 in my browser. However when I attempt to create a new case using the REST api I get a HTTP 500 error and the following response returned:

{"exception":"class java.lang.NullPointerException","message":"","stacktrace":[\< massive stack trace here \>]}

To do this I’m navigating to **[http://localhost:8080/bonita/API/bpm/process?p=0](http://localhost:8080/bonita/API/bpm/process?p=0)** to obtain the process ID, which I believe is the highlighted portion of the response below:

[{“id”:“ **7163253574217604033** ”,“icon”:“”,“displayDescription”:“”,“deploymentDate”:“2014-04-14 16:00:54.369”,“description”:“”,“activationState”:“ENABLED”,“name”:“AuthoriseBankAccountChange”,“deployedBy”:“4”,“displayName”:“AuthoriseBankAccountChange”,“last\_update\_date”:“2014-04-14 16:00:54.553”,“configurationState”:“RESOLVED”,“version”:“1.0”}]

Then I’m creating the POST request as follows - I’m just putting together a quick POC\evaluation first, which is why I’m hacking a quick test together using js in my browser:

// authenticate. verified correct by logging in with these credentials using the //web UI, logging out + clearing cookies, unsuccessfully navigating to // http://localhost:8080/bonita, then issuing the command and successfully //navigating to http://localhost:8080/bonita var loginURL = "http://localhost:8080/bonita/loginservice" $.post(url, { username: "walter.bates", password: "bpm", redirect: false })

// create a new case. returns http 500 error  
var processURL = “[http://localhost:8080/bonita/API/bpm/case/](http://localhost:8080/bonita/API/bpm/case/)”  
var processData = { “processDefinitionId”: 7163253574217604033, “variables”: [{“name”:“claccountid”, “value”:“123456”},{“name”:“datemodified”, “value”:“2014-04-14”},{“name”:“modifiedby”, “value”:“404404”},{“name”:“fieldname”, “value”:“SortCode”},{“name”:“oldvalue” , “value”:“123456”},{“name”:“newvalue” , “value”:“123455”},{“name”:“approved”,“value”:“false”}]}  
$.post(processURL, processData)

For each of the elements in “variables” the “name” field corresponds to a variable in the main swimlane of my BPM diagram. When I change the processDefinitionId to something random I get the same error, so I’m thinking that I might be using the wrong value - is this the case?

Edit: full stack trace is as follows…  
  
{“exception”:“class java.lang.NullPointerException”,“message”:“”,“stacktrace”:[“org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:212)”,“org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:198)”,“org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:188)”,“org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:168)”,“org.bonitasoft.web.rest.server.framework.APIServletCall.getJSonStreamAsItem(APIServletCall.java:84)”,“org.bonitasoft.web.rest.server.framework.APIServletCall.doPost(APIServletCall.java:169)”,“org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.doPost(ToolkitHttpServlet.java:184)”,“javax.servlet.http.HttpServlet.service(HttpServlet.java:643)”,“org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.service(ToolkitHttpServlet.java:71)”,“javax.servlet.http.HttpServlet.service(HttpServlet.java:723)”,“org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.service(ToolkitHttpServlet.java:222)”,“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.FilterManager.pageRedirect(FilterManager.java:88)”,“org.bonitasoft.console.common.server.login.filter.FilterManager.doFilter(FilterManager.java:68)”,“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(Unknown Source)”]}

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [15 April 2014 13:03 UTC](https://community.ofelia.com/t/500-error-from-create-case-rest-api-call/4399/2 "2014-04-15T13:03:04Z")

</div>

Hello,

it seems that you forget to set the language you want to use. See:  
[http://documentation.bonitasoft.com/web-rest-api-details#authentication](http://documentation.bonitasoft.com/web-rest-api-details#authentication)

Extract from the documentation:

> After you log in, get the translation resource for the current locale. This is used to return the appropriate language strings in subsequent calls.
> 
> **Request URL** : _[http://host](http://host):port/bonita/API/system/i18ntranslation?f=locale%3dlocale-id_  
> **Request Method** : _GET_  
> In the request URL, locale-id is the two-letter code identifiying the locale. For example, to get the French-language resources, use a GET request with the URL _[http://localhost:8080/bonita/API/system/i18ntranslation?f=locale%3Dfr](http://localhost:8080/bonita/API/system/i18ntranslation?f=locale%3dfr)_.

See more at: [http://documentation.bonitasoft.com/web-rest-api-details#authentication](http://documentation.bonitasoft.com/web-rest-api-details#authentication)

Note that this step could be not mandatory in the future 😉

Regards,

---

<div class="post-metadata">

**Author:** ![sean.mclemon](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@sean.mclemon](https://community.ofelia.com/u/sean.mclemon)\
**Post date:** [16 April 2014 09:15 UTC](https://community.ofelia.com/t/500-error-from-create-case-rest-api-call/4399/3 "2014-04-16T09:15:12Z")

</div>

This was 100% user error and caused by my use of the jquery’s $.post() which sets the contentType to application/x-www-form-urlencoded for POST data by default. I rearranged my code to use $.ajax() instead and I was able to create a new case successfully. For posterity I’ve included the solution below (I restarted my laptop and deployed a new instance of my process so the processDefinitionID has changed):

// authenticate. verified correct by logging in with these credentials using the //web UI, logging out + clearing cookies, unsuccessfully navigating to // http://localhost:8080/bonita, then issuing the command and successfully //navigating to http://localhost:8080/bonita var loginURL = "http://localhost:8080/bonita/loginservice" $.post(loginURL, { username: "walter.bates", password: "bpm", redirect: false })

// now issue a GET to the i18ntranslation resource to set the locale  
$.get(“[http://localhost:8080/bonita/API/system/i18ntranslation?f=locale%3Den](http://localhost:8080/bonita/API/system/i18ntranslation?f=locale%3Den)”)

// create a new case.  
var processURL = “[http://localhost:8080/bonita/API/bpm/case/](http://localhost:8080/bonita/API/bpm/case/)”  
var processData = { “processDefinitionId”: 6481676728838404000, “variables”: [{“name”:“claccountid”, “value”:“123456”},{“name”:“datemodified”, “value”:“2014-04-14”},{“name”:“modifiedby”, “value”:“404404”},{“name”:“fieldname”, “value”:“SortCode”},{“name”:“oldvalue” , “value”:“123456”},{“name”:“newvalue” , “value”:“123455”},{“name”:“approved”,“value”:“false”}]}

$.ajax({  
url: processURL,  
type: “POST”,  
dataType: “xml/html/script/json”, // expected format for response  
contentType: “application/json”, // send as JSON  
data: processData  
complete: function() {  
console.log(“complete”);  
},  
success: function() {  
console.log(“success()”);  
},  
error: function() {  
console.log(“error()”)  
},  
});

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [15 April 2014 05:32 UTC](https://community.ofelia.com/t/500-error-from-create-case-rest-api-call/4399/4 "2014-04-15T05:32:04Z")

</div>

Hi,

Could you share the stacktrace that you can find in the server log file?

---

<div class="post-metadata">

**Author:** ![sean.mclemon](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@sean.mclemon](https://community.ofelia.com/u/sean.mclemon)\
**Post date:** [15 April 2014 07:47 UTC](https://community.ofelia.com/t/500-error-from-create-case-rest-api-call/4399/5 "2014-04-15T07:47:18Z")

</div>

Yep, just updated the question with this data

---

<div class="post-metadata">

**Author:** ![sean.mclemon](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@sean.mclemon](https://community.ofelia.com/u/sean.mclemon)\
**Post date:** [15 April 2014 14:10 UTC](https://community.ofelia.com/t/500-error-from-create-case-rest-api-call/4399/6 "2014-04-15T14:10:07Z")

</div>

OK I may be misunderstanding the documentation but it seems to imply that I just need to issue a GET to that resource with the appropriate locale string (in my case it’d be [http://localhost:8080/bonita/API/system/i18ntranslation?f=locale%3Den](http://localhost:8080/bonita/API/system/i18ntranslation?f=locale%3den)), and then proceed with the API call. The example makes no mention of using the locale data returned - which is a giant JSON array of translated strings - which seems a little weird.

Anyway, after I do this I still get the same HTTP 500 error, so this cannot be the cause. Are you sure I am obtaining the processDefinitionId correctly? I get this same error regardless of whether or not I use a valid or invalid one.
