To help you build a production-ready integration, here is a Python automation script. This script follows the campaign lifecycle we've discussed: from creating a campaign to checking its real-time performance.
DOOH Campaign Automation Script (Python)
This script uses the requests library to handle both JSON data and file uploads.
Python
import requests
import time
# --- CONFIGURATION ---
BASE_URL = "https://api.dooh.one/api/v2"
AGENCY_ID = "2" # Replace with your actual Agency ID
TOKEN = "YOUR_ACCESS_TOKEN"
HEADERS = {
"x-authorization": f"Bearer {TOKEN}",
"x-adexchange-role": "dsp"
}
def run_campaign_workflow():
# 1. CREATE CAMPAIGN DRAFT
campaign_data = {
"name": "Automated Flash Sale",
"payment_model": "ad_plays",
"budget": 100.00,
"max_bid": 0.50,
"ad_duration": 10
}
req = requests.post(f"{BASE_URL}/agency/{AGENCY_ID}/dsp/request/", json=campaign_data, headers=HEADERS)
campaign_id = req.json().get("id")
print(f"✅ Campaign Draft Created! ID: {campaign_id}")
# 2. UPLOAD CREATIVE (Multipart/Form-Data)
# The '@' in curl is handled by the 'files' dictionary in Python requests
files = {'file': open('promo_video.mp4', 'rb')}
ad_payload = {
"campaign_id": campaign_id,
"name": "Vertical Promo v1",
"type": "video",
"duration": "10.0",
"resolution": "1080x1920",
"screen_resolution": "1080x1920"
}
ad_req = requests.post(f"{BASE_URL}/agency/{AGENCY_ID}/dsp/ad/", data=ad_payload, files=files, headers=HEADERS)
ad_id = ad_req.json().get("id")
print(f"✅ Video Uploaded! Ad ID: {ad_id}. Status: {ad_req.json().get('status')}")
# 3. ACTIVATE CAMPAIGN
# Note: In a real scenario, you'd wait for 'approved' status first.
activate_data = {"status": "active"}
requests.patch(f"{BASE_URL}/agency/{AGENCY_ID}/dsp/request/{campaign_id}/", json=activate_data, headers=HEADERS)
print(f"🚀 Campaign {campaign_id} set to ACTIVE.")
# 4. MONITOR RESULTS
print("📊 Fetching latest report...")
report = requests.get(f"{BASE_URL}/agency/{AGENCY_ID}/dsp/request/{campaign_id}/report/", headers=HEADERS)
print(f"Current Spend: {report.json().get('total_spent')} {report.json().get('currency')}")
if __name__ == "__main__":
run_campaign_workflow()
Final Implementation Checklist
Before handing this over to a customer or using it yourself, keep these "Technical Truths" in mind:
Error Handling: Always check if
req.status_code == 201(for creation) or200(for updates). If the agency balance is empty, the PATCH request to "active" will return an error.Media Hosting: In the Python example, the file
promo_video.mp4must be in the same folder as the script.The Audit Gap: Remind customers that Step 2 and Step 3 are usually separated by a few hours. A script should ideally poll the
/dsp/ad/{id}/endpoint until the status is"approved"before sending the"active"command.
Comments
0 comments
Please sign in to leave a comment.