# Marketo: Inbound Webhook Triggers (/docs/preference-management/inbound-webhook-triggers/marketo)

This guide will run you through how to setup a custom webhook trigger in Marketo to push consent changes into the Transcend Preference Store.

For other details about this integration, you can find documentation for that integration in the [Transcend Dashboard](https://app.transcend.io/infrastructure/integrations/new?filters=%7B%22text%22%3A%22marketo%22%7D\&integrationName=marketo). These instructions can also be found by selecting your integration from the [Infrastructure -> Integrations](https://app.transcend.io/infrastructure/integrations) page and clicking on the "Connection" tab to view the instructions.

## Overview [#overview]

Setting up webhook triggers into Transcend involves 4 steps:

1. Create a new custom field on your lead object called `Unsubscribed_Inverted`
2. Create a smart campaign that sets the value of `Unsubscribed_Inverted` to the opposite of whatever `Unsubscribed` is set to whenever a new lead is created or the `Unsubscribed` field is changed.
3. Create a webhook that calls the Transcend PUT /v1/preferences API that forwads the value of your `Unsubscribed_Inverted` field.
4. Create a smart campaign that triggers the webhook in (3) whenever the value of `Unsubscribed_Inverted` is changed.

## Step 1. Create custom field `Unsubscribed_Inverted` [#step-1-create-custom-field-unsubscribed_inverted]

- Click on the `Admin` top menu.
- Go to `Database Management` -> `Field Management` in left hand side menu

![Go to Marketo Field Management](/images/screenshot/2024-11-13-marketo-field-management.png)

- Click `New Custom Field` and specify following values
  - **Object**: `Person`
  - **Type**: `Boolean`
  - **Name**: `Unsubscribed_Inverted`
  - **API Name**: `unsubscribedInverted`

![Create New Custom Field](/images/screenshot/2024-11-13-marketo-new-custom-field.png)

- Click `Create`, after which you should be able to search for your newly created field in search menu on right hand side of the screen

![Marketo resulting created custom field](/images/screenshot/2024-11-13-marketo-view-created-field.png)

## Step 2. Create a smart campaign to populate `Unsubscribed_Inverted` [#step-2-create-a-smart-campaign-to-populate-unsubscribed_inverted]

- Click on the `Marketing Activties` top menu.
- Right click on `Default` in the left side menu and click `New Campaign Folder` to create a new folder to store Transcend smart campaigns

![Create a new campaign folder](/images/screenshot/2024-11-13-marketo-new-campaign-folder.png)

- Name the folder `Transcend` with a description something like `Integration with transcend.io for preference management`

![Name and save the Camaign folder](/images/screenshot/2024-11-13-marketo-name-camaign-folder.png)

- Click back on `Default` in top left corner and click `New Smart Campaign` button

![Create a new smart camaign](/images/screenshot/2024-11-13-marketo-new-smart-campaign.png)

- Fill out the form to create the smart campaign
  - **Campaign Folder**: `Transcend`
  - **Campaign Name**: `Set Unsubscribed_Inverted for transcend.io`
  - **Description**: `Set the Unsubscribed_Inverted custom field to be the inverted value of Unsubscribed field whenever a new lead is created or updated.`
  - **Executable**: Leave blank

![Fill out the smart campaign form](/images/screenshot/2024-11-13-marketo-smart-campaign-form.png)

- Go to `Smart List` tab and make the following changes:
  - Update filter to `Use ANY filters` instead of `Use ALL filters`
  - Add new rule for `Data Value Changes` with `Attribute` selection of `Unsubscribed`
  - Add additional rule for `Person is Created`

![Set up smart list rule for unsubscribed_inverted](/images/screenshot/2024-11-13-marketo-inverted-smart-list.png)

- Go to `Flow` tab and make following changes
  - Add rule for `Change Data Value`
  - Set if statement logic to: `If Unsubscribed is true`
  - Set first conditional to `Attribute: Unsubscribed_Inverted New Value: false`
  - Set default choice to `Attribute: Unsubscribed_Inverted New Value: true`

![Set up the flow for unsubscribed_inverted](/images/screenshot/2024-11-13-marketo-inverted-flow.png)

- Go to `Schedule` tab to activate campaign
  - Ensure Campaign Status is set to `Active`
  - Ensure `Block non-operational emails` is not checked
  - Ensure `Run each person through the campaign flow` is set to `every time`

![Enable qualifcation rules for unsubscribed_inverted campaign](/images/screenshot/2024-11-13-marketo-inverted-qualification-rules.png)

- At this point, you should be able to test that this is working
  - You should start seeing triggers for this smart campaing in the `Results` tab
  - You can test this by going to a lead, toggle the `Unsubscribed` field and then check back on the `Results` tab to ensure the campaign triggers

![View results of unsubscribed_inverted camaign](/images/screenshot/2024-11-13-marketo-inverted-results.png)

## Step 3. Create a webhook trigger [#step-3-create-a-webhook-trigger]

- Click on the `Admin` top menu.
- Go to `Integration` -> `Webhooks` in left hand side menu
- Click `New Webhook`
  - **Webhook Name**: `Transcend Preference Change`
  - **Description**: `Push consent change events to transcend.io Preference Management`
  - **URL**: This value can be found in the [section below](#finding-your-sombra-url). If Transcend hosted, this value is `https://multi-tenant.sombra.us.transcend.io/v1/preferences` for EU hosting and `https://multi-tenant.sombra.transcend.io/v1/preferences` for US hosting.
  - **Request Type**: `PUT`
  - **Template**: See Below
  - **Request Token Encoding**: `None`
  - **Response type**: `None`

The request template will look like:

```json
{
  "records": [
    {
      "userId": "{{lead.Email Address}}",
      "partition":  "6efb0409-a0f6-4d3c-90dd-0a03f909dd68",
      "timestamp": "{{system.dateTime}}",
      "purposes": [
        {
          "purpose": "Marketing",
          "enabled": {{lead.unsubscribedInverted}}
        }
      ]
    }
  ],
  "skipWorkflowTriggers": false
}
```

However you will need to adjust `partition` using the [guide below](#finding-your-partition) and `purpose` using the [guide below](#finding-your-purpose-and-preference-slugs)

![Create a new webhook in Marketo](/images/screenshot/2024-11-13-marketo-new-webhook.png)

- Lastly, you will want to add two Customer Headers
  - **Authorization**: This is an API key created under [Developer Settings -> API Keys](https://app.transcend.io/infrastructure/api-keys) and create a new API key with the scope `Modify User Stored Preferences`.
  - **Content-Type**: `application/json`

![Add webhook headers to Marketo webhook](/images/screenshot/2024-11-13-marketo-webhook-headers.png)

### Finding your Sombra URL [#finding-your-sombra-url]

- Go to [Infrastructure -> Sombra](https://app.transcend.io/infrastructure/sombra/sombras) in your Transcend account
- Choose the <GlossaryTerm id="sombra">Sombra</GlossaryTerm> gateway that makes sense for your use case (you most likely will want to use the Sombra marked as "Is Primary Sombra?")
- Copy the "Transcend Ingress URL" value as your Sombra base URL

![Preference Management Sombra Gateway](/images/screenshot/2024-11-11-copy-sombra-ingress.png)

### Finding your partition [#finding-your-partition]

The `partition` can be thought of as the ID of the consent database to update. In most implementations, you will just have one unique partition in your account. Multiple partitions can be useful in situations where you have multiple brands, partners or data controllers for which you need to separately track consent preferences for.

To grab this value:

- Go to [Preference Management -> User Preferences -> Settings](https://app.transcend.io/preference-store/settings)
- Ensure Preference Store toggle is enabled.
- Click on the button "Open Partition Settings"
- Locate your desired partition and click the copy button. The default partition is labeled `BUNDLE_ID` - this is most likely the value you will want to use.

![Preference Management Settings](/images/screenshot/2024-11-11-preference-management-settings.png)

![Preference Management Copy Partition Key](/images/screenshot/2024-11-11-partition-copy.png)

### Finding your purpose and preference slugs [#finding-your-purpose-and-preference-slugs]

When submitting requests to the Transcend API, you will want to update your purposes and preferences using their respective "Slug" values.

To find your purpose slugs, look at the "Slug" column under [Consent Management -> Regional Experiences -> Purposes](https://app.transcend.io/consent-manager/regional-experiences/purposes). To find your preference slugs, look at the "Slug" column under [Preference Management -> Topics](https://app.transcend.io/preference-store/preference-topics). To find your preference option slugs, look at the "Slug" column under [Preference Management -> Preference Topics -> Options](https://app.transcend.io/preference-store/preference-options).

## Step 4. Create a smart campaign to trigger webhook when `Unsubscribed_Inverted` changes [#step-4-create-a-smart-campaign-to-trigger-webhook-when-unsubscribed_inverted-changes]

- Click on the `Marketing Activties` top menu.
- Fill out the form to create the smart campaign
  - **Campaign Folder**: `Transcend`
  - **Campaign Name**: `Trigger Transcend Webhook when Unsubscribed_Inverted changes`
  - **Description**: `Send webhook event to Transcend when Unsubscribed_Inverted custom field changes.`
  - **Executable**: Leave blank

![Create new smart campaign to send webhook](/images/screenshot/2024-11-13-marketo-webhook-smart-campaign.png)

- Go to `Smart List` tab and make the following changes:
  - Add new rule for `Data Value Changes` with `Attribute` selection of `Unsubscribed_Inverted`

![Add smart list rules to webhook campaign](/images/screenshot/2024-11-13-marketo-webhook-smart-list.png)

- Go to `Flow` tab and make following changes
  - Add rule for `Call Webhook` with value `Transcend Preference Change` (created in Step 3)

![Add flow rules to webhook campaign](/images/screenshot/2024-11-13-marketo-webhook-flow.png)

- Go to `Schedule` tab to activate campaign
  - Ensure Campaign Status is set to `Active`
  - Ensure `Block non-operational emails` is not checked
  - Ensure `Run each person through the campaign flow` is set to `every time`

![View successful result in schedule tab](/images/screenshot/2024-11-13-marketo-webhook-success.png)

- At this point, you should be able to test that this is working
  - You should start seeing triggers for this smart campaing in the `Results` tab
  - You can test this by going to a lead, toggle the `Unsubscribed` field
  - If you refresh the page you should see `Unsubscribed_Inverted` set to the inverse of `Unsubscribed`
  - Under the `Results` tab of the second smart campaign created in step (4) you should see webhooks sending. Check to m
    and then check back on the `Results` tab to ensure the campaign triggers
  - Click on any `Results` to ensure that Transcend API is returning a 200 status code
- Check [Transcend Preference Management](https://app.transcend.io/preference-store/user-preferences) to ensure consent is synced in properly

![Enable webhook smart campaign](/images/screenshot/2024-11-13-marketo-enable-webhook-campaign.png)
