# Sending Forms Magic Links Data from OE to Celonis (Celonis)

You can manage retrieving data from Emporix OE to track which forms were sent to suppliers or contacts using the Magic Links extractor. The extractor allows for precise data retrieval or comprehensive tracking of all sent forms. This ensures accurate visibility into communication history with your suppliers and contacts.

## Prerequisite

To extract the data from OE to Celonis, you have to create a Data Pool in your Celonis account. Celonis uses Data Pools to collect and cluster data information to set up an integration flow. To learn about the details, see the [Celonis Data Pools](https://docs.celonis.com/en/creating-and-managing-data-pools.html) documentation.

## Extracting Magic Links data

### Creating a data connection

You can create your own data extractor based on an Emporix template. The steps below show how to work with the extractor template and how to use it for your custom configuration.

Start with creating a connection to your Celonis Data Pool that links your OE as the Data Source:

1. In your Celonis account, go to **Data Integration** -> **Your Data Pool** -> **Data Connections** and choose **Add Data Connection**.
2. Choose **Connect to Data Source**.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-79d87135472664c1ea6ca9a2219114dcf21f9341%2Fconnect_ds.png?alt=media" alt="" width="512"><figcaption></figcaption></figure>

3. Go to the **Custom** section and choose **Build custom connection** -> **Import from file**.
4. Enter the **Name** for your custom extractor. Optionally, you can also add a **Description** for it.
5. Download the Magic Link Extractor and then upload it as a JSON file in your Celonis extractor builder:

{% file src="<https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-b3d029b389dbc30cb4267872e74c0e261eaf7c43%2Fmagic_link_extractor_celonis.json?alt=media>" %}

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-70e4501eb3cedd45455ccd5537576fc60abbd7cf%2Fml_extractor.png?alt=media" alt=""><figcaption></figcaption></figure>

6. Choose **Save and Continue**.
7. Check the parameters that should be used for the connection and then continue to the next step. The parameters were configured automatically with the uploaded extractor JSON file.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-feea6243bc7fe0a971280cf62ab603d0ce4c736f%2Fml_extractor_parameters.png?alt=media" alt=""><figcaption></figcaption></figure>

8. Check the authentication method; for Emporix it's the OAuth2 (Client Credentials) method with the following endpoint and type details:

   * **Get Token Endpoint**: {Connection.AUTH\_URL}/oauth/token
   * **Grant Type**: client\_credentials\
     Don't modify this configuration. Continue to the next step to finish the process.

   <figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-8a252d5e56c3289a5a4e37f84da892045ab6e689%2Fauth_method.png?alt=media" alt=""><figcaption></figcaption></figure>

   At the end you can see endpoint defined for this extractor - **Get Magic Links**.

   <figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-854a0f336a8b53e2ce0755566727c3d2d8312e76%2Fml_extractor_endpoint.png?alt=media" alt=""><figcaption></figcaption></figure>
9. Having configured the data connection, we now need to establish the connection with Emporix system. Go to the **Data Connections** list again and choose **Add Data Connection** -> **Connect to Data Source** -> **Custom**. Choose the data connection that you created with the magic links extractor. It's visible there, under Custom connections.
10. Choose your connection and check its configuration to make sure all the authorization details like **Client ID** or **Client Secret** are added.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-34a67a8c4806037d6e6addb84d07dfcb6064a4ff%2Fml.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

11. When the connection to Emporix is established, you can now configure the responses that you get. In the endpoints configuration, choose the **Get Magic Links** endpoint.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-854a0f336a8b53e2ce0755566727c3d2d8312e76%2Fml_extractor_endpoint.png?alt=media" alt=""><figcaption></figcaption></figure>

Use the **Configure response using samples from your source system** option to generate the example from the source system.

Expand the field -> Choose **Use existing Data Source** -> Choose *your data source* -> Choose **Build Response**.\
This autogenerates the response configuration, which you can then view in the JSON below.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-ab070386d72b86ae2af1327ed6fade17b742d93b%2Fml_extractor_response.png?alt=media" alt=""><figcaption></figcaption></figure>

You can check that the JSON was updated with magic links configuration, for example:

```json
    {
    "id" : "",
    "name" : "",
    "expirationDate" : "",
    "stylesheet" : "",
    "submissionEventType" : "",
    "canBeSubmittedOnlyOnce" : false,
    "instanceId" : "",
    "scheduleId" : "",
    "createdAt" : "",
    "updatedAt" : "",
    "recipient" : {
      "company" : {
      "id" : "",
      "name" : ""
      },
      "contacts" : [
      {
          "id" : "",
          "name" : "",
          "value" : "",
          "language" : ""
      }
      ]
    },
    "mixins" : {
      "topicsNames" : "",
      "component" : {
      "escalated" : "",
      "name" : ""
      },
      "internalContact" : {
      "email" : "",
      "name" : "",
      "preferredLanguage" : ""
      },
      "internalContact2" : {
      "email" : "",
      "name" : "",
      "preferredLanguage" : ""
      }
    },
    "forms" : [
      {
      "id" : ""
      }
    ],
    "submissions" : [
      {
      "submittedAt" : ""
      }
    ],
    "customAttributes" : [
      {
      "name" : "",
      "values" : [
          ""
      ]
      }
    ]
    }
```

{% hint style="warning" %}
Make sure the `id` is checked as a **Primary Key**.
{% endhint %}

12. Choose **Finish** to save your connection configuration.

## Data jobs

1. To start with the data job configuration, in your **Data Pool** go to **Data Jobs** and choose **Add Data Job**. Add a name for the **Data Job** and choose the **Data Connection** you created for the magic links.

For example, a data job named **Load Magic Links** and a related **Magic Link Extractor** to it.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-ac9b8c4db8827967c8ff741779b6e2d9e48ac79c%2Fml_datajob.png?alt=media" alt=""><figcaption></figcaption></figure>

After creating the data job, you can add the forms extractions.\
2\. Choose **Add** in the **Extractions** section, add a **Name** for the extraction and save it.\
3\. Choose **Add Extraction** in the **Table Configuration**.\
4\. Select **magic\_link** from the list of available tables. Save the selection.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-2404624a4502f475e3ef7c71ec7fa6435eeadd64%2Fml_table.png?alt=media" alt=""><figcaption></figcaption></figure>

As a result, you should see the form table added to the extraction.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-98bbed4b22a60e1528b3893794e8918ce95826e4%2Fml_table2.png?alt=media" alt=""><figcaption></figcaption></figure>

5. Go back to the **Data Jobs** view. Choose **Execute Data Job**. This starts a new task and populates a schema that is later visible in the **Transformations**.\
   To check logs after a job execution, go to **Logs** tab and select the execution task that you want to view. You can see all the details related to the executed job.
6. Go back to the **Data Jobs** view and choose and **Add** two transformations in the **Transformations** section.

* `view the magic links` transformation - with `select * from "magic_link"` as the transformation statement

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-9a7929e84f75d906dbed7f68febc85881a79cb87%2Fml_transformation1.png?alt=media" alt=""><figcaption></figcaption></figure>

* `create submission table` transformation - with the following statement:

```json
     create table if not exists magic_link_submissions (
     magic_link_id varchar2(26),
     num_submissions integer,
     PRIMARY KEY(magic_link_id) 
     );


     DROP TABLE IF EXISTS magic_link_submissions_new;
     create table if not exists magic_link_submissions_new (
     magic_link_id varchar2(26),
     num_submissions integer,
     PRIMARY KEY(magic_link_id) 
     );

     INSERT into magic_link_submissions_new
     select ml.id, count(submissions."submittedAt") 
     from magic_link as ml left outer join "magic_link$submissions" as submissions on submissions."magic_link_id" = ml.id
     group by ml.id;

     merge into magic_link_submissions
     using magic_link_submissions_new
     on magic_link_submissions.magic_link_id = magic_link_submissions_new.magic_link_id
     WHEN NOT MATCHED THEN 
     insert (magic_link_id, num_submissions)
     VALUES (magic_link_submissions_new.magic_link_id, magic_link_submissions_new.num_submissions);
```

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-137ac3743011b3954421ad9ad87771ad89117f6e%2Fml_transformation2.png?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
For more details on Data Jobs, how to work with extractions and transformations, see the Celonis [Extracting and transforming data](https://docs.celonis.com/en/extracting-and-transforming-data.html) documentation.
{% endhint %}

### Data model

Set up the **Data Model** to establish relations between all of the extractor's components.

1. Go to *Your Extractor* -> **Data Model** and choose **Add Data Model**.
2. Select magic\_link related items for the table and choose **Next**.

You can skip the activity table configuration.\
3\. Set up all the **Foreign Keys** for your activity table.\
For example, set the ID key for the **magic\_link**.

* Choose **New foreign key** in the form settings.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-61c92dc4bdda7ae33964d658abb3229bef3d1783%2Fml_key.png?alt=media" alt="" width="250"><figcaption></figcaption></figure>

**Set up the relations**:

* Link `magic_link` (Dimension) with `magic_link_submissions` (Fact) by linking `id` and `magic_link_id`.
* Link `magic_link_submissions` (Dimension) with `form_submission` (Fact) by linking `magic_link_id` and `magicLinkId`.
* Link `form_submission` (Dimension) with `form_submission$data$visiting` (Fact) by linking `id` and `form_submission_id`.

To see an example of a configured data model, check the below sample **Data Model**:

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-b8503bf04880f5c063ac460b454bc3c2d2610b45%2Fml_model.png?alt=media" alt=""><figcaption></figcaption></figure>

4. After setting up the relations, go to **Data loads** tab and choose **Load Data Model**.

When the load is finished you can check the details of the currently loaded data model.

{% hint style="info" %}
To learn more about the configuration of Data Models in Celonis, see the [Data Model Denifinition](https://docs.celonis.com/en/data-model-definition.html) documentation.
{% endhint %}

## Executing a data load

Execute a data load based on your form submission configuration and created connection.

1. Go to **Data Pools** -> **Data Jobs** and choose **Execute Data Job**. You can select to execute a Delta or a Full Load. Delta loads only the part of data that changed since the last upload.
2. Choose **Execute Selection**. The job starts and you can already see the process logs.

When the process is finished, you can check the logs details.

### Restricting initial loads

Use the **Enable creation date filter** to set up a date from which the data should be loaded. This is used for setting the timestamp for the initial load and late in the delta loads as well.

To enable set up the initial load, use the `createdAtGte` filtering.

1. Go to **Data Jobs** -> *Your extraction task* -> **Table Configuration**.
2. Enable the **Creation date** filter and select the `createdAtGte` filter.
3. Set up the custom date and save your configuration.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-6ac2a1f5ca3d902fc006913bb98fdc70f844840e%2Fml_initial_load.png?alt=media" alt=""><figcaption></figcaption></figure>

### Delta loads

Use the **Enable change date filter** to configure your delta loads. You can set up a date from when the updated data would be fetched with the `updatedAtGte` filtering.\
You can also configure the executions to make the `updated at` column visible and to upload data only from the specified time.

1. Go to **Data Jobs** -> *Your extraction task* -> **Table Configuration**.
2. Enable the **Change date** filter.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-acd91a8ab8d183887ee7e8d8014e0627ddf69c0a%2Fml_filter.png?alt=media" alt=""><figcaption></figcaption></figure>

3. Create a new parameter for the modified time - `<%=max_modified_time%>`.

   Go to *Your Extraction* -> **Parameters** tab and choose **New Parameter** and provide the following values in the fields:

   * **type:** dynamic
   * **table**: magic\_link
   * **column**: updatedAt
   * **operation type**: FIND\_MAX
   * **data type**: date
   * **default date**: any date from the past

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-3d7dd4958a98a1b52e7417698e660d731d2b99d7%2Fml_delta.png?alt=media" alt=""><figcaption></figcaption></figure>

4. Use the Delta filter statement to define the parameter settings - `updatedAtGte = <%=max_modified_time%>`.

<figure><img src="https://1593395737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQHHnOQFqJkmze1kPDN3S%2Fuploads%2Fgit-blob-749748465401566d39a629b46ad13a3d6d984b2c%2Fml_filter_delta.png?alt=media" alt=""><figcaption></figcaption></figure>
