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
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Coupon code | |
| coupon_id | Yes | ID 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
- src/tools/coupons.js:36-65 (handler)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 }; } },
- src/tools/coupons.js:32-35 (schema)Zod schema defining input parameters: coupon_id and code.{ coupon_id: z.string().describe("ID of the coupon"), code: z.string().describe("Coupon code") },
- src/tools/coupons.js:30-67 (registration)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" } );