You can pull any data out of Facebook Ads through the Ads Insights API. The Insights API provides access to the analytics and reporting functionality. The way you interact with the data you own is by requesting reports where you define the data and the required granularity.
As in the case of Google, Facebook also exposes a very rich set of APIs that you can use for every aspect of your advertising needs, from creating ads programmatically to see how your campaigns perform.
In this post, we'll focus only on how to extract data out of Facebook Ads; for further information on what else can be performed through the Facebook Ads related APIs, you can check the documentation of the Marketing API.
The Facebook Marketing API is a RESTful web API and thus can also be accessed by performing requests directly to the appropriate endpoints. As a RESTful API, interacting with it can be achieved by using tools like CURL or Postman or by using HTTP clients for your favorite language or framework. A few suggestions are as below:
As with everything in Facebook, Ads and their statistics are part of the Graph API, which you can interact with also using the Graph Explorer, and there's a special edge that you can use to request your Ads' statistics; it's the insights edge.
Insights can be accessed from the following list of edges:
The response from each contains information belonging to the ad object for which insights are queried.
For example, let's assume that you would like to extract all stats related to your account. You could do this by executing the following request using CURL:
curl -F 'level=campaign' -F 'fields=' -F 'access_token=<ACCESS_TOKEN>' https://graph.facebook.com/v2.5/<CAMPAIGN_ID>/insights curl -G -d 'access_token=<ACCESS_TOKEN>' https://graph.facebook.com/v2.5/1000002 curl -G -d 'access_token=<ACCESS_TOKEN>' https://graph.facebook.com/v2.5/1000002/insights
Data can be returned in either XLS or CSV format, and when the report is ready based on your request, you can access it from a URL like the following: