Solution Recipe 17: Troubleshooting Event Data with ChatGPT

Nina Ephremidze
Klaviyo Developer Blog
9 min readFeb 10, 2023

Solution Recipes are tutorials to achieve specific objectives in Klaviyo. They can also help you master Klaviyo, learn new third-party technologies, and come up with creative ideas. They are written mainly for developers & technically-advanced users.

WHAT YOU’LL LEARN: How to troubleshoot the ingested data in Klaviyo using ChatGPT, the brainchild of OpenAI.
More specifically, we will troubleshoot the payload and properties we want to segment in Klaviyo’s UI. Later, we will modify the event data with ChatGPT, so that the nested properties become flattened, which will then let us create segments in Klaviyo.

WHY IT MATTERS: OpenAI is a company that has released AI systems which have gotten a lot of attention from the public in general. Particularly, tools such as ChatGPT are considered to be revolutionary and nearly the invention of the century. ChatGPT has many benefits for people in different fields and what not. It can be an especially handy tool for professionals in the tech industry. The tool helps generate personalized responses to user inquiries, allowing developers to tailor the chatbot to their particular use case, whether it’s debugging the code, troubleshooting errors, and understanding the source code.

LEVEL OF SOPHISTICATION: Moderate

INTRODUCTION

You may have already heard about the release of OpenAI on various news sources, social media, tech channels and may have wondered what the whole hype is about.
First of all, let’s demystify what OpenAI is all about.
OpenAI is a company that focuses on creating Artificial Intelligence tools conducting research in various fields. It aims to contribute to machine learning, robotics, and humanity as a whole.
ChatGPT (short for “Generative Pre-Training Transformer”), the main tool discussed in this blog, is a type of language model developed by OpenAI designed to generate human-like text by predicting the next word in a sequence based on the context of the words that come before it.
ChatGPT — Watch Video

There are a few other tools that are part of OpenAI, such as Playground, DALL-E, and Gym, but in this article, we will be focusing primarily on GPT ( aka chat.openai).

CHALLENGE
Now that you have a general understanding of OpenAI and ChatGPT, let’s see how the tool can be used in relation to Klaviyo and help troubleshoot technical requests.
There are a few ways one can utilize ChatGPT and Klaviyo together. For example, it can help debug one’s code, ask what the given errors mean in Klaviyo and how to change them.
Despite ChatGPT’s Thomas Edison Moment, it doesn’t come without drawbacks. In other words, ChatGPT helps modify and troubleshoot the provided source code, but it is up to a developer to have the fundamental background of how things work in order to be able to fully assess the adequacy of responses and ask the right questions in the prompt.
When experimenting with ChatGPT, make sure to test the output for code, especially before pasting it right away.
Here is one of the code examples shown below:

Create Event Example — Watch Video

INGREDIENTS

You will need the following ingredients in order to troubleshoot with ChatGPT:

  • A Klaviyo account
  • An OpenAI account — sign up while it’s still free
  • Postman/ Terminal/ or Klaviyo SDK if you have a library installed
    Note: I will be using Postman in this blog post
  • The payload you are trying to troubleshoot/debug

Once you have an account for both platforms, head to ChatGPT and type in a random question for fun.

INSTRUCTIONS

What We Are Trying to Solve: Let’s say you made an API call using the create event endpoint to ingest the placed order data into your Klaviyo account (payload below), so you can create a segment, based on the queried properties. However, it looks like the properties you wanted to segment aren’t showing up in the drop-down menu in Klaviyo, despite the success message in Postman.

Let’s ask ChatGPT for help!

Step I

Here is the payload sent via Postman for the Placed Order event:
https://docs.google.com/document/d/1GisFZWGVuSiL9LCQYpK8yACQJD_1F4sPEpvOSvdCjvI/edit
Note: Due to the length of the event data, it’s stored in the google docs above.

Step II

Postman response below shows a success message, meaning that the payload went successfully through.

Now let’s check the queried data in our Klaviyo account to see what it looks like there.

Step III
Below, we can see that the placed order event has been successfully ingested into Klaviyo’s UI.

Step IV

Let’s manually Create a Segment based on the placed order properties passed via the event endpoint for “ProductID”, “SKU”, “ProductName”, and “Quantity” attributes listed in the payload.
It looks like the desired properties we would like to segment by are not showing up in the segment dropdown, despite the fact that Postman showed a success message and we can see those properties in the metrics tab.

Step V
This is a good time to utilize ChatGPT and troubleshoot our code.
As noted earlier, in order to be able to debug the code with ChatGPT, one has to have the prior knowledge of the code/how Klaviyo works, in order to ask ChatGPT the right questions and understand the accuracy of the answers.

After taking a closer look at the properties we wanted to segment, it looks like the way we constructed the JSON payload is that those properties we’d like to segment represent objects in the array, meaning they are nested. In other words, those objects are inside another object.

Here is what ChatGPT answered when I asked why I can’t segment the properties:

