In this guide, we’ll show you how to integrate ChatGPT, Marketo, and your CRM with an IPaaS solution like Zapier or Workato to automatically generate reports for your sales team, granting them instant insights into MQLs.

Why does this matter?

In sales, context is key. Especially when interpreting how and why a lead has become a Marketing Qualified Lead (MQL).

Yet, too often, the data behind that qualification is buried in layers of engagement metrics, making it very time-consuming for sales reps to decipher and piece together the story on their own.

This solution directly addresses that issue by allowing ChatGPT to analyze lead engagement data and generate a clear, concise summary of their journey toward qualification.

By achieving a deep understanding of each lead’s journey more efficiently, your sales team will always be prepared to have effective and informed conversations that close.

Who is this guide for?

Before we get into the nitty gritty, this guide is designed for those with basic knowledge of Marketo, as well as foundational knowledge in an integration platform of their choice (whether that’s Zapier, Workato, Microsoft Power Automate, etc.)

Let’s get into it!
 

Why IPaaS?

For those who may not know, IPaaS stands for “Integration Platform as a Service”. Integrating ChatGPT with Marketo and our CRM without an IPaaS would’ve involved more manual coding work, AWS, and so on, making this entire process far more tedious.

For that reason, we’ve opted to lean on an integration platform to do some of the heavy lifting. We’re using Zapier, but any other one should get the job done. Your exact IPaaS will likely depend on which one your company has invested in.

And since the terminology, UI, and feature set will differ slightly depending on what you’re using, we’re going to keep this guide IPaaS-agnostic – focusing more on the logic behind the workflow, as well as the code snippets you’ll need at each step.

Here’s a graphic of what the entire workflow will look like at a high level:


 

Step 1: Initial setup in Marketo

Start by creating a “text” field in your Marketo instance and make sure it’s mapped to your CRM for sales team visibility. This is where we’ll house the text summary written by ChatGPT that contextualizes MQLs for sales reps.
 

Step 2: Starting the workflow in your IPaaS

Now, we need to build the workflow that will fill the Marketo text field we just created. Head over to your integration platform and create a new workflow that is triggered by an HTTP request.

This trigger will be our first block in the flow:


 

Step 3: Retrieving data from Marketo

In this step, we’re going to tackle the next three blocks in the workflow:

There are a couple things we need from Marketo to extract lead engagement data that we’ll feed to ChatGPT later.

1) First, we need the Marketo Access Token. This will grant us access to the Marketo API, allowing us to programmatically talk to Marketo to enable the automation of tasks, integrate with other systems, and retrieve data.

Use this code to get the Marketo Access Token:

import requests
import pandas as pd
import json
MUNCHKIN = "EDIT HERE"
client_id = "EDIT HERE"
client_secret= "EDIT HERE"
leadid="EDIT HERE"
sinceDate="EDIT HERE"
gptAPIKey="EDIT HERE"
fieldName="EDIT HERE"
def get_access_token():
    global client_id
    global client_secret
    global MUNCHKIN
    params={'grant_type': 'client_credentials',
            'client_id': client_id,
            'client_secret': client_secret}
    headers={'Accept-Encoding': 'gzip'}
    url="https://"+MUNCHKIN+".mktorest.com/identity/oauth/token"
    response=requests.get(url=url,params=params,headers=headers)
    data=response.json()
    print(data)
    return data['access_token']

 

2) Second, we need the Marketo Paging Token. This is required to use the Activities API, which is used to interact with lead engagement data (opened web pages, attended webinars, etc.) We also use this to define the time frame for pulling engagement data. In Marketo, you can’t select any specific time frame; you can only set a start date (up to 3 months ago) and pull data from there to the present. In our case, we recommend setting that to 1 month ago.

Use this code to get the Marketo Paging Token:

url="https://"+MUNCHKIN+".mktorest.com/rest/v1/activities/pagingtoken.json"
token=get_access_token()
params={'access_token': token,
        'sinceDatetime': sinceDate}
response=requests.get(url=url,params=params)
data=response.json()
nextPageToken=data['nextPageToken']

 

