Starting process by Spring Boot Rest Client causing error 400

Hi, I tried to start simple process via rest client but I always received an error 400. I have stand-alone Camunda Community 7.13. My process is the same like this in Niall’s tutorial from YT with WatchMunster example.

I can’t find any good solution for it. The message is empty so I do not know what may it wrong. Can anyone help me solved this issue? When I tried simple .getForEntity( url, JsonNode.class) I received Status.Ok…

My code:

public class CamundaRestController implements CommandLineRunner {

  RestTemplate camunda;

  private String camundaEndpoint = "http://localhost:8080/engine-rest/process-definition/key/WatchMunster/start";

  private void callRestService() throws Exception {
      HttpHeaders headers = new HttpHeaders();

      HttpEntity<String> entity = new HttpEntity<String>("{}", headers);

      ResponseEntity<JsonNode> sth = camunda.postForEntity(camundaEndpoint, entity, JsonNode.class);

  public void run(String... args) throws Exception {

And log:

	at org.springframework.boot.SpringApplication.callRunner( [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.callRunners( [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at de.ikor.ClaimBPMS.ClaimBpmsApplication.main( [classes/:na]
Caused by: org.springframework.web.client.HttpClientErrorException$BadRequest: 400 : [{"type":"InvalidRequestException","message":""}] ```

Hi @WGie welcome to the community.

Are you using a tomcat distro?
Also - are you able to reach the rest api through the browser?
If you make this call http://localhost:8080/engine-rest/engine you should get
[{"name":"default"}] back.

Hi @Niall, yes I am using tomcat distro. And I am able to reach the rest api through the browser- I made this call and get [{"name":"default"}] back.

Are you able to make the call successfully using postman or another rest client?

Yes I can, via Postman when I made POST call with the same url which is in the java code and empty json I get status ok 200

@WGie, check whether are you querying for process definitions with processDefinitionKey by using processDefinitionName or processDefinitionId.

Both (name and id) are WatchMunster. I also tried with /process-definition/WatchMunster/start and received the same error.
Edit. Sorry I’m wrong id is different but I tried it also and always the same result. I’m not sure, maybe I should set something in headers? But I tried few options and no changes :frowning:

I added my project to github maybe I have something wrong in my configuration :frowning:
Here is link:
Thanks in advance for help

@WGie are you deploying in tomcat?

Yes I am deploying in tomcat.

@WGie, You need to fix the issues in your project, its not been properly setup.

  • If you are deploying tomcat server, why does your controller class implements command line runner? You can run as java application itself.

  • To deploy in tomcat, .war file should be generated when you run mvn clean install, but its not working.

I’m sorry, I misunderstood you, I’m running my project as a java application. (I have camunda tomcat distro). And when I run my application I get the error 400.

Can you provide more details about the command how you run the application with tomcat distro?

I have been downloaded camunda community. And I simply start it via bat file- I have an access in i.e. browser in url: http://localhost:8080/camunda, and then I start my project in Intelij as java application. If I good understand, in start it’s call the camunda for start the process. And I always have an exception: (IllegalStateException: Failed to execute CommandLineRunner)

	at org.springframework.boot.SpringApplication.callRunner( [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.callRunners( [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at pl.wgie.ClaimBPMS.ClaimBpmsApplication.main( [classes/:na]
Caused by: org.springframework.web.client.HttpClientErrorException$BadRequest: 400 : [{"type":"InvalidRequestException","message":""}]
	at org.springframework.web.client.HttpClientErrorException.create( ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.DefaultResponseErrorHandler.handleError( ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.DefaultResponseErrorHandler.handleError( ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.ResponseErrorHandler.handleError( ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.RestTemplate.handleResponse( ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.RestTemplate.doExecute( ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.RestTemplate.execute( ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at ~[classes/:na]
	at ~[classes/:na]
	at org.springframework.boot.SpringApplication.callRunner( [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	... 5 common frames omitted ```

@aravindhrs, You are right, it was something wrong with my code I removed command line runner and change the code a little bit and it works. Thank you for help.

Hi @Niall, I have same type of issue when calling camunda services with REST API. The data sent with the body is not getting picked (Ex: to start a message-event we need to send the correlationKey and etc…).

I can send data with postman, unable to do the same with REST calls. My setup is
remote camunda engine,
rest api just to send the calls that we send with postman

Can you show in detail the call your making and the results you’re getting in the engine?

and I tried different implementations but non did worked.

URI : http://localhost:8080/engine-rest/message

	public void sendPayment(Payment payment) {

	try {

		HttpHeaders headers = new HttpHeaders();

		headers.set("Content-Type", "application/json");

		MessageBody b = new MessageBody("bizcare_pay_notification", "key-PR-5555",
				new CorrelationKeys("bizcare_pay_notification"), payment);

		ObjectMapper obj = new ObjectMapper();
		String json = obj.writeValueAsString(b);

		final String uri = CAMUNDA_ENGINE + "/message";
		RestTemplate restTemplate = new RestTemplate();

		HttpEntity<String> entity = new HttpEntity<>(json, headers);

		ResponseEntity<JsonNode> sth = restTemplate.postForEntity(uri, entity, JsonNode.class);

	} catch (Exception e) {
		logger.error("Error occured " + e.getMessage());

with postman, i get 204
but with rest, i get “400 : [{“type”:“InvalidRequestException”,“message”:”"}]"

Is there any doc that i can refer related this?