Call REST API from listener

Hi!

I’ve added a ‘create’ task listener to one of the tasks, and I’m wondering if I can use it to do some API calls to get some data from the DB, like the users. Right now, I do it using AngularJS from the embedded form code, but it’s getting messy as I add more calls like the following:

$scope.getUsers = function() {
    return $http.get(Uri.appUri('engine://engine/:engine/user'), {
        headers: {
            'Content-Type': "application/json;charset=utf-8"
        },
        body: {
            'sortBy': 'userId',
            'sortOrder': 'asc'
        }
    });
}

How could I do the same inside the notify method of the task listener class?

Thanks,

You can use a library to run a http request. Similar to using HTTP-Connector.

Many examples on the forum.

Hi!

I thought that it would be necessary to use some of Camunda’s classes. I’ll do some tests with Apache HTTPComponents to see if it works.

Thanks!

Hi again,

One more question: With Angular, I use $http.get(Uri.appUri('engine://engine/:engine/user') to request the users. What would be the URL to call from Java? I’ve tried the following but it doesn’t work:

HttpGet httpGet = new HttpGet("/camunda/api/engine/engine/default/user");

Unless necessary, I wouldn’t like to write the full URL in the code, to avoid changing it when we change the server’s address. Is this possible?

Thanks!

You can use the internal apis if you want to access Camunda resources: execution.getProcessEngineServices().getIdentityService()…