# Connecting Inbox to Zendesk using Flow Builder

In this guide, you’ll learn how to integrate Inbox with Zendesk with [Flow Builder](https://dashboard.messagebird.com/en/flow-builder).&#x20;

You can integrate Inbox with 3rd party systems by adding additional steps in the Inbox Flow Builder flow. In this guide, we’ll illustrate a simple contact synchronization scenario:

* Show Zendesk contact information directly in Inbox—so that your agents know who they are interacting with.
* Ensure that if an agent further enriches the contact information (e.g. gets better customer details) that new contact information is synchronized back to Zendesk.&#x20;

**Prerequisites**

* A [Zendesk](https://www.zendesk.com/) account
* Knowledge of the [Zendesk API](https://developer.zendesk.com/rest_api/docs/support/users)
* An [Inbox](https://inbox.messagebird.com/) account
* [Flow Builder](https://dashboard.messagebird.com/en/flow-builder)

**Pro-tip:** In this guide, samples are provided to navigate the more technical aspects. Be sure to import the provided flow for details.

**What it will look like**

Sometimes it’s easier to understand how to get there if you can already see where you’re going, so here is the final flow we will build:

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-73bec2ddf6bcd6f299fe1ae6540c37226814cac3%2Fimage15.png?alt=media" alt=""><figcaption></figcaption></figure>

**What we will be doing**

* Customize the default Flow Builder **Inbox flow** (which is created by default for every Inbox installation)
* When a user conversation is initiated in Inbox, we’ll query Zendesk for any data available about that contact
* Update the Inbox contact with the information retrieved from Zendesk
* After the interaction is concluded (ticket closed), the contact information (potentially updated) is automatically push back to Zendesk

**End result as importable json**

You can [import this flow ](https://drive.google.com/file/d/1rAgHepTxv9l1w7wjmjjG6OU6wk0tS7nc/view?usp=sharing)directly into your sandbox. You’ll have to connect it to the appropriate channels.&#x20;

If you already have an Inbox Flow (Conversations) flow, deselect the channels from the first step, Omnichannel and you’ll be able to select them in the flow you just imported.

&#x20;

**Step by step**

**Step 1: Locate the flow corresponding to your Inbox installation**<br>

1\. Go to [Flow Builder](https://dashboard.messagebird.com/en/flow-builder) and choose the **Inbox Flow (Conversations)** flow.<br>

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

\ <br>

By default, this flow has one step, **Create Inbox ticket**:

&#x20;

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

**Step 2: Determine the channel**

To best locate the corresponding contact inside Zendesk, we’ll determine the channel the customer is reaching out on (phone, email, etc).&#x20;

1\. Add a **Branch** step to the flow and check if there’s a phone number associated with the contact (meaning that the conversation is happening over a channel that has a phone number as an ID, like SMS or WhatsApp).

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

2\. To set the condition of the branch, choose **custom condition** and check if the contact’s phone number is set:

&#x20;

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

**Step 3: Query Zendesk for contact information**

If it’s a conversation coming over on a phone number (as opposed to conversations over emails or live chat), then we can query Zendesk using their [Search API](https://developer.zendesk.com/rest_api/docs/support/search) to see who is associated with that particular phone number:

1\. Look for contacts that correspond to that particular phone number, using something like:&#x20;

```
curl "https://{subdomain}.zendesk.com/api/v2/search.json" \

-G --data-urlencode "query=type:user phone:numberToSearch for" \

-v -u {email_address}:{password}
```

&#x20;

2\. Convert this to a Flow Builder *HttpFetch request*. The query parameters will reside in the URL, and we’ll make sure to URL encode the query parameter:

[https://{subdomain}.zendesk.com/api/v2/search.json?query=type%3Auser+phone%3A](about:blank)contact.phoneNumber

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

3\. Since the Zendesk API requires user and password authorization, we need to convert that to something Flow Builder understands, meaning an Authorization header with Basic authorization.

4\. As a preliminary step, we will need to Base64 encode the *user:password* parameter. Using <https://codebeautify.org/base64-encode>. It will look something like this:&#x20;

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-69163b101d0a1272d2f17fe18128bfb72f5b083c%2Fimage2.png?alt=media" alt=""><figcaption></figcaption></figure>

5\. Putting it together, it becomes an Authorization header:

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-7c19cc9207fa2fdc76119dbf61f263751f527d72%2Fimage10.png?alt=media" alt=""><figcaption></figcaption></figure>

6\. Done? Awesome! Now we need to store the results we received inside a variable.

Since in Zendesk you can have multiple contacts with the same phone number, we must make a decision and choose which is the “best”match”. In this example we will simplify things and just pick the first result *(results\[0])*.\
We will be picking up the phone, email, name, and URL for the Zendesk user.<br>

**Note:** We will need the Zendesk user’s URL later to push back changes to Zendesk.

&#x20;

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-4572976c1dd960186c5ebabcbd4973684f618586%2Fimage13.png?alt=media" alt=""><figcaption></figcaption></figure>

**Pro-tip:** Do a CURL query to the Zendesk API to check the entire response and understand what other properties might be extracted.

**Step 4: Check if we got at least one match**

We will add another branch step and check if we got any results from Zendesk (if not then there is nothing to inform Inbox about.<br>

Similarly to what we did previously, we check via a Custom condition if the *results\[0].name* variable contains any data.

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

**Step 5: Update the Inbox contact**

Now that we got the contact information back from Zendesk, it’s time to update the data on Inbox by using the **Update Inbox contact** step, passing the variables we saved earlier (results\[0].name, results\[0].phone, etc.) as shown below:

**Step 6: Pass the information to Inbox**

Now that we’ve ensured to get the latest customer information from Zendesk we can signal Inbox that a case can be created and assigned to an agent. Just add the **Create Inbox Ticket** step and keep the default configuration.

**Step 7: Retrieve the updated Inbox contact information**

During the conversation with the user, the agent might discover new information about the user (e.g. company name, email, etc.). While the agent will update the Inbox contact information, we want to make sure this information is synchronized back to Zendesk.<br>

1\. Let’s make sure the flow has access to the latest Inbox contact information. We’ll add another **Http Fetch** step, make a call to the V2 version of the [Contacts API](https://contacts.messagebird.com/v2/contacts/), and pass the contact ID.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-23f9da34cddc6ee27500502cfcd3654103fdcd41%2Fimage5.png?alt=media" alt=""><figcaption></figcaption></figure>

2\. Since the MessageBird APIs use API key authentication, we will also add an Authorization header of type *AccessKey*, followed by the MessageBird API key. You can find your key on MessageBird Dashboard, under [Developers API access](https://dashboard.messagebird.com/en/developers/access).

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-48d01441752da6f5e21cf22e602ae62cedb01ad3%2Fimage12.png?alt=media" alt=""><figcaption></figcaption></figure>

**Step 8: Push latest contact information back to Zendesk**

1\. Use the **Zendesk user URL** we saved earlier to do an update (put) with the latest Inbox contact information:&#x20;

* The URL has to be *results\[0].url*
* The payload (body) follows the format described in the [Zendesk documentation](https://developer.zendesk.com/rest_api/docs/support/users#update-user). In our case, we will be updating the *first name* and *email* fields

```
{"user": {"name": "firstName", "email": "email"}}
```

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-23eded3393a744ae45f1773b4c0e307d148e764f%2Fimage9.png?alt=media" alt=""><figcaption></figcaption></figure>

3\. **Publish** your flow in the top right corner of your screen, and you're good to go! 2. Add the Authorization header specific to Zendesk calls (see step 3).

&#x20;

&#x20;

And that’s it! 🎉 Now you know how to connect Inbox to Zendesk using Flow Builder.&#x20;
