Skip to main content
Glama

create_coupon_code

Generate and assign coupon codes in Klaviyo by specifying a coupon ID and code, enabling targeted marketing campaigns and promotions.

Input Schema

NameRequiredDescriptionDefault
codeYesCoupon code
coupon_idYesID of the coupon

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "code": { "description": "Coupon code", "type": "string" }, "coupon_id": { "description": "ID of the coupon", "type": "string" } }, "required": [ "coupon_id", "code" ], "type": "object" }

Implementation Reference

  • The async handler function that executes the create_coupon_code tool logic, posting to Klaviyo API to create a coupon code.
    async (params) => { try { const payload = { data: { type: "coupon-code", attributes: { code: params.code }, relationships: { coupon: { data: { type: "coupon", id: params.coupon_id } } } } }; const result = await klaviyoClient.post('/coupon-codes/', payload); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error creating coupon code: ${error.message}` }], isError: true }; } },
  • Zod schema defining input parameters: coupon_id and code.
    { coupon_id: z.string().describe("ID of the coupon"), code: z.string().describe("Coupon code") },
  • Registration of the create_coupon_code tool using server.tool, including name, schema, handler, and description.
    server.tool( "create_coupon_code", { coupon_id: z.string().describe("ID of the coupon"), code: z.string().describe("Coupon code") }, async (params) => { try { const payload = { data: { type: "coupon-code", attributes: { code: params.code }, relationships: { coupon: { data: { type: "coupon", id: params.coupon_id } } } } }; const result = await klaviyoClient.post('/coupon-codes/', payload); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error creating coupon code: ${error.message}` }], isError: true }; } }, { description: "Create a new coupon code in Klaviyo" } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ivan-rivera-projects/Klaviyo-MCP-Server-Enhanced'

If you have feedback or need assistance with the MCP directory API, please join our Discord server