3) Now, we’ll use the two tokens above, plus the lead ID from Step 2, to fetch all the engagement data from a specified back date. This will generate a large string of data that includes all the email interactions, web activity, program status, and more of a lead.

Use this code to fetch lead engagement data:

access_token=get_access_token()
def get_lead_activities(auth_token, lead_id, firstToken):
   url = f"https://"+MUNCHKIN+".mktorest.com/rest/v1/activities.json"
    params = {
        "access_token": auth_token,
        "leadId": lead_id,
        "activityTypeIds": "1,2,3,10,11,34,104",
        "nextPageToken": firstToken
    }
    activities = []
    more_results = True
    while more_results:
        response = requests.get(url, params=params)
        data = response.json()
        if 'result' in data:
            activities.extend(data['result'])
        more_results = data.get('moreResult', False)
        if more_results:
            params["nextPageToken"] = data['nextPageToken']
    return activities
all_activities = get_lead_activities(access_token, leadid,nextPageToken)
all_activities = str(all_activities).replace('"', "'")
activities=all_activities

 

Step 4: Analyze engagement data with ChatGPT

Let’s move on to the final two blocks of the workflow:


 

1) This is where we come up with an appropriate prompt about summarizing how and why a lead became an MQL, then send it to ChatGPT through the GPT-4o API.

Here’s a prompt that produced good results for us:

“Analyze the following lead activities and explain the activities that contributed to this lead being marked as MQL so a salesperson knows how they should approach the client, including which product or service this lead is most interested in and any other relevant insights. Include relevant URLs on form fills:" +activities+" – Remember this will only be read by a salesperson, so don't use technical explanations, just your best summary. Keep your response limited to 100 words.”

 

And use this code to send it to ChatGPT via the API:

def send_to_chatgpt(activities):
    url = "https://api.openai.com/v1/chat/completions"
    headers = {
        "Authorization": gptAPIKey,
        "Content-Type": "application/json"
    }
    prompt = """Analyze the following lead activities and explain the activities that contributed to this lead being marked as MQL so a salesperson knows how they should approach the client, including which product or service this lead is most interested in and any other relevant insights. Include relevant URLs on form fills:""" +activities+""" – Remember this will only be read by a salesperson, so don't use technical explanations, just your best summary. Keep your response limited to 100 words."""
    data = {
        "model": "gpt-4o-mini",
        "messages": [{"role": "user", "content": prompt}],
        "max_tokens": 250
    }
    response = requests.post(url, headers=headers, json=data)
    return response.json()
gpt_response = send_to_chatgpt(activities)['choices'][0]['message']['content']

 

2) Once we’ve prompted GPT, we need to capture the text summary it sends back to us and use an API request to store it in the Marketo text field we created in Step 1.

Use this code to capture and store ChatGPT’s response:

def update_marketo_field(lead_id, field_name, gpt_response):
    url = "https://+MUNCHKIN+.mktorest.com/rest/v1/leads.json?access_token="+str(input_data['access_token'])
    headers = {
        "Content-Type": "application/json"
    }
    payload = {
        "action": "updateOnly",
        "lookupField": "id",
        "input": [
            {
                "id": int(lead_id),
                field_name: gpt_response
            }
        ]
    }
    response = requests.post(url, headers=headers, json=payload)
update_response = update_marketo_field(leadid, fieldName, gpt_response)

 

Step 5: Automate the workflow

In our fifth and final stage, we need to ensure this IPaaS workflow is triggered any time a lead becomes an MQL in our Marketo instance. This is achieved by creating a webhook in Marketo that looks like this:


 

Example response:


 
pink line

And that’s it!

Now, whenever a lead becomes an MQL in Marketo, your IPaaS workflow should be triggered.

This will automatically send a full text summary of why that lead became an MQL to a Marketo text field that is also mapped to your CRM for sales reps to see.

Instant insights into the lead journey will save your sales reps tons of time they’d otherwise spend sifting through metrics to piece together the story.

Ultimately, they’ll be more informed more quickly, so they can have better conversations with prospects and close more sales.

If you need help setting this up or have any other questions, feel free to reach out here.

Recommended: