Microsoft Advertising
A platform for Microsoft's advertising efforts designed to manage all advertising and reporting for partner advertisers. Previously known as Bing Ads and adCenter.
52 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello! I am a novice, so please bear with me. I am trying to write a script in Google's Apps Script to pull in our Bing Ad data, such as date impressions, clicks, and Campaign name.
I can't seem to pull in the data, I think it may be endpoint url I'm using or the payload I'm sending. I've been trying to read through the documentation, although I am struggling to find a solution. Any advice would be very much appreciated!
I am getting this error: HTTP response code: 302
Here's my code:
function fetchBingAdsData(accessToken) {
var url = "https://bingads.microsoft.com/Reporting/v13";
var payload = {
"Aggregation": "Daily",
"Columns": [
"TimePeriod",
"Impressions",
"Clicks",
"CampaignName"
],
"Filter": {
"DateRange": {
"MinDate": "2024-04-10",
"MaxDate": "2024-04-20"
}
},
"Scope": {
"AccountIds": [""] // Removed for privacy
}
};
var options = {
method: "post",
headers: {
Authorization: "Bearer " + accessToken
},
payload: JSON.stringify(payload),
followRedirects: true // Follow redirects automatically
};
var response = UrlFetchApp.fetch(url, options);
console.log(response.getContentText())
if (response.getResponseCode() == 200) {
var bingAdsData = JSON.parse(response.getContentText());
return bingAdsData;
} else {
throw new Error("Failed to fetch Bing Ads data. HTTP response code: " + response.getResponseCode());
}
}