“It looks like the properties for “ProductID”, “SKU”, “ProductName”, are nested within the “Items” property, which is in turn nested within the “properties” property.
According to the documentation in Klaviyo, you need to have a top-level property in order to be able to segment the attributes in Klaviyo. This means that, in order to segment based on these properties, we would need to flatten the payload so that all properties are at the top level.”

To paraphrase, instead of having the “Items” property contain an array of objects with nested properties, we would need to separate top-level property for each item property, such as “ProductID_1”, “SKU_1”, “ProductName_1”, etc. for the first item, and “ProductID_2”, “SKU_2”, “ProductName_2”, etc. for the second item.

How do I know?
With the help of OpenAI’s abracadabra magic displayed below

Send Klaviyo event API — 6 January 2023 — Watch Video

When I asked OpenAI to provide the flattened payload it did not generate the entire payload in the response and ended at the shipping address.

ChatGPT helped flatten the entire payload, but the response removed all the required attributes such as profile or ID and left out the curly braces in the payload.

I still couldn’t segment the ProductID, SKU, and ProductName, even though ChatGPT confirmed they are all top-level .

Send Klaviyo event API — 6 January 2023 — Watch Video

“It looks like all of the properties in the payload are top-level. However, the SKU property is nested within the Items array. In order to segment on the SKU property in Klaviyo, you would need to include it at the same level as the other properties, rather than nested within the Items array. You can do this by flattening the structure of the payload, so that each item in the Items array is represented as a separate top-level property. This will allow you to segment on the SKU property in Klaviyo.”

Step VI
After pushing back and asking the question differently to achieve the desired result, ChatGPT was a lot closer to the result, but it didn’t provide the entire payload, skipping the unique id.

Step VII

Several attempts later, ChatGPT provided the finalized results without shortening the event data and flattening the JSON.
As you can see, it took a few attempts and modifications to get there though.

Send Klaviyo event API — 6 January 2023 — Watch Video

Despite some back-and-forth communication and pushback with ChatGPT, the good news is that it can still give an idea for why some properties weren’t segmentable and how to reformat the payload/ make it all top-level.

Step VIII
The final step entailed asking ChatGPT to reformat the event data so that I could directly copy-paste into Postman and use the Create Event endpoint.
At first, the given results weren’t complete.

When copy-pasting the given result into Postman, I got the following generated error: “One of `attributes`, `relationships` or `id` must be included in the request payload.”

I asked ChatGPT to help fix the above error, it did resolve that issue, however another error prevailed. “‘profile’ is a required field for the resource ‘event’.”, meaning that it took out the profile from the payload.

Send Klaviyo event API — 6 January 2023 — Watch Video

After the above error correction by ChatGPT, Postman generated a success message, meaning that the modified payload went through and should have all the properties identified as top-level :

Below is the final version of the payload:
https://docs.google.com/document/d/1BkPWxg0wsaUgVbHrDKezLyYTFkNr2hq8mdo9cMOn9LA/edit

Success message from Postman:

ChatGPT confirming that all the properties are top-level.

Step IX
Let’s see if we can segment all of the properties in Klaviyo UI that we weren’t able to previously.
It looks like we can now segment the SKU, product Name , Product ID properties that were nested before.

CHATGPT LIMITATIONS

  • Limited in the ability to understand context, making it difficult for ChatGPT to answer more open-ended questions
  • Relies heavily on training data to generate accurate responses, making it difficult to personalize the chatbot for each user’s particular needs
  • Still early in its development, so it may suffer from unexpected errors or inaccuracies
  • The data only references up until 2021, so it is recommended to double check Klaviyo’s documentation to ensure developers are following best practices and the most recent information. Especially since we have had new endpoints come out in 2022 and coming in 2023
  • While ChatGPT can answer accurately on most occasions, consult the documentation or developer community if you continue to run into issues using the tool

FINAL THOUGHTS

In this recipe, we learned how to use ChatGPT to troubleshoot code we’d like to ingest in Klaviyo and convert the nested properties into top-level, so they are segmentable in Klaviyo.

The major takeaway from this test is that although incredibly efficient, we still can’t rely blindly on the answers generated by ChatGPT. One would need to have prior knowledge of Klaviyo, have developer experience in order to ensure that the responses are accurate.

By using chatopenai.com, developers can quickly troubleshoot code and debug payloads. As seen in this recipe, ChatGPT can help users flatten payloads to make them segmentable in Klaviyo, enabling users to create more targeted segments and personalize experiences for their customers.

It can certainly help save time and effort when working with Klaviyo and other third-party technologies.

ChatGPT is a powerful tool that can help developers and tech-savvy users troubleshoot code and debug payloads more efficiently.

Overall, ChatGPT is a great tool to have in your arsenal when it comes to troubleshooting code and debugging payloads.
As noted earlier, you still need to have a fundamental knowledge of how the code works, what tools to use, what Postman is, but ChatGPT can certainly help you save time and point you in the right direction in a matter of seconds.

--

--