How to pull Bing ad data into Google Sheets

Erik McGovern 0 Reputation points

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 = "";
  var payload = {
    "Aggregation": "Daily",
    "Columns": [
    "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);

  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());

Microsoft Advertising
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.
54 questions
0 comments No comments
{count} votes