Integrating ChatGPT with Marketo

Level 9 - Champion Level 9 - Champion
Level 9 - Champion

AI tools have exploded in popularity since 2023 and there is not one industry or job role that does not have the opportunity to be improved using these tools. In this blog post, I will show you how we can use ChatGPT in marketing operations use cases to classify leads created in Marketo and to identify bot formfills.


We will be using webhooks and the Zapier automation tool to query ChatGPT for the classification of new leads created in Marketo and then update these new leads with this classification.



Making ChatGPT Requests Using Zapier


Filtering Leads Sent to Zapier


As we will see in the next section, we will be using the “New Lead” trigger within the Marketo app in Zapier. If you want to classify every lead created in your Marketo instance then you do not need to do anything within Marketo.


However, if you want to selectively classify leads in Marketo then you will need to set up a smart campaign to add these leads to a static list and then select this list in Zapier (see next section) so that only leads added to this list will be sent to Zapier for classification.


For example, you might not want to send freemails to Zapier for classification since ChatGPT will likely not be able to find much about these people. Additionally, you can also use constraints on the “Person is Created” trigger to only classify people created from certain forms or lists or who are created with a certain “Person Source”.




Smart list criteria to determine who gets added to the list


Adding people to the static list


Classifying Leads using Zapier & ChatGPT




Zapier workflow for lead classification


The “New Lead” event is used in the Marketo app in Zapier to trigger our classification workflow. As shown in the image below this zap will only trigger for leads added to the “Score with GPT” list in Marketo. We also have the opportunity here to specify any additional fields that we want to be available for the lead that triggers the zap. By default, only the lead’s email, first name, and last name will be pulled in for this trigger.




Configuration to only trigger when people are added to a list


All the information we requested about the lead is then included in our prompt sent to ChatGPT. If you have not connected your ChatGPT account to Zapier yet then you will need to get an API key from your account to complete setup.




Including lead information from Marketo in a ChatGPT prompt


Don’t be intimidated that there is a Python step in this Zap! As shown in this GPT chat we can actually use ChatGPT to generate the Python code to extract the classification and reason and then all we have to do is copy this code into the Code by Zapier action.

Finally, once we have extracted the fit and reason we can use the “Create/Update” lead action to update the lead by populating their lead quality fields with the GPT classification and reason.




Updating the lead in Marketo with the GPT classification

Making ChatGPT Requests Using Webhooks



As shown in the Webhook Guide with Examples blog post we can also use webhooks in Marketo to make API requests and that means we can make requests to ChatGPT via API from within Marketo.


Webhook to make ChatGPT API Requests


As specified in the ChatGPT API docs we will make a POST request to the “completions” endpoint containing the model we want to use and the message content.



  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "Hello!"}]


As shown in the image below we can use lead tokens within the payload template to send information about a Marketo person to ChatGPT for evaluation. Contrary to making ChatGPT requests in Zapier, as shown in the section above, we do not have an easy way in Marketo of parsing the response returned from ChatGPT so we have to tell ChatGPT to give us very specific answers that we can map directly to Marketo fields.




Webhook configuration in Marketo to make an API request to ChatGPT


Next, we need to specify custom headers for the webhook. You can get your API key from your ChatGPT account here.


Authorization: Bearer xxxContent-Type: application/json


Configuring custom headers for the ChatGPT API request


The final part of the webhook configuration is to map the response from ChatGPT to a field in Marketo so that the value can be stored. Looking at the response structure from the ChatGPT request we can see that in order to reference the message content we need to access the first index (index 0 since counting starts at 0 instead of 1) of the choices array parameter, then the message parameter, and finally the content parameter.


  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "\n\nHello there, how may I assist you today?",
    "finish_reason": "stop"
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21


Storing the response from ChatGPT in a Marketo field

Using the ChatGPT Webhook


Now that you have the webhook configured to make API requests to ChatGPT you can start using this webhook within your smart campaigns in Marketo.


When you go to the activity log of a lead you will be able to click into the “Call Webhook” action to see the detail of the API request sent from Marketo to ChatGPT as well as the response returned from ChatGPT. Similarly, you can click into the “Change Data Value” activity to see that the reason the person’s field value was updated was because of the ChatGPT webhook.




Activity log showing the webhook and change data value actions



Details of the ChatGPT API request sent from Marketo



Lead classification field updated with value from ChatGPT

Identifying Bot Formfills Using ChatGPT



Check out the video below to see how to use Marketo webhooks to send form-fill information to ChatGPT to determine whether the form-fill was made by a bot.



Here is a link to the Google Sheet that I use for iteratively testing prompts and below is the prompt I found most effective at identifying bot form fills.


  "model": "gpt-4",
  "messages": [{"role": "user","content": "Given this information submitted to the Telnyx contact sales form please classify this form submission as either “[Genuine]” where it looks like the form was submitted by a human or “[Bot]” where it looks like it was submitted by a robot and the fields contain strings of consecutive random characters. Give a reason for your choice. Please format your answer like so: [[Classification]|[[Reason]]. Please note that the form information has been URL encoded so you will need to decode the content before making your assessment.Full Name: {{lead.Full Name}}, Email: {{lead.Email Address}}, Company Name: {{company.Company Name}}, Phone: {{lead.Form - Phone}}, Website: {{company.Website}}, Additional Information: {{lead.Form - Additional Information}}"}]


1 Comment