# Trigger Example with V7

You can integrate model annotation workflows from [V7 Labs](https://www.v7labs.com) with Valohai using webhooks.

## Configuration on Valohai

You will need a step configured in your project to be launched as a V7 webhook is received. Here's an example configuration and code:

Add this step to your `valohai.yaml`:

```yaml
- step:
    name: V7 incoming
    image: python:3.11
    command:
    - pip install valohai-utils
    - python ./v7_request.py
    inputs:
      - name: v7-payload
```

Create a file named `v7_request.py`, with this code:

```python
import json
import valohai

with open(valohai.inputs("v7-payload").path()) as payload_f:
    payload = json.load(payload_f)

print("Got this data from V7:")
print(json.dumps(payload, indent=4))
```

We can now create a new Webhook Trigger in your Project settings -> Triggers -> Create Trigger

You will need to create and write down a unique secret token to authorize the webhook request. Your password manager can create and manage this secret, or you can choose this value freely.

1. For *Trigger Type*, select Webhook
2. Using the condition column's *+ Add* menu, add a *Web Request Authentication* condition
   1. *Type*: select "Static Token"
   2. *Token Lookup Namespace*: select "HTTP Header"
   3. *Token Lookup Key*: type `Authorization`
   4. *Secret Key*: put the unique secret token
   5. *Value Prefix*: type `token=`
3. Using the action column's *+ Add* menu, add a *Run Execution* action
   1. *Source Commit Reference*: type the primary branch of your Valohai project in Git. This is usually either `main` or `master`
   2. *Step Name*: type `V7 incoming`
   3. *Payload Input Name*: type `v7-payload`
4. Click on *Save Trigger*
5. You are now on the Triggers list again. Select the `...` menu of the trigger we just created, and select "Edit" to return to editing the trigger. Get the trigger URL and save it to your notes.

{% hint style="info" %}
**You can also launch a pipeline:** While this guide just uses a simple execution that lets you inspect the data payload V7 is sending, a good next step is to bootstrap the creation of a pipeline by parsing the webhook payload into input files and parameters for further steps in a pipeline.

This allows reusing general purpose steps as only the entry point execution needs to know how V7 sends data payloads.
{% endhint %}

## Configuration on V7

Webhooks are represented on V7 as Webhook stages in a workflow.

Navigate to your workflow, create a webhook stage, and connect it to the rest of the workflow:

1. *URL*: paste the webhook URL we created above
2. *Authorization header*: type: `token=<paste unique secret token here>`
3. Check *Include annotation data*
4. You can now click the "Test" button to check that it's all wired up and an execution is launched on Valohai

V7 will now automatically launch your step on Valohai once the workflow reaches the Webhook stage.

## Next steps

* Read [7labs docs about Webhook stages](https://docs.v7labs.com/docs/the-webhook-stage)
* You can call the V7 API from inside your Valohai executions to report results back. See the [V7labs docs for example code](https://docs.v7labs.com/docs/validate-annotations-with-webhooks)
