Miscellaneous topics that do not fit into specific categories.
Dear confidanto,
Thank you for reaching out to the Microsoft Q&A Forum.
The error "The request message is null" indicates that the Bing Ads API is not receiving your request body properly.
There are some issues with your code:
- Wrong endpoint URL - You're using
/GenerateReport/Submitinstead of/Reports/SubmitGenerateReport - Incorrect header format - Missing required headers
- Wrong body structure - Using SOAP-style structure instead of REST
Here is the fixed code:
import requests
import time
ACCESS_TOKEN = "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwia2lkIjoiZ0lpZlY5OHcwRjZkQW8ydTFXa05oZzBZYWRFMkg4a0dVb1BHcUVnazJ3dyIsInppcCI6IkRFRiJ9..WBaWKsMxkuInnjK5HC5uNA.9cBWynADp_D46C3R9P65IiPjl2ZjlN8cl1S5H-cms3bUs72IINdem2w_ZpSozWYUIYZewi8kYbhPcIjE-7R5ClWGUSXx7uWNdb_ptStwxL2FgZNm-ocgJKPAqSkd8s4HBOewBL1lqzyqaSQ7lHZdweNAzEhLq_yGqiGeQJfEszDyjQHPlG3NOVg4vtQd4C4fJsML74RQnJLZTjeflIfmj7mBetU6toqlmzyqmNFcLfRL4ox2RgoW2_KRki25FFGH4aIe8Cnh38Nn-zhGcW8FfMsysgNLSzfCwpzyuCKY7qJTokfno4cq1-OnGbU79Pt6XGYuoYei4LtZ1hWRYfYPgXzMPg-yRh1R0g0r2ACl4RM1s-4e0IBkc9bioCAt2ckKXH_RfPdWn65Yd7VfbBYGTUVOolkfeQpUaHa34EY2JpZRVFVwEgpLrsBFme8-13Y-CjU52YB4G8-QGix66kQ-TBS55FjXmyYXWW8yF8_rSy9_ri76X41-J_wFPdPYKOZrooPMXRHLkB2WHbeY9gy8NYHHqh_1MwzPNFh9Qk2W6-AMUszc92TWoNqPu28Vc6tR0AvLBMRh78Zs8XrkTzkzjSI8bRPkYqRXucl0pwe4TnVBQlVjeMP_kX6MKILf0lUO2E4z73JqB7uYS9AannTJaWDJp-lB_pWLMkB39lgdq-UOr2rg5Ow_CPFwwhpr0Vw86LYlaj0NOMbeopm6pxsffWF_zgBXPKmFVv1fiBwgSv-mc_n6_E28QMbNaKzCqlITUiaSl_Vl-SsRM64SCpKuLLIeqXWUnWklw6rilFUohGLy349BQRQnHGVeZWHdVYHVSluSNYQpu7j5yYrhqeNo3DlnK_AO8Pni2BQvtKP588GKS6q00kILho9r2iwna6XDI6A4nPObryGaYxKviSp6TlBAtvyYMwkqYf5No7a3mzQr4TAam47r9_4BYqMdvbCHWYGtgq9_E3n1vwdS8Uj4kJCm7xXXJTX1uxDQMhSz3S9pQwgtoNZyWCUD1Ym8BjTOOd4l45VIaOc5W5qEQoJboMthBaXlH2E5zlAvQCTfnqSLv0o3fdUNgiPeRp6FNRcLAE5rQO0Ho5yrQdfsqO8WMc-WI05PoHKiHpzafORIBtXLCGdbxG0RLHjb9Nf_TUok9Olj_KWcWzvwX1XkzvMTIyq4aXMm42RE4RzmODISNIwQ2V26KTaVjEKClu0qTaAGa3-aTq99vVABLfKWogEglEVm8dZg6-MwwGOApaQrEV5nFLcPu8b0jg2ntPXs6wrbf1nllR40ShTmTsxVPMRNxNGHdJvry21G0aLe1EaAA8eTtajMkQCb2h_D4Rtqagjk_5Vc-f-Vj8qYCExbe_LH_SqOk0lMd2Kt5CUyUOquDslpenSMNlZ0kzyZ2arkc3mvQK8vVQY35ESW8xmCwk19iYk02OFE2Nly7jJE2yZu7qQfTZeupiKI_Rl1YujiyCp5.TnwN2d1pB1BN__0a38d-UWrS3tCA6rm40gqoYyK_2QU"
DEVELOPER_TOKEN = "10712KL49V334137"
CUSTOMER_ID = "253889040"
ACCOUNT_ID = 138763727
# Correct headers format
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"DeveloperToken": DEVELOPER_TOKEN,
"CustomerId": CUSTOMER_ID,
"AccountId": str(ACCOUNT_ID),
"Content-Type": "application/json"
}
# Step 1: Submit Report - CORRECT ENDPOINT
submit_url = "https://reporting.api.bingads.microsoft.com/Reporting/v13/Reports/SubmitGenerateReport"
# Correct body structure for REST API
body = {
"ReportRequest": {
"Format": "Csv",
"Language": "English",
"ReportName": "Campaign Performance Report",
"ReturnOnlyCompleteData": False,
"Aggregation": "Daily",
"Columns": [
"TimePeriod",
"AccountName",
"CampaignName",
"CampaignId",
"Clicks",
"Impressions",
"Ctr",
"AverageCpc",
"Spend",
"Conversions"
],
"Scope": {
"AccountIds": [ACCOUNT_ID]
},
"Time": {
"PredefinedTime": "Last30Days"
}
}
}
print("🟢 Submitting report request...")
print(f"Headers: {headers}")
print(f"Body: {body}")
try:
submit_response = requests.post(submit_url, headers=headers, json=body, timeout=30)
print(f"Submit Status: {submit_response.status_code}")
print(f"Submit Response: {submit_response.text}")
if submit_response.status_code != 200:
raise Exception(f"Submit failed with status {submit_response.status_code}")
submit_json = submit_response.json()
print(f"Submit JSON: {submit_json}")
# Extract report request ID from correct path
report_request_id = submit_json.get("ReportRequestId")
if not report_request_id:
raise Exception("No ReportRequestId found in response")
print(f"✅ Report Request ID: {report_request_id}")
# Step 2: Poll for report
poll_url = "https://reporting.api.bingads.microsoft.com/Reporting/v13/Reports/PollGenerateReport"
for attempt in range(12):
print(f"⏳ Polling attempt {attempt + 1}/12...")
poll_response = requests.post(
poll_url,
headers=headers,
json={"ReportRequestId": report_request_id},
timeout=30
)
print(f"Poll Status: {poll_response.status_code}")
if poll_response.status_code == 200:
poll_json = poll_response.json()
print(f"Poll JSON: {poll_json}")
status = poll_json.get("ReportRequestStatus", {}).get("Status")
if status == "Success":
download_url = poll_json["ReportRequestStatus"].get("ReportDownloadUrl")
if download_url:
print("✅ Report ready! Downloading...")
# Step 3: Download CSV
csv_response = requests.get(download_url, timeout=30)
if csv_response.status_code == 200:
print("📊 CSV Data:")
print(csv_response.text)
break
else:
raise Exception(f"Download failed: {csv_response.status_code}")
else:
raise Exception("No download URL found")
elif status in ["Pending", "InProgress"]:
time.sleep(5)
continue
else:
raise Exception(f"Report generation failed with status: {status}")
else:
print(f"Poll failed: {poll_response.text}")
time.sleep(5)
else:
raise Exception("Report generation timeout")
except requests.exceptions.RequestException as e:
print(f"❌ Request error: {e}")
except Exception as e:
print(f"❌ Error: {e}")
I hope this could help. If you have any further issues, I'm very happy to assist.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.