REST: how to get the activity name from activity id

Hi,

From the /incident API, I retrieve a list of incidents, each having an activityId field.
From this activityId (such as “Activity_080808”), I would like to retrieve the activity name, which is displayed in the renderer.

Unfortunately I cannot find any API that would help me to get that.

I have seen this post which makes me wonder if it exists: How to get ActivityName for ActivityId from REST API for Generate Migration Plan

And looking at the various tables in the database, I really wonder where this is stored btw.

And BTW2, I actually realize that activityId can correspond to various things: a task, an event, a sequence flow…

Can you please help??
Many thanks

1 Like

Hi @bfredo123 ,

You are right, that activityID can be multiple symbols. I am not sure if there is a way to find out the activity type by having the activity ID. It would either relate to a usertask (task) an external task or a job in the database.

I think in order to make a GET call you would need to know if you are looking for a usertask, an external task or a job.

I hope that helps, kind regards
Nele

Thanks for your help Nele. Well, it looks like the most viable way to go is to query the BPMN diagram to find the activity matching the ID, and from there, get its name. This will have to be client-side, so if anyone sees a way to make it server-side, I would appreciate.

Best regards

BTW using the Java API, you cant extract an Activity name, if you know the Process Definition Id and the Activity Id:

public String getFailedActivityName(String processDefinitionId, String activityId) {
    RepositoryService repositoryService = 
    ProcessEngines.getDefaultProcessEngine().getRepositoryService();
    ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId);
    InputStream resourceStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());

    BpmnModelInstance modelInstance = Bpmn.readModelFromStream(resourceStream);
    Collection<Activity> activityList = modelInstance.getModelElementsByType(Activity.class);

    for (Activity activity : activityList) {
        if (activityId != null && activityId.equals(activity.getAttributeValue("id"))) {
            return activity.getAttributeValue("name");
            }
        }
    }
    return null;
}