Shopify Video API: Generate Product Videos from Webhooks | agent-media
Use Case
Register a product.create webhook in Shopify, receive the payload, and call the agent-media API to generate a talking-head video for each new product automatically. TypeScript SDK, Python client, and CLI supported. Read the docs.
Webhook Handler: Next.js / Express
Receive Shopify products/create events and trigger video generation. This example uses a Next.js API route, but any framework that handles POST requests works.
{'// Verify the Shopify HMAC header in production'}
import {'{'}{' '}
AgentMedia {'}'} from{' '}
"agent-media";
import {'{'}{' '}
NextResponse {'}'} from{' '}
"next/server";
const client ={' '}
new AgentMedia(
process.env.AGENT_MEDIA_API_KEY!);
export async function{' '}
POST(req: Request) {'{'}
{' '}
const product ={' '}
await req.json();
{' '}
const video ={' '}
await{' '}
client.videos.create({'{'}
{' '}script: product.body_html,
{' '}actor: "emma",
{' '}brollImages: [product.image?.src],
{' '}style: "clean",
{' '}duration: 10,
{' '}template: "product-demo",
{' '}{'}'});
{' '}
return{' '}
NextResponse.json({'{'} videoId: video.id {'}'});
{'}'}
TypeScript SDK: Generate a Product Demo Video
Use the SDK directly when you need more control -- poll for completion, attach metadata, or upload the result back to Shopify via the Admin API.
import {'{'}{' '}
AgentMedia {'}'} from{' '}
"agent-media";
const client ={' '}
new AgentMedia(
process.env.AGENT_MEDIA_API_KEY!);
const video ={' '}
await{' '}
client.videos.create({'{'}
{' '}aiScript: "Organic bamboo cutting board, 14x10
inches, knife-friendly surface",
{' '}template: "product-demo",
{' '}actor: "emma",
{' '}brollImages: [
"https://cdn.shopify.com/s/.../bamboo-board.jpg"],
{' '}style: "clean",
{' '}duration: 10,
{'}'});
{'// Poll until ready'}
const result ={' '}
await{' '}
client.videos.wait(video.id);
console.log(result.url);{' '}
{'// '}https://media.agent-media.ai/videos/abc123.mp4
Python: Batch Process Your Catalog
Pull products from the Shopify Admin API and generate videos for every SKU in a single script.
import shopify
import agent_media
client = agent_media.Client(api_key=os.environ[
"AGENT_MEDIA_API_KEY"])
products = shopify.Product.find()
for product{' '}
in products:
{' '}video = client.videos.create(
{' '}ai_script=product.body_html,
{' '}template="product-demo",
{' '}actor="emma",
{' '}broll_images=[product.image.src],
{' '}style="clean",
{' '}duration=10,
{' '})
{' '}print(f"{'{'}product.title{'}'}: {'{'}video.id
{'}'}")
CLI: One-Off or Scripted
Generate a single product video from the command line, or wrap it in a shell loop for quick batch runs.
# Generate a single product video
$ agent-media video
create \
{' '}--ai-script "Organic bamboo cutting board, 14x10
inches, knife-friendly surface" \
{' '}--template product-demo \
{' '}--actor emma \
{' '}--broll-images
"https://cdn.shopify.com/s/.../bamboo-board.jpg" \
{' '}--style clean \
{' '}--duration 10 --sync
# Batch: loop over a CSV of products
$ while IFS=, read -r
name desc img; do
{' '}agent-media video create --ai-script "$desc"
--actor emma \
{' '}--broll-images "$img" --template
product-demo --style clean
{' '}done < products.csv
Set Up the Webhook in Shopify Admin
Register the webhook so Shopify sends product data to your endpoint automatically.
In your Shopify admin, navigate to{' '}
Settings →{' '}
Notifications{' '}
and scroll to the Webhooks section at the bottom.
Click Create webhook.
Set the event to{' '}
Product creation
, format to JSON, and enter your endpoint URL (e.g.{' '}
https://yourapp.com/api/shopify/webhook
).
Shopify signs every webhook with an HMAC header. Verify it
against your app's secret to ensure the payload is
authentic. See the{' '}
docs
{' '}
for a verification helper.
Create a test product in Shopify. Your webhook fires,
agent-media generates the video, and you get the video URL
back. Poll{' '}
client.videos.get(videoId)
{' '}
or use the{' '}
--sync
{' '}
flag in the CLI to wait for completion.
Why Developers Choose agent-media
Related Pages
Last updated: April 2026