MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / createMediaBuy

Function createMediaBuy

server/tests/unit/comply-test-controller.test.ts:53–91  ·  view source on GitHub ↗

Create a media buy and return its ID.

(server: ReturnType<typeof createTrainingAgentServer>)

Source from the content-addressed store, hash-verified

51
52/** Create a media buy and return its ID. */
53async function createMediaBuy(server: ReturnType<typeof createTrainingAgentServer>): Promise<string> {
54 // Get a valid product first
55 const { result: products, isError: productsError } = await simulateCallTool(server, 'get_products', {
56 buying_mode: 'wholesale',
57 account: ACCOUNT,
58 brand: BRAND,
59 });
60 if (productsError || (products as any).errors) {
61 throw new Error(`get_products failed: ${JSON.stringify(products)}`);
62 }
63 const productList = (products as any).products || [];
64 const product = productList[0];
65 if (!product) throw new Error('No products in catalog');
66
67 const pricingOption = product.pricing_options[0];
68 if (!pricingOption) throw new Error(`No pricing options for product ${product.product_id}`);
69
70 const now = new Date();
71 const endTime = new Date(now.getTime() + 30 * 24 * 60 * 60 * 1000);
72
73 const { result, isError } = await simulateCallTool(server, 'create_media_buy', {
74 idempotency_key: crypto.randomUUID(),
75 account: ACCOUNT,
76 brand: BRAND,
77 start_time: now.toISOString(),
78 end_time: endTime.toISOString(),
79 packages: [{
80 product_id: product.product_id,
81 pricing_option_id: pricingOption.pricing_option_id,
82 budget: 10000,
83 }],
84 });
85 if (isError || (result as any).errors) {
86 throw new Error(`create_media_buy failed: ${JSON.stringify(result)}`);
87 }
88 const mediaBuyId = (result as any).media_buy_id;
89 if (!mediaBuyId) throw new Error(`No media_buy_id in response: ${JSON.stringify(result)}`);
90 return mediaBuyId;
91}
92
93/** Sync a creative and return its ID. */
94async function syncCreative(server: ReturnType<typeof createTrainingAgentServer>): Promise<string> {

Calls 1

simulateCallToolFunction · 0.70

Tested by

no test coverage detected