I'm looking to download a CSV from my api call to FB ads, I've set it in the parameters as per the code below, the call works fine but I only get a paginated JSON as a response. I'm not quite sure how to access the CSV report, the response doenst give me any report ID or download link. How can I download this CSV?
Using nodejs facebook-nodejs-ads-sdk image showing the parameter information 'export_format' Documentation: https://developers.facebook.com/docs/marketing-api/reference/adgroup/insights/
var getReport = function(){
console.log("API for FB report has been called")
let ads_insights;
let ads_insights_id;
const logApiCallResult = (apiCallName, data) => {
console.log(apiCallName);
if (showDebugingInfo) {
console.log('Data:' + JSON.stringify(data));
}
};
const fields = [
'ad_name',
'impressions',
'reach',
'spend'
];
const params = {
'export_format': 'csv',
'export_name': new Date() + 'fb-download',
'level' : 'ad',
'filtering' : [],
'breakdowns' : [],
'time_range' : {'since':'2018-01-22','until':'2018-01-23'}
};
new AdAccount(ad_account_id).getInsights(
fields,
params).then((result) => {
logApiCallResult('ads_insights api call complete.', result);
console.log("##########" + result + "#####")
ads_insights_id = result[0].id;
}).catch((error) => {
console.log(error);
});
}
Extract data from Facebook Ads. You can pull your data from Facebook Ads through the Ads Insights API. The Insights API provides access to analytics and reporting functionality and the way you interact with your data is by requesting reports where you define exactly the data and its granularity that you need.
The Marketing API is an HTTP-based API that you can use to query data, create and manage ads, and perform a wide variety of other tasks. The Marketing API can programmatically access Facebook's advertising platform and optimize your business operations.
Exporting actual report files doesn't seem to be a part of the official Facebook Graph API.
My solution was to make a GET request to the following endpoint:
https://www.facebook.com/ads/ads_insights/export_report/?report_run_id=<REPORT_RUN_ID>&name=<REPORT_FILE_NAME>&format=csv&access_token=<FACEBOOK_API_KEY>
Please note that this endpoint will output a file with columns that constantly change without warning, so its not good for automated data collection. The only way to export standardized reports is in the JSON format.
The docs for this endpoint are sort of hard to find: located here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With