# How do I get the ProcessInstanceId in my Interceptor?

**URL:** <https://forum.camunda.io/t/how-do-i-get-the-processinstanceid-in-my-interceptor/54192>\
**Category:** Discussion & Questions\
**Created:** [August 12, 2024, 4:36pm UTC](https://forum.camunda.io/t/how-do-i-get-the-processinstanceid-in-my-interceptor/54192 "2024-08-12T16:36:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Realistic\_Name](https://forum.camunda.io/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@Realistic\_Name](https://forum.camunda.io/u/Realistic_Name)\
**Post date:** [August 12, 2024, 4:36pm UTC](https://forum.camunda.io/t/how-do-i-get-the-processinstanceid-in-my-interceptor/54192/1 "2024-08-12T16:36:46Z")

</div>

Hi,

I’m currently working on an interceptor to handle the suspended state, and I need to retrieve the `processInstanceId` within the interceptor. The goal is to send an HTTP request to an API where the `processInstanceId` is stored.

I’ve attempted to use reflection to obtain this ID, but doing so has resulted in an `OptimisticLockingException`.

Is there an alternative way to acquire the `processInstanceId` from the context?

Thank you in advance for your help!

```auto
private synchronized <T> String getProcessInstanceId(Command<T> command) {
        String processInstanceId = null;
        try {

            // Access the protected field processInstanceId via reflection
            Field field = command.getClass().getSuperclass().getDeclaredField("processInstanceId");
            field.setAccessible(true);
            processInstanceId = (String) field.get(command);
            field.setAccessible(false);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            System.err.println("Error accessing processInstanceId: " + e.getMessage());
        }
        return processInstanceId;
    }

```
