> For the complete documentation index, see [llms.txt](https://doc.wearepatchworks.com/product-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.wearepatchworks.com/product-documentation/connectors-and-instances/patchworks-connectors/cybertill-prebuilt-connector/cybertill-post-request-script.md).

# Cybertill post-request script

## Introduction

Having installed the Cybertill connector, some setup is required before it can be used. You must:

* [Stage 1: Create a post-request script](#stage-1-creating-a-post-request-script)
* [Stage 2: Apply the post-request script to your Cybertill connector](#stage-2-applying-the-post-request-script)

Once this setup is complete, you can [add instances](/product-documentation/connectors-and-instances/working-with-instances/adding-an-instance.md) for use in [process flows](/product-documentation/process-flows/building-process-flows.md).&#x20;

## Stage 1: Creating a post-request script

A post-request script is required to generate an authentication token from the given instance credentials. Follow the steps below to create this script.

**Step 1**\
From the Patchworks dashboard, select **scripts** from the left-hand navigation menu.&#x20;

**Step 2**\
Click the **create script** button:

<div align="left"><figure><img src="/files/dkPKvXj5eziNnGeJAVpf" alt=""><figcaption></figcaption></figure></div>

**Step 3**\
In the **name** field, type the following:

```
Cybertill Post-Request Script
```

**Step 4**\
In the **description** field, type the following:

```
Cybertill Auth Token Generator - Post Script
```

**Step 5**\
Click in the **language** field and select **PHP 8.1**:

<div align="left"><figure><img src="/files/X8cUXBRnooew29DSjIli" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 6**\
Click the **create** button.

**Step 7**\
The script is created and opened in edit mode - select and remove any placeholder code:

<div align="left"><figure><img src="/files/qqO6jjdZNSZNzlznZb30" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 8**\
Paste in the code below.

<details>

<summary><img src="/files/4iYjBn9HEfUXX4ZSP1vh" alt=""> Post-request script code</summary>

{% code lineNumbers="true" %}

```php
 <?php

/**
 * Handler function.
 *
 * @param array $data [
 *      'payload'   => (string|null) the payload as a string|null
 *      'variables' => (array[string]string) any variables as key/value
 *      'meta'      => (array[string]string) any meta as key/value
 *    ]
 */

function handle($data)
{
    if (!isset($data['variables']['token'])) {
        throw new \Exception('Token has not been passed to script.');
    }

    if (!isset($data['variables']['auth_id'])) {
        throw new \Exception('Auth ID has not been passed to script.');
    }

    $token = sprintf('%s:%s', $data['variables']['token'], $data['variables']['auth_id']);

    $data['variables']['auth_token'] = base64_encode($token);

    return $data;
}
```

{% endcode %}

</details>

**Step 9**\
Click the **save and deploy** button:

<div align="left"><figure><img src="/files/Gq26sGP4gEr0e9a9JrIJ" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 10**\
Click the **scripts** element of the breadcrumb trail to exit back to your list of scripts and go to the next stage:

<div align="left"><figure><img src="/files/8nzBx5z9hbSuTPPXSuH6" alt="" width="563"><figcaption></figcaption></figure></div>

## Stage 2: Applying the post-request script

**Step 1**\
From the Patchworks dashboard, select **connectors and instances** from the left-hand navigation menu to access your installed connectors.

**Step 2**\
Find your Cybertill connector and click the **settings** icon.

<div align="left"><figure><img src="/files/xglSrn8AcxhBUnUyA64V" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 3**\
Click the **authentication** option:

<div align="left"><figure><img src="/files/uoPbie0xOCdeetFbsHPj" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 4**\
Select the **SOAP** authentication method:

<div align="left"><figure><img src="/files/PuMs2FybP34PdkOCWAfc" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 5**\
In the lower panel, select the **post-request script** tab:

<div align="left"><figure><img src="/files/VQORcFjhPYnKUkgQDTIH" alt=""><figcaption></figcaption></figure></div>

**Step 6**\
Click in the **select script** field and select your **Cybertill Post-Request Script**:

<div align="left"><figure><img src="/files/9xnjKdK5mWN5mLaUOoXX" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 7**\
Select the latest version:

<div align="left"><figure><img src="/files/nsCgWfccuLKXZiXkP0Pr" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 8**\
Save changes:

<div align="left"><figure><img src="/files/f1Q46NiMG7TluD5suS2f" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 9**\
You can now [add instances ](/product-documentation/connectors-and-instances/working-with-instances/adding-an-instance.md)of this connector for use in [process flows](/product-documentation/process-flows/building-process-flows.md).
