# Trigger shape (callback)

## Introduction

`Callback` triggers are used in conjunction with the [callback shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/callback-shape), so you can send API requests to initialise a process flow and return data in a real-time, synchronous call.&#x20;

When you add a `callback` to a process flow [trigger shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/trigger-shape), a unique Patchworks URL is generated. This URL should be used in your API request(s), so data can be returned from the [callback shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/callback-shape). For more information, please see our [callback shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/callback-shape) page.&#x20;

{% hint style="info" %}
Callbacks won't be initialised until the associated process flow is [deployed](https://doc.wearepatchworks.com/product-documentation/process-flows/process-flow-versioning#deploying-a-draft-or-inactive-version) and [enabled](https://doc.wearepatchworks.com/product-documentation/process-flows/managing-process-flows/enabling-and-disabling-a-process-flow/enabling-and-disabling-a-process-flow-without-virtual-enviroments).
{% endhint %}

## About Patchworks callback URLs

### URLs

The structure of a `callback` URL includes multiple elements. Some elements are always the same, some are unique to your organisation and/or environment, and some are unique for every callback:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FSIbTFM4rwVuqqs4c0gzC%2Fcallback%20structure%20-%20with%20ve%201a.png?alt=media&#x26;token=ecb395f6-862a-458b-8c46-d1619de94bdf" alt=""><figcaption></figcaption></figure></div>

For example:

{% code overflow="wrap" %}

```
https://callbacks.wearepatchworks.com/api/v1/docs_demo/01k678es5y21ref5rgzszd6yvw/2?patchworks_signature=9ne4gh16n123h5z9ytmmgyt12gd6td9ehs0cf1krr5g8atsg84h5
```

{% endcode %}

These elements are summarised below:

<table><thead><tr><th width="230.54296875">Callback URL element</th><th>Summary</th></tr></thead><tbody><tr><td>Base URL</td><td>This is always the same and would only change in the event of a new version of the Patchworks API being released.</td></tr><tr><td>Company</td><td>Your company/organisation name. </td></tr><tr><td>Callback ID</td><td>A unique identifier for the callback (different for every callback generated).</td></tr><tr><td>VE prefix</td><td>If you choose to <a href="#adding-a-trigger-webhook">generate trigger URLs for a virtual environment and then copy the VE URL</a>, the prefix (i.e. internal identifier) for the selected virtual environment is included in the URL. To verify the identifier used here, you can access the corresponding virtual environment and locate<a href="../../../../../virtual-environments/accessing-virtual-environments/the-anatomy-of-a-virtual-environment"> the URL prefix</a>.</td></tr><tr><td>Patchworks signature</td><td>A unique signature generated as a random hash (that doesn't expire). This provides built-in authentication for our URLs; however, signatures should still be kept private.<br><br>The Patchworks signature is rather like an impossibly long password. To generate this, we start by generating two unique identifiers. Next, we concatenate these identifiers and shuffle the result into a never-before-seen signature. The risk of collision is one in several billion, so even if someone could guess your URL, they could never guess the signature as well.  </td></tr></tbody></table>

## Need to know

As noted [above](#urls), the callback URL includes a signature, which (by default) is passed in as a URL parameter.&#x20;

However, some third-party systems do not allow URL parameters to be passed in and remove any that are received. In this case, a `patchworks-signature` header can be used. For details, please refer to: [Passing the Patchworks signature as a header for callback requests](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/trigger-shape/trigger-shape-callback/passing-the-patchworks-signature-as-a-header-for-callback-requests).&#x20;

## Adding a callback trigger

Follow the steps below to add a new `callback` trigger.

{% stepper %}
{% step %}
**Access trigger shape settings**

Click the `settings` icon associated with the `trigger` shape in your process flow:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FvPbltVCeMZVj0ZtnYRwY%2Ftrigger%20webhook%20settings%201.png?alt=media&#x26;token=81b4c548-efe9-4085-8456-4883c470fcd9" alt="" width="367"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**(Optional) Select a virtual environment**

If your callback needs to initialise a process flow that runs in a [virtual environment](https://doc.wearepatchworks.com/product-documentation/virtual-environments/about-virtual-environments), use the `customise URLs for virtual environment` selector to choose the required environment. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F8zoHktflwEtqtwZukXeJ%2Ftrigger%20webhook%20settings%202.png?alt=media&#x26;token=612ac003-cf38-4593-8841-476aa81bab53" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="info" %}
If you don't use [virtual environments](https://doc.wearepatchworks.com/product-documentation/virtual-environments/about-virtual-environments), ignore this option.
{% endhint %}
{% endstep %}

{% step %}
**Generate a new callback**&#x20;

Move down to the `callbacks` section and click the `add new callback` button. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F23TLqmyRAGMF7SAHBMoE%2Fadd%20callback%203.png?alt=media&#x26;token=0d2ddc6b-0b0e-4882-91fe-4cd1a2a66a5b" alt="" width="375"><figcaption></figcaption></figure></div>

...a unique [Patchworks callback URL](#about-patchworks-callback-urls) is generated - for example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FNdMCuYN5vaIBAuXR5rfj%2Fadd%20callback%203a.png?alt=media&#x26;token=fc009630-ceee-4dd1-aedf-86c4ac4adb7b" alt="" width="375"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Copy the callback URL**

Use `copy url` OR `copy ve url` buttons to copy this URL, ready to paste into your third-party application.&#x20;

{% hint style="warning" %}
If you selected a virtual environment in step 2, you should use the `copy ve url` option - this ensures that the callback triggers this process flow in the correct virtual environment.
{% endhint %}
{% endstep %}

{% step %}
**(Optional) customise callback behaviour**

By default, the payload returned for a callback is expected in JSON format, so the `content-type` for callback responses is set to `JSON`. If you require a different format, you can edit settings for the callback URL - for example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FVpQ3Vedl74djaUYX7yR3%2Fadd%20callback%204a.png?alt=media&#x26;token=8e10e531-0021-4b86-8cc5-11cc21db44c6" alt="" width="375"><figcaption></figcaption></figure></div>

...now you can update the expected format:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F5qL1pmfptHC7rbS3O5Vg%2Fadd%20callback%204b.png?alt=media&#x26;token=8acf377f-9de3-4069-87a3-dce07714f232" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
Payloads are not validated against this setting - it simply determines the `content-type` header value in responses.
{% endhint %}
{% endstep %}

{% step %}
**Complete process flow development**

Build the rest of your process flow as required.&#x20;

{% hint style="info" %}
When you're ready, ensure that your process flow is [deployed](https://doc.wearepatchworks.com/product-documentation/process-flows/process-flow-versioning#deploying-a-draft-or-inactive-version) and [enabled](https://doc.wearepatchworks.com/product-documentation/process-flows/managing-process-flows/enabling-and-disabling-a-process-flow/enabling-and-disabling-a-process-flow-without-virtual-enviroments). Callbacks will not be made if this isn't done.&#x20;
{% endhint %}
{% endstep %}
{% endstepper %}

## Related pages

* [The callback shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/callback-shape)
