Retrieve process instance key

This is my setup for a process
1- i have a form frontend with a flask backend what enriches the form data
2- this flask backend sends the form data to my camunda process via a webhook and starts the camunda process instance.

3- the first task after this webhook is a user task what is assigned to a user with a username for giving an approval. The username is in the formdata btw.

So here is the problem. I want to send this user a mail for the exact location of the user task url. For that I need to know the user task id. And to search for this user task id i need to know the process instance key. So how can I retrieve one of these keys?

You can obtain the formID and the ProcessDefinition key through the /v1/tasks/search endpoint as shown in the image, if you have questions about how to make the tasklis request I wrote an article explaining it step by step, you can take a look Uncomplicating communication via API in Camunda 8 Self-managed using Postman or Insomnia | by Domingos Dias | Mar, 2024 | Medium

Ooh but that is the thing. I am not using the camunda forms. This is just a form in vue.js

You asked how you can recover the process instance key, right? Do this using the camunda REST API using the camunda form or not, you can also use the process-instances endpoint as shown in the image

The problem is that I have no correlation with the initial processInstance to search for. I mean sure I could search for the last x processinstances, but it does not guarantee me that the one I am looking for is in the list if there are too many processes. So the thing is I need some correlator to search for and the process name is not enough.

Hi @gevezex ,

when starting a process via webhook, you need to correlate the process to a “business variable”. Just pass a variable like orderId from your backend to the webhook. You can use the API then to directly search for the user tasks for this variable (Search tasks | Camunda 8 Docs). Note that the tasks are provisioned to the search 5 sec after creation.To find the specific task, search by that variable and the taskDefinitionId.

In case there’s a reason to not rely on a variable on your end, you can also consider this alternative:

As an alternative to the Webhook, you could implement your own backend logic to start processes, and implement the gRPC API.

When you start a process instance using the gRPC API, you receive the key of it.

C.f. the gRPC docs: Gateway service | Camunda 8 Docs

We will also deliver “task listeners” in 8.6 which allows your backend to listen for user task creation or assignment, and send notifications/mails as a reaction (or anything else).

Product Manager Tasklist

Thnx for your detailed answer @christian-konrad , this helps a lot.

In my opinion the ProcessInstanceKey should really be a default variable what should be available in every process aspecially for the rest connector what does not have a worker. This would avoid a lot of work-around what your solution suggests.

@gevezex would it help in your case if we expose metadata such as the process instance key and user task key as variables, to be used in both workers and Modeler (hence connectors)?

Would you envision other metadata exposed as variables as well?

Absolutely, as the two keys in question do not contain sensitive information, disclosing them poses no security concerns. The primary process instance key is crucial, and with that information at hand, I can readily perform a search for the user task key by making an additional REST call to the search API, should integrating the user task key directly prove to be overly cumbersome.