Checking post request body of a rest api call

Say, for the bpmn as below,diagram_1Testing.bpmn (2.8 KB)
I’ve called the rest call, http://localhost:8080/engine-rest/task/{{taskId}}/complete, a POST call with a request body of {“checkReqBody”:“Hello”}. Now I want to check the request body in a service task and send a response to the api call like {“checked”: true}.
How do I do that without using external service task? Help please

Hey Arnab! I am happy to try help you out here.
So what you want to achieve is to complete a task via HTTP post and set the variable “checkReqBody” to “Hello”.
After having set this process variable you want to validate it and return the result to an external api (not Camunda’s).
Did I understood this correctly?

If so, you can make use of a Java Delegate or a Script instead of an external task worker.
Hopefully this was already a bit helpful for you!

Yes, Thank you Thomas.
Unfortunately I failed to write the question completely, my bad.
Now, let’s say, when the POST api call for starting a particular process, http://localhost:8080/engine-rest/process-definition/key/Process_Desks/start is called, and now I wanna check the request body. Can I use {“variables”: {“checkReqBody”: “Hello”}} now to check the request body?

So assuming you have started a process instance with the according variable. You could access and check this variable via multiple possibilities.

  • As you have mentioned correctly - an external task listener
  • Via a Java Delegate
  • Via a Script task or a scripted listener.

Via a script you can easily access the variable like this
var requestBody = execution.getVariable('checkReqBody');
After having done so you can check wether the submitted value is allowed.

1 Like

Now, let’s assume that I haven’t started a process instance yet. But I want to by calling POST api call. When it’s called from postman, I want to check the request body on the camunda application. I don’t think I can check the variables in the request body of this POST call, can I?

In this case I would suggest that you register a start listener on the process and validate the presence of those variables there. Since this will be happening in the same transaction boundary you should be able to throw a http 400 error right back to postman.