> 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).

## 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.

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

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FSsP5wy7Blf4EK2hj0DxQ%2Femarsys%201.png?alt=media&amp;token=52863079-2a5a-4acf-8477-1f9c0b9bc52e" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FwzLrnqUH07AYFbF2TncN%2Fcybertill%20script%201a.png?alt=media&amp;token=09f21233-29d4-4568-b412-643e500186c5" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FRUMu4Ko2GjHaks1APPer%2Fcybertill%20script%202a.png?alt=media&amp;token=4aa8e425-9f96-46f5-98d9-2bde1842262d" alt="" width="563"><figcaption></figcaption></figure></div>

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

<details>

<summary><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FoTQs7eEfsfqZUPfRoiT7%2Ficon_code.svg?alt=media&amp;token=b4a6f8e5-8ebf-4ef8-ab24-a130d29b50c5" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F2v14X1SzJmEkse7wCvxF%2Fcybertill%20script%203.png?alt=media&amp;token=91cf0bf3-30a0-4c14-a2aa-8f0ec8a871b0" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FqGa5xs9XTPW7P99xyeYo%2Fcybertill%20script%203a.png?alt=media&amp;token=b3156409-ea74-4980-b87f-d8a70b2f9aa0" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fn5gQvQMQnGJwnx3OXsDz%2Fcybertill%20script%205.png?alt=media&amp;token=83c9a882-c5ec-49db-87f8-e34b2ac10a51" alt="" width="563"><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FYHBbceyjjCOjgi6JN30X%2Femarsys%20apply%20script%202.png?alt=media&amp;token=54acb6f2-f86b-44ed-8f10-ff3c9c5f3a19" alt="" width="563"><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FD5i2KFQatPoR9nWeU07J%2Fcybertill%20script%206.png?alt=media&amp;token=acddec43-39ab-4b77-9b04-e1fabbd6f6ee" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FoMDj67vy7ZxHkz7tmoy5%2Fcybertill%20script%204a.png?alt=media&amp;token=ec279132-1670-46cc-aecc-c61f93e9dcd8" 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="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FP9hvjHEJHjM8IGj5rjl3%2Fcybertill%20script%205a.png?alt=media&amp;token=67b79ac0-3d71-42ef-9a86-6756b387fde3" alt="" width="563"><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FyetMNsMg5rtvsLOfQaot%2Fcybertill%20script%206a.png?alt=media&amp;token=30ccdbbc-1a78-4a18-a2e6-9cc995c6b8ef" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 8**\
Save changes:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FZCC2kZZVzSLbSSabSWg2%2Fcybertill%20script%207a.png?alt=media&amp;token=40981314-a49c-40ce-b476-f64318d4b62c" 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).
