> For the complete documentation index, see [llms.txt](https://docs.saas.haut.ai/haut.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.saas.haut.ai/haut.ai/haut.ai-features/consumer-apps/make-real-time-data-connection-with-external-platforms-via-webhooks/example-of-haut.ai-saas-integration-with-klaviyo-via-zapier-with-the-recommendation-system-2.0.md).

# Example of Haut.AI SaaS integration with Klaviyo via Zapier (with the recommendation system 2.0)

This page describes how to pass data from Haut.AI to Klaviyo via Zapier, including results from Recommendation System 2.0.

{% hint style="success" %}
Integration with external platforms via webhooks is available for <mark style="color:green;">**all**</mark> plans.
{% endhint %}

{% hint style="warning" %}
To use webhooks in Zapier, you need a "Professional" plan in Zapier or higher.

You can check Zapier plans and pricing here: <https://zapier.com/pricing>.
{% endhint %}

{% hint style="info" %}
Check the no-code integration of the Consumer App with Klaviyo that allows to capture e-mails in the Consumer App and send them to the Klaviyo.
{% endhint %}

## Steps of Integration

To integrate Haut.AI SaaS with Klaviyo via Zapier, you need to complete a few steps:

1. [Set up and configure webhook in Zapier.](#set-up-and-configure-webhook-in-zapier)
2. [Test configured webhook.](#test-configured-webhook)
3. [Parse data passed via webhook.](#parse-data-passed-via-webhooks)
4. [Structure data.](#structure-data)
5. [Send data to Klaviyo.](#sending-results-to-klaviyo)

***

## Set up and configure webhook in Zapier

The first step is to receive data from SaaS to Zapier.

1. Login into your Zapier account.
2. Click on the "Create" button in the top-left corner.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2F82IG4k2QLHwiYx9x1iai%2Fimage.png?alt=media&amp;token=7fd2fbfa-1eba-4d47-b0d6-3f76aaa36317" alt=""><figcaption></figcaption></figure>
3. Select "Zaps" in the dropdown.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FYh66RmH5CaMncaxKUwbs%2Fimage.png?alt=media&amp;token=3f9f5aa2-6ae0-4346-91c8-943b79c721a2" alt=""><figcaption></figcaption></figure>
4. You will see the blank canvas as shown below. Click on the "Trigger" area.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FtYhSOYwV5qAnD5bqYeZz%2Fimage.png?alt=media&amp;token=f9f8ef30-fc03-4939-a7c0-8f013ff0cedf" alt=""><figcaption></figcaption></figure>
5. In the window that pops up, select "Webhooks by Zapier."

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2Fa0CJMiP1SfLn76q4r6lc%2Fimage.png?alt=media&amp;token=9a2d4f22-3570-4980-8aa1-1fbb73cad6e5" alt=""><figcaption></figcaption></figure>
6. In the window on the right, click on the "Choose an event" dropdown and select "Catch Raw Hook."

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2Fxm0GShwLU8wKsZLMm4Ms%2Fimage.png?alt=media&amp;token=5da58571-597e-45a1-bfed-517648d6b526" alt=""><figcaption></figcaption></figure>
7. Click "Continue" in the bottom right corner.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FLmsf3u9kUJfhGtGJehn9%2Fimage.png?alt=media&amp;token=9e89c886-2d76-475e-8797-c68589e20b26" alt=""><figcaption></figcaption></figure>
8. Click "Continue" again on the next step to skip it.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FBSao1zGePI4IxCQ11tQV%2Fimage.png?alt=media&amp;token=2df9cebd-a08a-4da2-9834-7c7ff79df152" alt=""><figcaption></figcaption></figure>
9. Copy the webhook URL by clicking on the "Copy" button.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2F04nNTW209jEr8RNmNaVB%2Fimage.png?alt=media&amp;token=cd6e6fc0-cd47-4885-9029-6a2840ee8f33" alt=""><figcaption></figcaption></figure>
10. Now go to your Haut.AI account,
11. Go to "Dataset" and open the dataset connected to your Consumer App. You can find this dataset by going to the Consumer App and clicking on ID of the Linked dataset.<br>

    <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FFq0Ww7UkyW9DJYelsQQi%2FLinked%20dataset%20in%20Skin%20Consultant%20app.jpg?alt=media&amp;token=6d8777e2-d831-45cf-835f-3711175db6cf" alt=""><figcaption></figcaption></figure>
12. Click "Settings" in the top menu of the Dataset.

    <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FK7Mg06yKWECmDisiz5GY%2Fimage.png?alt=media&amp;token=7433a85b-d631-409e-845e-baca67d7c54c" alt=""><figcaption></figcaption></figure>
13. Scroll down to the "Webhook (for developers)" section.
14. Paste the URL that you copied from Zapier to the URL field.<br>

    <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FNjuIycOVBqAdyQzz09Lr%2Fimage.png?alt=media&amp;token=0da7d450-e2ca-41be-93d4-bebe279e2ce3" alt=""><figcaption></figcaption></figure>
15. In the "Authorization method" field, select "Basic."
16. In the "Authorization key" and "Authorization value" fields, paste any value because Zapier does not require authorization.
17. In the "Request method" field, select "POST."
18. To add Survey answers to the webhook, select "Add survey answers to webhook." See [how to configure Survey questions in Step 1](/haut.ai/haut.ai-features/consumer-apps/make-real-time-data-connection-with-external-platforms-via-webhooks.md).
19. Select "Merge webhooks" to receive one webhooks for all attached applications.
20. Click "Save changes."

***

## Test configured webhook

The next step is to check that data received from SaaS is visible in Zapier.

1. Open your Consumer App.
2. Conduct skin analysis.
3. Go back to your Zapier account.
4. Click "Test trigger."

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2Fu6qaFQFzNZKEaAg82eQZ%2Fimage.png?alt=media&amp;token=3e0a13f6-822e-4b6e-ab82-29a7e4d0851d" alt=""><figcaption></figcaption></figure>
5. If everything is set correctly, you can see webhook results.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2F9jSpHc46trwimlfXewL8%2Fimage.png?alt=media&amp;token=e9da60c4-c90b-4099-8c5f-8030bf118f06" alt=""><figcaption></figcaption></figure>
6. If you click on the record, you will see skin something similar to the screen below.<br>

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2F1wx5VIWVqhP2X1p4xtWv%2Fimage.png?alt=media&amp;token=b680849b-b576-49a7-9b13-4c58f4d1d12f" alt=""><figcaption></figcaption></figure>
7. Select the record and click "Continue with selected record."

***

## Parse data passed via webhooks

The key important step is to parse received data in order to prepare it for connection with your 3rd party platform (e.g. Klaviyo)

1. For the action step, select "Code by Zapier"

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FNa9dmNSM2QP4kPMXXotT%2Fimage.png?alt=media&amp;token=8cac9655-7d2e-45c0-b437-190e85e97e18" alt=""><figcaption></figcaption></figure>
2. In the window on the right, select "Run Python" and click "Continue."

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FtLewkr5PVs6V0mwN4bEg%2Fimage.png?alt=media&amp;token=b5d2c1a1-1145-4414-a6d2-edde9637e0b3" alt=""><figcaption></figcaption></figure>
3. Now, you need to feel the "Input Data."

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FU6lkVSPUiwP8Kx2tCNxd%2Fimage.png?alt=media&amp;token=5807fe7e-78b3-43b8-892d-da1ec8f8a43c" alt=""><figcaption></figcaption></figure>
4. Paste `raw_data` into the left field, as shown on the screen below

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FNzQqetcF1DHKiNR4Qs2f%2Fimage.png?alt=media&amp;token=edf67d1b-9f0f-4653-beac-90e8426521b4" alt=""><figcaption></figcaption></figure>
5. Click on the "+" button and select "Raw Body"

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FE4HjTCEqToZxm92hJwwN%2Fimage.png?alt=media&amp;token=65bb05e6-6cac-4f3f-886b-09f8bbb04fac" alt=""><figcaption></figcaption></figure>

***

## Structure data

1. Copy and paste the following code in to the "Code" field and click "Continue".

```python
import json

# Load the raw data from input
raw_data = input_data.get('raw_data', '{}')
data = json.loads(raw_data)
    
# Extract survey questions and answers
survey_questions = [answer['question_text'] for answer in data.get('survey_answers', [])]
survey_answers = [', '.join(answer['answer_values']) for answer in data.get('survey_answers', [])]
subject_id = data.get('subject_id', '')

# Create a dictionary mapping questions to answers
questions_answers_mapping = dict(zip(survey_questions, survey_answers))

# Get all face area results
face_area_results = [algorithm for algorithm in data.get('area_results', []) if algorithm.get('area_name') == 'face']

# For Eye Condition - additional metrics are stored as submetrics
eye_area_condition = [result for result in face_area_results if result.get('tech_name') == 'eye_area_condition']
if len(eye_area_condition) > 0:
    eye_area_condition = eye_area_condition[0]['sub_metrics']
    eye_area_condition = [metric for metric in eye_area_condition if 'score' in metric.get('tech_name')]

# Add Eye Condition additional metrics to all metrics
face_area_results += eye_area_condition

# Perform metrics mapping - take only public name and value
metrics_mapping = {
    area['name']: area['value']
    for area in face_area_results
}

# Extract product recommendations (category as key, list of names as values)
recommendations = {}
recommendation_system_result = data.get('recommendation_system_result', {})

# Handle recommended products
for category, products in recommendation_system_result.get('recommended_products', {}).items():
    recommendations[category] = [product.get('name') for product in products]

# Handle featured products
for category, products in recommendation_system_result.get('featured_products', {}).items():
    if category in recommendations:
        recommendations[category].extend(product.get('name') for product in products)
    else:
        recommendations[category] = [product.get('name') for product in products]

# Get event name
event = data.get('event')

# Prepare final output
output = {
    'Questions_answers': questions_answers_mapping,
    'Metrics': metrics_mapping,
    'Subject_id': subject_id,
    'Event': event,
    'Recommendations': recommendations
}
```

2. Click on the "Test step" button.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FJseVT6exhcAA60CgbgEE%2Fimage.png?alt=media&amp;token=94eb2e48-1af1-4479-9e8e-72fc11c454e8" alt=""><figcaption></figcaption></figure>
3. Check the test results and move to the next step.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FkbACQjCUX03Vhu6mhThK%2Fimage.png?alt=media&amp;token=6207c8e0-c126-49a4-99a6-24c2fa376106" alt=""><figcaption></figcaption></figure>

## Handling errors

In rare cases, a photo may take longer than usual to process (more than 60 seconds). In such cases, if you choose the ‘merge webhooks’ option, you will get two webhooks:

* The first webhook will include the results of applications that were completed within 60 seconds. This webhook will contain the parameter `"event": "photo_calculated_by_all_apps_timeout"`
* The second will include all results from all applications. This webhook will contain the parameter This webhook will contain the parameter `"event": "photo_calculated_by_all_apps"`

### Step-by-step guide for handling errors

* Click "Add step"

  <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2F32GHlD5f6qZnruq3eqhC%2Fimage.png?alt=media&amp;token=9f7a2464-94dd-4a1f-bf11-5b2cd3e4cd03" alt=""><figcaption></figcaption></figure>
* Select "Filter by Zapier"

  <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2F5EWhvRtmGV0sdkLs55Es%2Fimage.png?alt=media&amp;token=0bf36e05-a872-426d-ba1d-404654ecc54f" alt=""><figcaption></figcaption></figure>
* Select "Event" as a field<br>

  <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2F0YVzawNe6GQn99JBzrZc%2Fimage.png?alt=media&amp;token=cea192c5-68d4-43e2-a0d8-f000ff37213c" alt=""><figcaption></figcaption></figure>
* Select "(Text) Does not contain"
* Paste `timeout` into the text field
* Now, your Zap will send data to Klaviyo only if the data is complete

## Format the data

{% hint style="info" %}
Skip this step if you do not collect users phone number
{% endhint %}

1. Click on the "+" button on the canvas and select "Formatter" by Zapier

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FV8NNhBwbgXXK8JPJJ046%2Fimage.png?alt=media&amp;token=df5bd320-887b-4e49-8eaf-1baf20591f04" alt=""><figcaption></figcaption></figure>
2. Click on the "Action event" dropdown, select "Numbers," and click "Continue."

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FyFZUF9hkAFolNWdAWyJp%2Fimage.png?alt=media&amp;token=f3a5b5c3-bf4a-4fd5-b146-9107f1f7603e" alt=""><figcaption></figcaption></figure>
3. In the next step, click the "+" icon and select the data item with a phone number from the list. For the format, select "E164" and choose the country code. Click "Continue."

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2F9J9gFdW8ed0T3KFtcaWp%2Fimage.png?alt=media&amp;token=39812686-75e0-488c-87a9-86a5c08368cf" alt=""><figcaption></figcaption></figure>

***

## Send results to Klaviyo

1. Click on the "+" button on the canvas.
2. Type "Klaviyo" in the search field and select it from the search results.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FE5r0lU2N3M39v6qcrcpp%2FKlaviyo%20in%20Zapier.jpg?alt=media&amp;token=6d3d0af5-6640-4e2f-bb12-bec2ba435187" alt="" width="563"><figcaption></figcaption></figure>
3. Click on the "Action event" dropdown and select "Create Profile."

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FavjjuaSxu1q59oE4bwXP%2Fimage.png?alt=media&amp;token=e24d349e-a7cd-436f-b3e9-1db1e7755221" alt=""><figcaption></figcaption></figure>
4. Click on the "Account" and connect your Klaviyo account. Once you connect the account, click "Continue."

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FHT93IDJGDzQGyoGt8hlo%2Fimage.png?alt=media&amp;token=24f6b7bf-01f5-4c66-b4bf-42562410bed3" alt=""><figcaption></figcaption></figure>
5. Now, you need to map all the structured data from the previous step with Klaviyo fields.
   1. Add custom properties to map the skin analysis results

      <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2Fi0UuALUQndyqJ7m9ir1V%2Fimage.png?alt=media&amp;token=2e1f6f39-18ec-421c-bb83-0c78c7815750" alt=""><figcaption></figcaption></figure>
   2. You can either put all the products recommended to the user in one field, or you can put them in several separate fields for each step. In the example, we have shown how to combine all recommended products into one field.\
      ![](https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2Fb2Y2u2dzeE5ImdrgCbcM%2Fimage.png?alt=media\&token=652463a9-7fa3-49b3-afee-30244c66878d)<br>
6. Once you finish mapping, click "Continue" and then click "Test step." Check if new record appears in Klaviyo.

   <figure><img src="https://245161714-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWxBX_zB4FnflOpyBGO%2Fuploads%2FUNEgHaoW2TFeS9CTG6C1%2Fimage.png?alt=media&amp;token=867d95eb-6b4a-4cce-8fd9-59258357aa75" alt=""><figcaption></figcaption></figure>
7. If everything works correctly, click on the "Publish" button.

***

{% hint style="warning" %}
Not a Haut.AI client yet?
{% endhint %}

<a href="https://haut.ai/book-a-demo?utm_source=referral&#x26;utm_medium=saas_docs&#x26;utm_campaign=Docs_SaaS_HautAI" class="button primary" data-icon="user-vneck">Book a demo</a> <a href="https://haut.ai/product/ai-skin-analysis?utm_source=referral&#x26;utm_medium=saas_docs&#x26;utm_campaign=Docs_SaaS_HautAI" class="button secondary" data-icon="external-link">Platform overview on haut.ai</a>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.saas.haut.ai/haut.ai/haut.ai-features/consumer-apps/make-real-time-data-connection-with-external-platforms-via-webhooks/example-of-haut.ai-saas-integration-with-klaviyo-via-zapier-with-the-recommendation-system-2.0.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
