# How to wait for an incoming hook

**URL:** <https://community.temporal.io/t/how-to-wait-for-an-incoming-hook/4799>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [May 25, 2022, 10:05pm UTC](https://community.temporal.io/t/how-to-wait-for-an-incoming-hook/4799 "2022-05-25T22:05:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktalebian](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ktalebian/32/2117_2.png) [@ktalebian](https://community.temporal.io/u/ktalebian)\
**Post date:** [May 25, 2022, 10:05pm UTC](https://community.temporal.io/t/how-to-wait-for-an-incoming-hook/4799/1 "2022-05-25T22:05:50Z")

</div>

Imagine I have the following workflow

```auto
workflow --> executeActivity1 (call an external service, pass executation id)
                 --> awaitForIncomingHook (external service would invoke your application back at a later stage)
                 --> doMoreStuff

```

One of the activity is to call another service. This service is async and can be completed at a far time future (maybe minutes, but maybe days). This service supports making a call back to a given URL whenever it is completed.

So I want to call this service, set the execution id, and then wait for this service to call me back before I continue with the rest of the workflow.

What is the best approach here? Is it best to do a `Workflow.await` and a `Signal`, where I have some API layer that posts a Signal to the workflow whenever it gets a call back?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [May 26, 2022, 12:07am UTC](https://community.temporal.io/t/how-to-wait-for-an-incoming-hook/4799/3 "2022-05-26T00:07:44Z")

</div>

Hi @ktalebian,

typically you have two options either using signal to report completion of your external service as you mentioned or using async activity completion (see sample [here](https://github.com/temporalio/samples-java/blob/main/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java)) .

In the case where your external service can heartbeat (continuously report progress via ActivityCompletionClient or some callback) using async activity completion would be fine.  
Otherwise having an activity to enqueue the external service and then having a signal for the reply is preferred.

---

<div class="post-metadata">

**Author:** ![ktalebian](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ktalebian/32/2117_2.png) [@ktalebian](https://community.temporal.io/u/ktalebian)\
**Post date:** [May 26, 2022, 3:08pm UTC](https://community.temporal.io/t/how-to-wait-for-an-incoming-hook/4799/4 "2022-05-26T15:08:34Z")

</div>

@tihomir thanks for the reply.

I’m not sure I understand the `async activity completion` way. How would the `ActivityCompletionClient` be invoked via the external service? There would basically be an API service that the external service calls. This API service would then have to somehow send a Signal to the Workflow to continue with the next execution. Are you suggesting the API service would somehow send something to the Activity?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [May 26, 2022, 8:36pm UTC](https://community.temporal.io/t/how-to-wait-for-an-incoming-hook/4799/5 "2022-05-26T20:36:01Z")

</div>

> How would the `ActivityCompletionClient` be invoked via the external service?

Typically you would need to pass the activity task token to your external service (as part of lets say a rest call) and the external service would use Temporal client apis to create an activity completion client and either heartbeat or complete the activity based on the passed task token.

For your use case (and if you do not control this 3rd party service) I think having an activity to enqueue it and waiting for its completion via signal would be preferred.

---

<div class="post-metadata">

**Author:** ![kaiyuanhou](https://avatars.discourse-cdn.com/v4/letter/k/57b2e6/32.png) [@kaiyuanhou](https://community.temporal.io/u/kaiyuanhou)\
**Post date:** [June 23, 2023, 10:25pm UTC](https://community.temporal.io/t/how-to-wait-for-an-incoming-hook/4799/6 "2023-06-23T22:25:37Z")

</div>

@tihomir

> In the case where your external service can heartbeat (continuously report progress via ActivityCompletionClient or some callback) using async activity completion would be fine.

Does the external service have to heartbeat in order for async activity completion to work? Or was the concern about the activity dragging too long if the external service fails and never completes the activity (in which case the activity start-to-close timeout could help)?

> Typically you would need to pass the activity task token to your external service (as part of lets say a rest call)

Any suggestion on how to pass this activity task token? From a quick try the token seems larger than 100 bytes and doesn’t look like something one would pass as query parameter in a REST call, for example. Any recommended way to encode and pass?

Also, it seems that with Java SDK, we don’t have a way to assign a business-level identifier as Activity ID [yet](https://github.com/temporalio/sdk-java/issues/86). Wanted to double check if I missed something.

I’m trying to complete an activity asynchronously, and am not sure how to best pass the activity task token or assign my own activity ID which will be easier to pass. Thanks!
