Bad Request using Rest Api Task/Claim

Hi,

I am using the REST Api to communicate with Camunda. Many Rest calls are working fine but I have a problem to claim a task. In the docu is the following link described.

POST /task/{id}/claim

For me it is new that the ID is somewhere in the middle of the url? Is it a query Param or just a real text?
Anyway… I am getting everytime a Bad Request.

Can someone give me a hint?
I implemented the folowing client using JERSEY.

public void claimTask(TaskDto taskDto) throws TaskedNotClaimedException {
        String taskId = taskDto.getId();
        String camundaMethod = "task/"+taskId+"/claim";
        String url = REST_URI + camundaMethod;

        WebTarget webTarget = client.target(url);
        ClientResponse response = webTarget.request().post(Entity.entity(user.getUserName(), MediaType.APPLICATION_JSON),
                ClientResponse.class);

        if (response.getStatus() >= 204) {
            throw new TaskedNotClaimedException("Request Not Successful. TaskId = " + taskId + "and UserID = " + user
                    .getUserName() + " Response = " +response.toString());
        }
    }

I call the method with the following unit tests…

@Test
public void claimTask() throws TaskedNotClaimedException {
    Mockito.when(user.getUserName()).thenReturn("demo");
    TaskDto task = new TaskDto();
    task.setId("dd270476-9275-11e7-a125-b2fc20524153");
    sut.claimTask(task);
}

The jersey call is returns a Bad Request Exception

Thanks :slight_smile:

Hi,

the problem is that I have to to send JSON instead of the String UserName.

Here is the corrected code…

@Override
public void claimTask(TaskDto taskDto) throws TaskedNotClaimedException {
    String taskId = taskDto.getId();
    String camundaMethod = "task/"+taskId+"/claim";
    String url = REST_URI + camundaMethod;

    ObjectMapper objectMapper = new ObjectMapper();
    ObjectNode jsonUserId = objectMapper.createObjectNode();
    jsonUserId.put("userId", user.getUserName());

    WebTarget webTarget = client.target(url);
    Response response = null;
    response = webTarget.request(
            MediaType.APPLICATION_JSON).post(Entity.entity(jsonUserId, MediaType.APPLICATION_JSON));
    if (response.getStatus() > 204) {
        //TODO: Check allready assigned....
        throw new TaskedNotClaimedException("Request Not Successful. TaskId = " + taskId + "and UserID = " +
                jsonUserId + "Response = " +
                    response.toString());
    }
}

The topic can be closed!

Thanks for sharing the solution :slight_smile: