christroutner

Centro API for Generating a Report

Feb 2nd, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     //This function is called by getCampaigns(). It uses the data that has been aggregated into
  2.     //the reportObj object from previous functions to generate a Centro Report.
  3.     function generateReport() {
  4.       debugger;
  5.      
  6.       reportObj.flightDates.today = formatToday();
  7.      
  8.       var reportQuery = {
  9.         "description": reportObj.brandName+'-'+reportObj.flightDates.today,
  10.         "reportType": "CAMPAIGN",
  11.         "aggregation": "DAILY",
  12.         "fromDate": reportObj.flightDates.from,
  13.         "toDate": reportObj.flightDates.today,
  14.         "advertiserId": Number(advertiserId),
  15.         "campaignIds": reportObj.campaigns
  16.       };
  17.      
  18.       var authHeader = 'Bearer '+accessToken;
  19.  
  20.       //Create the FormData data object and append the file to it.
  21.       var webForm = new FormData();
  22.  
  23.       var opts = {
  24.  
  25.         //Main url
  26.         url: 'http://api.sitescout.com/advertisers/reports',
  27.  
  28.         headers: {'Authorization': authHeader},
  29.         //contentType: 'application/x-www-form-urlencoded',
  30.         contentType: 'application/json',
  31.         //processData: false,
  32.         type: 'POST',
  33.         data: reportQuery,
  34.         success: function(data){
  35.  
  36.           debugger;
  37.  
  38.          
  39.  
  40.         },
  41.  
  42.         //This error function is called if the POST fails for submitting the file itself.
  43.         error: function(err) {
  44.           debugger;
  45.           console.error('AJAX request failed with following response: '+err.responseText);
  46.         }
  47.       };
  48.  
  49.       //Execute the AJAX operation.
  50.       jQuery.ajax(opts);
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment