By following this guide, you will build a working Custom GPT Action that connects ChatGPT directly to your marketing stack, pulling live campaign data and triggering workflows without leaving the chat interface. The setup takes roughly 90 minutes and requires no prior experience with OpenAI's API beyond a basic understanding of REST requests.
What You'll Build
- A Custom GPT with a registered Action that authenticates against an external marketing API
- A lightweight middleware endpoint (deployed on Vercel) that proxies requests from ChatGPT to your tools
- A working example that fetches live campaign metrics from HubSpot and returns a plain-language summary
- An OpenAPI 3.1 schema that describes your Action so ChatGPT knows when and how to call it
Prerequisites
- A ChatGPT Plus, Team, or Enterprise subscription (Custom GPTs require one of these plans as of August 2026)
- A HubSpot account with a private app token (free developer account works)
- Node.js 20+ and pnpm 9 installed locally
- A Vercel account for deploying the middleware (free tier is sufficient)
- Basic familiarity with JSON and REST APIs
Step 1: Understand How Custom GPT Actions Work
A Custom GPT Action is a bridge between a GPT you configure and an external HTTP endpoint. You write an OpenAPI schema that tells ChatGPT what endpoints exist, what parameters they accept, and what they return. ChatGPT decides when to call those endpoints based on the conversation.
The flow looks like this: user sends a message, ChatGPT reads the schema, calls your endpoint with the right parameters, receives the JSON response, and converts it into plain language for the user. Your endpoint does the actual work against HubSpot, Klaviyo, or whichever tool you connect.
This matters because the GPT itself never stores your API credentials. Authentication is handled by your middleware, not by OpenAI's servers.
What if you want to connect multiple tools?
You can define multiple paths inside a single OpenAPI schema. Each path maps to a different endpoint on your middleware server. Start with one tool, get it working, then extend the schema with additional paths for Klaviyo, GA4, or any other API your stack includes.
Step 2: Set Up Your Middleware Project
The middleware is a small Next.js 15 API route that sits between ChatGPT and your marketing tools. It keeps your API keys server-side and handles any data transformation before returning JSON to the GPT.
Create a new project:
pnpm create next-app@latest gpt-action-middleware --typescript --app --no-src-dir --no-tailwind
cd gpt-action-middleware
pnpm add axios
Create the HubSpot route handler at app/api/hubspot/campaigns/route.ts:
import { NextRequest, NextResponse } from 'next/server';
import axios from 'axios';
export async function GET(req: NextRequest) {
const token = process.env.HUBSPOT_PRIVATE_APP_TOKEN;
if (!token) {
return NextResponse.json({ error: 'Missing token' }, { status: 500 });
}
const { data } = await axios.get(
'https://api.hubapi.com/marketing/v3/emails',
{
headers: { Authorization: `Bearer ${token}` },
params: { limit: 10, sort: '-updatedAt' },
}
);
const campaigns = data.results.map((email: any) => ({
id: email.id,
name: email.name,
subject: email.content?.subject ?? 'No subject',
status: email.state,
updatedAt: email.updatedAt,
}));
return NextResponse.json({ campaigns });
}
Add a .env.local file:
HUBSPOT_PRIVATE_APP_TOKEN=your_token_here
Run the dev server to confirm it works:
pnpm dev
Visit http://localhost:3000/api/hubspot/campaigns. You should see a JSON array of your recent HubSpot email campaigns.
What is a common pitfall at this step?
HubSpot's private app tokens have scopes. If you get a 403, open your HubSpot portal, go to Settings, then Integrations, then Private Apps, and confirm the token has the marketing-email read scope enabled. Adding the scope generates a new token, so update your .env.local file.
Step 3: Deploy the Middleware to Vercel
ChatGPT cannot reach your local dev server. You need a public HTTPS URL. Vercel's free tier is the fastest way to get there.
pnpm add -g vercel
vercel login
vercel --prod
During the prompts, accept the defaults. After deployment, Vercel will print a URL like https://gpt-action-middleware.vercel.app. Copy it.
Then add your secret to Vercel so the deployed function can read it:
vercel env add HUBSPOT_PRIVATE_APP_TOKEN production
Paste your token when prompted. Redeploy to apply the environment variable:
vercel --prod
Confirm the live endpoint responds by visiting https://your-vercel-url.vercel.app/api/hubspot/campaigns in a browser.
Step 4: Write the OpenAPI Schema
This schema is what you paste into the Custom GPT Action editor. It tells ChatGPT the shape of your API. Use OpenAPI 3.1 format, which the GPT editor supports as of mid-2026.
Create a file called openapi-schema.yaml in your project root:
openapi: 3.1.0
info:
title: Marketing Stack API
description: Fetches campaign data from HubSpot for analysis.
version: 1.0.0
servers:
- url: https://your-vercel-url.vercel.app
paths:
/api/hubspot/campaigns:
get:
operationId: getHubSpotCampaigns
summary: Get the 10 most recently updated HubSpot email campaigns
responses:
'200':
description: A list of campaigns
content:
application/json:
schema:
type: object
properties:
campaigns:
type: array
items:
type: object
properties:
id:
type: string
name:
type: string
subject:
type: string
status:
type: string
updatedAt:
type: string
Replace your-vercel-url.vercel.app with your actual Vercel domain.
Why does the operationId matter?
ChatGPT uses the operationId to decide which function to call during a conversation. Make it descriptive and unique. If you later add a Klaviyo endpoint, name it something like getKlaviyoFlowMetrics so ChatGPT distinguishes between them correctly.
Step 5: Create and Configure the Custom GPT
Open ChatGPT and go to the GPT builder. Click "Create a GPT" and give it a name like "Marketing Analyst." Write a clear system prompt in the Instructions field. Here is a practical starting point:
You are a marketing analyst assistant. When asked about campaign performance, call the getHubSpotCampaigns action and summarise the results in plain language. Highlight campaigns by status and flag any that have not been updated in the past 30 days. Always present data as a concise bullet list unless the user asks for a table.
Next, click "Add actions" in the left panel. Select "Create new action". In the Schema field, paste the full contents of your openapi-schema.yaml file. The editor will validate the schema and list your endpoint under "Available actions."
Set Authentication to "None" for now. Your middleware does not require ChatGPT to send credentials because the HubSpot token is stored on the server. If you later add user-specific data, you can switch to API key or OAuth authentication using OpenAI's built-in options.
Click "Save" and choose "Only me" or "Anyone with the link" depending on whether this is for personal use or your whole marketing team.
Step 6: Test the GPT in the Preview Panel
Open the preview chat on the right side of the GPT builder. Type a prompt like:
Show me my recent HubSpot email campaigns and tell me which ones are still in draft.
You will see ChatGPT pause briefly, then display a note saying it called getHubSpotCampaigns. The response should summarise your campaign list in plain language based on the JSON your middleware returned.
If you see an error instead, the most common causes are a mismatched server URL in the schema, a CORS issue on the Vercel function, or an expired HubSpot token.
How do you fix a CORS error at this step?
Add a next.config.ts file to your project with the following content, then redeploy:
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
async headers() {
return [
{
source: '/api/:path*',
headers: [
{ key: 'Access-Control-Allow-Origin', value: 'https://chat.openai.com' },
{ key: 'Access-Control-Allow-Methods', value: 'GET, OPTIONS' },
],
},
];
},
};
export default nextConfig;
Step 7: Extend the Schema With Additional Marketing Tools
Once the HubSpot path works, adding more tools follows the same pattern. Create a new route file in your Next.js app, add a new path to the OpenAPI schema, and update the GPT's schema in the Action editor.
Useful extensions for most marketing stacks in Australia, Singapore, Canada, and the US include a GA4 path using the Google Analytics Data API v1, a Klaviyo path using their v2023 REST API, and a Looker Studio export path for pulling report snapshots. Each addition gives your Custom GPT access to another data source without requiring you to copy and paste numbers from dashboards manually.
If you manage content planning alongside campaign data, a well-structured content calendar helps your GPT give more relevant answers. The free Lenka Studio social media toolkit includes a ready-made content calendar template that pairs well with a GPT built to analyse your posting cadence and suggest improvements.
At Lenka Studio, the same approach described here underpins the AI automation workflows we build for SMB clients. Connecting existing tools through a GPT Action layer often reduces the time teams spend pulling reports by 60 to 70 percent, without replacing any of the underlying platforms.
Frequently Asked Questions
Does this work with free ChatGPT accounts?
No. Custom GPTs and Actions require a ChatGPT Plus, Team, or Enterprise subscription. As of August 2026, the free tier does not include GPT creation or Action configuration.
Is my HubSpot data sent to OpenAI when I use this GPT?
Yes. The JSON your middleware returns is sent to OpenAI's servers so ChatGPT can generate the response. Review OpenAI's data usage policy and your organisation's data residency requirements before connecting any personally identifiable information or commercially sensitive campaign data.
How is this different from using a HubSpot ChatSpot integration?
ChatSpot is a HubSpot-native AI assistant tied to HubSpot's own models. A Custom GPT Action lets you combine HubSpot data with data from other tools like Klaviyo, GA4, or your own database in a single conversation, using ChatGPT's general reasoning capabilities rather than a purpose-built HubSpot assistant.
What happens if my Vercel function times out?
Vercel's free tier has a 10-second function timeout. Most marketing API calls complete well within that window. If you are fetching large datasets, add pagination to your route and return only the most recent records, as shown in the example above with limit: 10.
Can I share this GPT with my whole marketing team?
Yes. Set the GPT visibility to "Anyone with the link" or, for Enterprise plans, publish it to your workspace. Every team member who has access will call the same Vercel middleware, so your HubSpot token remains server-side and is never exposed to end users.
Next Steps
You now have a working Custom GPT Action connected to your marketing stack. From here, add a second path to your OpenAPI schema for GA4 or Klaviyo, write a more detailed system prompt that matches your team's reporting language, and explore OpenAI's OAuth authentication option if you need user-level data access.
If you want to take this further and build a full AI automation layer across your marketing, sales, and operations tools, the team at Lenka Studio can help you scope and build it. Get in touch and we can walk through what makes sense for your stack.




