| 3 | from adcp import test_agent |
| 4 | |
| 5 | async def create_campaign(): |
| 6 | # Calculate dates dynamically - start tomorrow, end in 90 days |
| 7 | tomorrow = datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(days=1) |
| 8 | end_date = tomorrow + timedelta(days=90) |
| 9 | |
| 10 | print(f"Start time: {tomorrow.isoformat().replace('+00:00', 'Z')}") |
| 11 | print(f"End time: {end_date.isoformat().replace('+00:00', 'Z')}") |
| 12 | |
| 13 | result = await test_agent.simple.create_media_buy( |
| 14 | brand_manifest={ |
| 15 | 'name': 'Nike', |
| 16 | 'url': 'https://nike.com' |
| 17 | }, |
| 18 | packages=[ |
| 19 | { |
| 20 | 'product_id': 'prod_d979b543', |
| 21 | 'pricing_option_id': 'cpm_usd_auction', |
| 22 | 'format_ids': [ |
| 23 | { |
| 24 | 'agent_url': 'https://creative.adcontextprotocol.org', |
| 25 | 'id': 'display_300x250_image' |
| 26 | } |
| 27 | ], |
| 28 | 'budget': 30000, |
| 29 | 'bid_price': 5.00 |
| 30 | }, |
| 31 | { |
| 32 | 'product_id': 'prod_e8fd6012', |
| 33 | 'pricing_option_id': 'cpm_usd_auction', |
| 34 | 'format_ids': [ |
| 35 | { |
| 36 | 'agent_url': 'https://creative.adcontextprotocol.org', |
| 37 | 'id': 'display_300x250_html' |
| 38 | } |
| 39 | ], |
| 40 | 'budget': 20000, |
| 41 | 'bid_price': 4.50 |
| 42 | } |
| 43 | ], |
| 44 | start_time=tomorrow.isoformat().replace('+00:00', 'Z'), |
| 45 | end_time=end_date.isoformat().replace('+00:00', 'Z') |
| 46 | ) |
| 47 | |
| 48 | # Check for errors (discriminated union response) |
| 49 | if hasattr(result, 'errors') and result.errors: |
| 50 | print(f"ERROR: Failed to create media buy: {result.errors}") |
| 51 | return |
| 52 | |
| 53 | print(f"SUCCESS: Created media buy {result.media_buy_id}") |
| 54 | print(f"Upload creatives by: {result.creative_deadline}") |
| 55 | print(f"Packages created: {len(result.packages)}") |
| 56 | |
| 57 | asyncio.run(create_campaign()) |