Search code examples
restbpmncamunda

Whats wrong in my camunda fetchAndLock API request. Getting InvalidRequestException


I have 2 topics to receive data from API, those I can Successfully executed through code. Now I'm trying to execute through rest api using postman tool. now i'm getting InvalidRequestException. Before attempting request I fetched the external tasks using camunda get external-task api and my topics showing there.Later I tried to use /external-task/fetchAndLock API to send input variables.

External tasks response is:

http://localhost:8080/engine-rest/external-task
[
    {
        "activityId": "Activity_0jokenq",
        "activityInstanceId": "Activity_0jokenq:0623e6f2-4837-11ec-8c7e-02426d005d3a",
        "errorMessage": null,
        "executionId": "0623e6f1-4837-11ec-8c7e-02426d005d3a",
        "id": "0623e6f3-4837-11ec-8c7e-02426d005d3a",
        "lockExpirationTime": null,
        "processDefinitionId": "Process_0qcjqnm:1:da2ae20a-4836-11ec-8c7e-02426d005d3a",
        "processDefinitionKey": "Process_0qcjqnm",
        "processDefinitionVersionTag": null,
        "processInstanceId": "0623bfdb-4837-11ec-8c7e-02426d005d3a",
        "retries": null,
        "suspended": false,
        "workerId": null,
        "topicName": "yvalue",
        "tenantId": null,
        "priority": 0,
        "businessKey": null
    },
    {
        "activityId": "Activity_1xxpyet",
        "activityInstanceId": "Activity_1xxpyet:0623e6f6-4837-11ec-8c7e-02426d005d3a",
        "errorMessage": null,
        "executionId": "0623e6f5-4837-11ec-8c7e-02426d005d3a",
        "id": "0623e6f7-4837-11ec-8c7e-02426d005d3a",
        "lockExpirationTime": null,
        "processDefinitionId": "Process_0qcjqnm:1:da2ae20a-4836-11ec-8c7e-02426d005d3a",
        "processDefinitionKey": "Process_0qcjqnm",
        "processDefinitionVersionTag": null,
        "processInstanceId": "0623bfdb-4837-11ec-8c7e-02426d005d3a",
        "retries": null,
        "suspended": false,
        "workerId": null,
        "topicName": "testingtopic",
        "tenantId": null,
        "priority": 0,
        "businessKey": null
    }
]

my request is:

POST http://localhost:8080/engine-rest/external-task/fetchAndLock
    {
        "workerId": 1,
        "maxTasks": 100,
        "topics": [
            {
                "topicName": "testingtopic",
                "lockDuration": 100000,
                "variables": {
                    "a": {
                        "value": 1,
                        "type": "long"
                    },
                    "b": {
                        "value": 2,
                        "type": "long"
                    },
                    "id": {
                        "value": 1,
                        "type": "long"
                    }
                }
            }
        ],
        "asyncResponseTimeout": 5
    }

my BPMN diagram is: BPMN Diagram


Solution

  • Sorry mistake was mine I mentioned wrongly in request body. I mentioned

    "variables": {} 
    

    But it's a array of json "variables": []

    I mentioned here just variable names "variables": ["a","b","id"]

    Later I used POST /external-task/{id}/complete request to pass with values to complete the process