Search API Connector Documentation
Import Facebook Ad Data to Google Sheets
In this guide, we’ll walk through how to pull Facebook ad data from the Facebook Marketing Insights API directly into Google Sheets, using the API Connector add-on for Google Sheets.
There are 2 ways to connect to the Facebook Ads API:
- Preset “Connect” button (OAuth) premium
- Personal access token. Please check the appendix for detailed instructions to retrieve your token.
Contents
- Before You Begin
- Part 1: Connect to the Facebook Ads API
- Part 2: Fetch Data from Facebook Ads
- Part 3: Handle Filtering
- Part 4: Create a Custom Request
- Part 5: Handle Actions
- Part 6: Handle Pagination
- Part 7: API Request URL Builder
- Part 8: API Documentation & Resources
- Appendix: Connect with an Access Token
Before You Begin
Click here to install the API Connector add-on from the Google Marketplace.
Part 1: Connect to the Facebook Ads API
The easiest way to get started with the Facebook Ads API is through API Connector’s built-in integration.
- Select Facebook Ads from the drop-down listof applications
- Under Authorization, click Connect to Facebook Ads
- You will be directed to Facebook and asked to approve the connection. Click Done.
- You’ll then be returned to your Google Sheet, and can verify that your Facebook Ads connection is now active.
Part 2: Fetch Data from Facebook Ads
Now that we’re connected, let’s pull some data into Sheets.
- Select the
/act_{account_id}/insights
endpoint, , which allows us to retrieve Facebook ad insights data. - Under Path parameters, enter your account ID. Get your account ID as described here, or you can retrieve it by running a request to the
/me/adaccounts
endpoint. - Optionally select any request parameters to customize your request. Request parameters include the fields in your report, dates, sorting, and so on.
- Choose a destination sheet, name your request, and hit Run. A moment later you’ll see the response data in your sheet.
Part 3: Handle Filtering
Use the filtering
parameter to filter for specific data points or conditions.
When you add a filter, there are eight available operators: CONTAIN
, EQUAL
, GREATER_THAN
, IN, LESS_THAN
, NOT_CONTAIN
, NOT_EQUAL
, and NOT_IN
.
CONTAIN
,NOT CONTAIN
: filter for text stringsEQUAL
,NOT_EQUAL
: filter for exact matches (strings or numbers)GREATER_THAN
,LESS_THAN
: filter for numerical conditionsIN
,NOT_IN
: filter for multiple values in an array. For example, if your request includes theactions
field, you can include a filter for just the actions of interest (otherwise all actions will be returned). Action filters can be added like this:action_type IN ["link_click","post_reaction"]
Part 4: Create a Custom Request
Alternatively, you can run your own custom requests instead of using API Connector’s pre-built integration. To create a custom request, add your complete URL into the Request URL field, and choose Facebook Ads from the OAuth menu.

You can check Facebook’s API documentation or use this sheet to manually construct Facebook Ads API URLs.
In a custom request, action filters will be included like this:
https://graph.facebook.com/v13.0/act_YOUR_ACCOUNT_ID/insights?fields=actions,reach,impressions,clicks,cpc,spend&filtering=[{field: "action_type",operator:"IN", "value":["offsite_conversion.fb_pixel_purchase","offsite_conversion.fb_pixel_add_to_cart"]}]
Part 5: Handle Actions
“Actions” (aka results or conversions) may include purchases, leads, link clicks, outbound clicks, post engagement, video views, etc. These actions are retrieved by including fields=actions
in your query.
The Facebook API response combines all actions into a single field, which is usually inconvenient for reporting. Therefore, API Connector automatically flattens each action into its own column using a configuration option located at Output options > More options > Flatten field to header
By default, this setting will be applied to all requests using the Facebook Ads OAuth connection.
For more information on flattening fields, please see this article: Flatten Fields to Columns
Part 6: Handle Pagination
- By default Facebook limits the number of results in a single response (usually to 25 records) as described here. To get more records, set the limit parameter to 5000.
- If you need more records after that, you can loop through them using pagination handling (paid feature).
- Pagination type:
cursor
- Next token parameter:
after
- Next token path:
paging.cursors.after
- Run until: choose when to stop running the request
- Pagination type:
Part 7: API Request URL Builder
This is a convenient tool for easily building custom Facebook API request URLs. Just select your dates and parameters.
Once you’ve constructed your URL, you can copy and paste it into API Connector’s custom request URL input field. Here’s the link: Facebook API Request Builder
Part 8: API Documentation & Resources
- Official API documentation: https://developers.facebook.com/docs/marketing-api/insights/parameters
- This is a good blog article containing additional examples and information about the API.
Appendix: Connect with a Facebook API User Access Token
- Begin by navigating to https://developers.facebook.com/, and click My Apps.
- Click Add a New App.
- Facebook will ask you to choose an app type. Select Business and click Next.
- Finally, enter your app details. You can name your app anything as long as it doesn’t include terms related to Facebook. Click Create App.
- You’ll be directed into your Developer dashboard. Under the heading “Add Products to Your App”, scroll down to Marketing API and click Set Up.
- On the left sidebar, you’ll now see Marketing API listed under Products. Click Tools.
- This will produce a screen where you can select your token permissions. All the example API requests in this article use the “ads_read” permission, which allows you to read ads reports from the Ads Insights API for ad accounts you own or have been granted access to by the ad account owner. Click Get Token.
- You’ll now see your access token. Copy it down and keep it safe as they won’t show it again. Congrats, you can now access the Facebook Advertising API!
- Now that you have your token, you can use it by appending
access_token=YOUR_ACCESS_TOKEN
to any API URL, e.g.https://graph.facebook.com/v13.0/act_123456789012345/insights?fields=clicks,cpc,spend&access_token=YOUR_ACCESS_TOKEN
. Since you’re manually including a token, leave OAuth2 authentication set to None.
Is there a way how to get the daily breakout of performance and show the corresponding day for the data in each row? My request is working however, I am not able to pull in the specific date of each row (ad performance for a specific day within the time range), I only have date_start, date_stop (the first and last days of the whole time period).
Thanks!
Sure, just add
&time_increment=1
to your query.Thanks Ana, that worked perfectly
Hi, how ca I breakdown for gender
This should work:
&breakdowns=["gender"]
Great article! Would it be unwise to use this to pull in info from two different fb users? I’m thinking it might not be a good idea to show facebook a link between the two separate users/accounts so they don’t suspect something fishy is going on? Could they know two APIs are linked to the same Google sheet??
I don’t really have any idea what Facebook is looking at, or if they even can tell that the API is being pulled from a Google Sheet, but I would be very surprised if this is an issue. Many agencies & companies work with multiple brands and accounts, so it’s totally normal to bring data from separate FB accounts into the same sheet.
Ana I need your helpppp Please
I want to have a sheet for every single campaign on fb ads, but i can’t because it writes me all the campaigns in a single sheet. Secondly I really need the conversions number and conversion cost but i really can’t add them. Thank you very very much for this work.
Here I am! 😀 If you want to get campaign data into individual sheets, you should create multiple requests, each one filtering for the campaign ID. Like this:
https://graph.facebook.com/v6.0/act_11111111111111/insights?date_preset=last_14d&time_increment=14&level=ad&fields=account_id,account_name,campaign_id,campaign_name,adset_id,adset_name,ad_id,ad_name,account_currency,actions&access_token=XXXXXXXX&filtering=[{field: "campaign.id",operator:"IN", value: ['23842750602790045']},{field: "action_type",operator:"IN", value: ['offsite_conversion.fb_pixel_purchase']}]
You can get all your campaign IDs by first running the above request without the
filtering
parameter.The “actions” field shows all conversions. The example above shows the actions field filtered for just purchase conversions.
Hello dear Ana, Tahnk you so much of this Topic that helped me so much !
I’m wondering if you have any idea about the API Url to use to generate a report that includes the spending per day per campaign?
Also, I’d like to know if there is a way to automate for a daily update and keep the previous data stored (yesterday’s for example)
Thanks you in advance
You’re welcome! Sure, just choose
fields=campaign.name, spend
, with atime_increment
of 1 for daily data. The paid version of API Connector lets you automate daily updates. As for storing the previous day’s data, that’s actually exactly what my other add-on Archive Data does, it’s totally free and you can check it out here: https://gsuite.google.com/marketplace/app/archive_data/187729264527Hi Ana and great site! I’ve been playing around the API Connector and it’s been working great but when I tried to add any information about ad sets, ad ids, etc, it seems to completely ignore it. Much appreciated!
https://graph.facebook.com/v7.0/act_id/insights?date_preset=lifetime&fields=reach,clicks,adset_id,adset_name,ad_id,ad_name,spend&time_increment=1&access_token=
Thank you! Your request is missing the parameter
&level=ad
, so that’s why it won’t work. You’ll need to include that parameter if you’re pulling ad-level metrics like ad ID and name.Hello Ana, I have joined the family for a week now, so far has been so great! Thanks!
However, there’s one thing about this Facebook api bugs me. The time zone is always in GT-8 time zone, and I’m in Auckland (GT+12), how can I convert the time(data » date_start) and date to my local time?
Thanks!
Hi James! I’m glad you like API Connector 🙂 It’s rather hidden, but Facebook’s documentation says “We report ad insights data in the ad account’s timezone.” Therefore, please check the timezone your ad account is set to. You should be able to view that at this URL: https://www.facebook.com/ads/manager/account_settings/information.
The default is GMT-8 (Pacific time), so this is probably the reason you’re seeing that time zone from the API. If you have admin access to the FB Ads account, you can change that value to your local time.
Hi Ana,
Thank you so much for this documentation! It really helps.
I just have one thing to raise: Is this realtime data that gets displayed on Sheets or is there an auto update? If so, how often does the update happen?
Thank you so much again!
Hi Alex! Thank you for the comment, I’m glad you like the article.
The data is up to date at the moment you pull it, and you can run the request manually at any time to get newly refreshed data. Alternately you can set up scheduling (paid feature) to run the requests automatically on a schedule. Please let me know if that answers your question.
hi there, I followed your guide and the integration was super cool and worked fine for the last couple months. Today, however, I keep getting server error 400 when I send a new API. What could that be?
Hi there, a 400 error generally means there’s an error with how you’ve entered the request (info). Since the error just started, it’s likely related to an expired token. If you click ‘show response’ in the footer of API Connector, you should be able to see the exact error message from Facebook.
Hi Anna,
thanks so much for the detailed explanation. I have one issue, which I can’t solve with google.
The format of numbers is very weird.
Example:
CTR in FB-ads-manager is 5,76%. In Google Sheets it’s 5.781.521
Costs in FB-ads-manager is 78,37€. In Google Sheets it’s 78.37
Language of sheets is german.
I already tried to change the format, but nothing helped.
Do you know the solution to this?
Thanks!
Niklas
I think it’s related to the locale of the sheet. Can you please try changing it to the United States to see if it helps? The setting is located under File > Spreadsheet Settings > Locale.
It works now. Thanks!
Hi Ana.
I need create an Ad Library API and export to spreadsheet. The process its similar?
Best regards,
Alex.
I think so, based on the documentation here: https://www.facebook.com/ads/library/api/. You’ll need to get a user token and then run a URL like this:
https://graph.facebook.com/v7.0/ads_archive?search_terms='california'&ad_type=POLITICAL_AND_ISSUE_ADS&ad_reached_countries=['US']&access_token=$YOUR_TOKEN
Hi Ana,
I tried this 2 weeks ago and was getting each campaign in a separate row, however now it’s not working and I am only getting all ads data in one single row which is no good.
Thank you!
Hey Amy, it sounds like you may have inadvertently switched your report style back to the default single-row style.
Under Output Settings, please click
Output options > Report style: compact
to see if that resolves the issue.Hi Ana,
This is really a great article, which can make Facebook Ads numbers appear on Google Sheet, and it really helped me a lot in my work. I have a question about connecting accounts, can I extract campaign’s data of all accounts in the my Facebook Business Manager through one API request? I hope that campaign spending of all accounts in one Business Manager can be presented on the same sheet. The request URL in this article seems to be designed for a single Ads account using. Was wondering whether you can help me to adjust the requested URL?
Thank you very much!
Thanks, Murphy, I appreciate the nice comment! Unfortunately you can’t pull data from multiple accounts at the same time, as the Facebook API only allows for a single account ID. You can either duplicate your requests, substitute in different account IDs for each request, and then aggregate them together into a single sheet with a function like QUERY(), or use the multi-query function to list out all your URLs and run through them in one go.
Hi Ana, thanks a lot for this great tutorial. In that particular case – pulling data from multiple ad accounts – will it be necessary to generate one access token for each request, every 2-3 months, or only one access token is needed for my App?
Hi Patrice, you only need one access token. It’s tied to the user, so it will provide access to all the accounts that the user — you — has access to.
Hi Ana,
Thanks for the post. Really helpful.
I am looking to pull inlcude paused campaigns in my data pull. Do you have an idea on how I can acheive this?
Nice, I’m glad it’s helpful 🙂 All campaign types including paused campaigns should be included by default. Are you seeing something different?
I’ve been looking for something like this product for *soooooooo long*
I’m sooo happy. really.
and this tutorial is amazing. and it’s working.
what can I say? You got yourself a loyal customer.
keep rockin’
Oh, this is a really nice comment, thank you! I’m interested to know whether you were looking for a tool to get FB data specifically, or just for an API connection tool in general.. sent you a message 🙂
How to get installs counts?
Conversion actions like installs are shown under the “actions” field, so you need to add “actions” to your list of fields and include a filter for the action you’re interested in (if you’re not sure of the action name, then first pull all the actions and add your filter after).
Nice Article, Ana!
But i am getting the below error.
{“error”:{“message”:”Invalid OAuth access token.”,”type”:”OAuthException”,”code”:190,”fbtrace_id”:”AsnC2jHPNAav8JXp_7090vx”}}
Can you pls help me in understanding this?
Facebook says that error code 190 means “Access token has expired” so you will need to get a new token. You can find details about your token by pasting it into FB’s token debugger.
Hi Ana,
Thank you for this insightful documentation! This really helped with my weekly reporting for the company i work at.
However, i have trouble to get my conversion data into sheets. We have 3 different custom conversions. I used the template from this blog and tried to change the conversion type, but it doesnt show the right conversions.Right now it only shows purchases, but we don’t use this goal.
Could you please help me out? Every other metric comes out fine, i only have problems with the conversions. Thanks in advance and i hope to hear from you soon!
-Jael
Hi Jael, you should be able to substitute in the conversion you’re interested in. The entire request would then be something like this:
https://graph.facebook.com/v8.0/act_YOUR_ACCOUNT_ID/insights?date_preset=last_7d&fields=campaign_name,impressions,reach,clicks,spend,actions&level=campaign&filtering=[{field: "action_type",operator:"IN", value: ['offsite_conversion.YOUR_CONVERSION']}]&access_token=YOUR_ACCESS_TOKEN
Hi Ana,
Thanks for the fast and extensive response! The thing i dont understand is what to fill in at ‘offsite_conversion.YOUR_CONVERSION. Should i replace ‘YOUR_CONVERSION’ with the custom conversion id? Or should it be the name of the conversion? For example the name of the conversion is ‘Registration bootcamp’.
Thanks again, i hope my explenation is clear!
– Jael
You should replace it with your custom conversion ID. To find your ID, you can open up FB Business Manager, click Events Manager, then click Custom Conversions in the lefthand sidebar. You’ll see a list of custom conversions and their IDs. So then you would substitute in that value, like
offsite_conversion.custom.398028550584411
If you don’t have immediate access to FB Ads Manager, an alternate method is to run this request:
https://graph.facebook.com/v8.0/act_1111111111111/insights?fields=actions&access_token=+++'Tokens'!B1+++
It will return a list of all your conversions and custom conversion IDs, but it won’t include their name. Still, it could work if you only have one or two custom conversions and are able to identify them.
Hi Ana,
Thank you so much, it worked :D. This is amazing. I used the custom conversion id from FB Business manager.
I have one more question, we have a total of 3 custom conversions, how should the request look like if i want to include all 3 of them?
Thanks again!
– Jael
woohoo, I’m glad it worked! So, you have two options here:
1) Run them separately. I think this might be best because the output can get complicated when you’re looking at multiple conversions in a single response.
2) Run them together. In that case your query would look like this:
&filtering=[{field: "action_type",operator:"IN", "value":["offsite_conversion.custom.398028550584411","offsite_conversion.custom.123456789","offsite_conversion.custom.987654321"]}]
You can try the second one and see what you think, and if the output is too complicated try the first one 🙂
Hey,
This API request I have created starting of this month after running smoothly now it’s throwing error –
i.e.
Status
Request failed: The server responded with an error (500) show response
{“error”:{“code”:1,”message”:”Please reduce the amount of data you’re asking for, then retry your request”}}
Is there any data limitation I should know about?
This error message comes from Facebook itself. FB doesn’t seem to provide any documentation on it, but based on some comments here, their limits aren’t based on specific numbers, but rather on how many resources it takes to get the data. You can reduce the amount of data you’re asking for by using the
limit
parameter or using date parameters likesince
anduntil
.When we create the token manually and copy it for use in the API Connector, where exactly do we put it in the API Connector? I’ve tried a few things and they haven’t worked.
Once you have your token, you can use it by appending it to any API URL, like
https://graph.facebook.com/v8.0/act_123456789012345/insights?access_token=YOUR_ACCESS_TOKEN
.Hey Ana ! Thanks for the great tutorial.
But can i design the sheet like this https://ibb.co/SXjhrcT ?
If yes, can u help me generate the code ?
Thanks, I’m glad you like the article. You would need to run your query twice, once with
date_preset=last_3d
and once withdate_preset=last_7d
. That will pull in the raw data to your sheet, and you can then reconfigure it however you like to make it match your desired dashboard output.Hi Ana,
Thank you very much for the article, but I stumble on a problem, can you please point me where i did wrong? By the way, I am not a coder, so it would be very helpful if you explain it in simple terms. Thank you so much 🙂
I try to add “yesterday” date to the fields, and i use this URL
https://graph.facebook.com/v8.0/act_xxxxxxxxxxxxxxxxx/insights?date_preset=yesterday&fields=date_presets{yesterday},spend,reach,impressions,click
Hi Adya, thanks for the message. Date presets aren’t added into the “fields” parameter. Please try the following instead:
https://graph.facebook.com/v9.0/act_xxxxxxxxxxxxxxxx/insights?date_preset=yesterday&fields=spend,reach,impressions,clicks
Hi there,
I’m trying to export the time of day (viewer’s time zone) as a breakdown but without success. Can you please let me know how to do that?
Hi Francesco, please try this:
https://graph.facebook.com/v9.0/act_1111111111111/insights?breakdowns=["hourly_stats_aggregated_by_audience_time_zone"]
Hi Ana, I need to extract the spend from every day ever since the ad account has been created, and it should be updated once a day moving forward. And unfortunately, I am stuck.
https://graph.facebook.com/v8.0/act_xxxxxxxxxxxxxxxx/insights?fields=spend/&time_increment=all_days
You should be able to get historical data with a query like this:
https://graph.facebook.com/v9.0/act_1111111111111111111/insights?date_preset=lifetime&fields=spend&time_increment=1&limit=5000
Going forward you can just switch your date_preset value to ‘yesterday’ and run it each day.
Hi Ana, thank you for your answer.
Hi there!
I’m trying to pull out lifetime spend for one of mine accounts. Spend should be per day. So one row for one day. I tried but I’m getting error. https://prnt.sc/103v8qk
Is it even possible to go with lifetime spend per day?
Thank you
Hi Milica! It is possible, but since Facebook is giving you the “Please reduce the amount of data you’re asking for” error message, you’ll need to split up your request into smaller blocks, like with a date range filter for each request.
Another method would be to set the limit to something smaller (e.g. limit=500) and then set up pagination handling as described in the article.
Can you please try and see how it goes?
Hi Anna! Thank you soo much for your help! First option you suggested didn’t work. But I managed to set all up with pagination handling.
Thanks again!
Awesome, I’m glad to hear you got it working : )
how do i filter by campaign name ?
You can add a filter parameter to your URL like this:
&filtering=[{field: "campaign.name",operator:"CONTAIN", value: 'your_campaign'}]
Substitute in your own campaign name where it says
your_campaign
.thx anna
how can I filter to see two campaigns?
Their documentation is very unclear about this, but in my own tests I can only get the CONTAIN operator to work on campaigns. So I think you can only do this if you find a string that both of your campaigns contain.
Hi, I’m Facebook Ads Marketer. I have a question:
Can I get Data Bill Payment account or invoice payment?
Because now I used “Sum amount spend” but it not good for charge fee with customer. I wanna get data payment in bill transaction to know exactly Facebook charge fee me and notify customers when the deposit is almost exhausted.
Hi there, this page shows how to get invoices from the Facebook API. It says you would send a URL like this:
https://graph.facebook.com/v10.0/Business_ID/business_invoices?start_date=2017-01-01&end_date=2017-04-01
However it’s not that easy, since the page also says your account needs a finance role and your connection requires business_management scope, which is not provided by API Connector’s built-in Facebook Ads connection. So you would need to create your own app at https://developers.facebook.com/, and then add the permissions needed for the invoices endpoint. Hope that helps point you in the right direction.
Hi Ana,
your API still uses version 8.0 as far as I know.
I just received a mail from facebook that apps using version 8.0 are not supported after May 2021.
Do you have any plans to upgrade to version 9.0 or 10.0?
Thanks for the API! It helps me a lot 🙂
Thanks,
Niklas
Hey Niklas! Thank you for the messsage. I just got that email too, we will upgrade our side to version 10 soon.
Hello, can I hook this to an ad account I have access to but do not own? I would like to generate for my Client
Yeah, if your client has provided your account with access to their FB Ads account, you can access their data via FB Ads Manager or the API.
hey there
Very good article, thank you for making it. I am trying to create an API URL to read all the data from form id, but I am getting no response.
Kindly suggest how can I fetch all the columns and data.
Response
{
"data": []
}
URL:
https://graph.facebook.com/v10.0/{form-id}/leads?access_token=
Please check this article for info on getting leads.
Hi Ana.
Please help me!
I get an error and cannot get the data from late April.
error message;
Completed with errors
– Server responded with an error (500) show response{“error”:{“code”:1,”message”:”Please reduce the amount of data you’re asking for, then retry your request”}}
Thank you!
Hi Yoshi! I think the error message says it all: you need to reduce the amount of data you’re asking for and then try again.
The simplest way is probably to just reduce your date range. You could break it into a couple different requests and then merge the data back together at the end. Alternatively, you could pull fewer metrics, or pull one action at a time, or perhaps choose level=campaign instead of level=ad if you don’t need that level of detail. Basically Facebook doesn’t like it when we try to extract too much data at once…
Hi Ana,
First of all congratulations on such a great product, I’ve been looking for a while for something just like this and I’m thrilled of all the possibilities I have thanks to this API Connector.
I’ve successfully been able to get all FB Ads information on a daily basis and going through the results, I’ve found out that the total actions for the events on the action_type field are not the same totals found on FB Ads Manager directly. Doing some research, I think this is due to new iOS 14 policies and I’m wondering if there’s a way in which I can get the total amount of actions for the conversions through the API Connector.
What I’ve understand so far is that it can be possible but I’m not sure how to get iOS conversion actions information through the API Connector.
Thanks in advance,
Santiago
Hey there, thank you for the nice comment!
Yeah, at the end of April, Facebook changed its attribution changes to comply with iOS 14.
Based on their docs, I think you now need to add
&use_unified_attribution_setting=true
to the end of your API request URL. This will force the data to use the attribution setting of the ad being queried, and should result in data matching between Ads Manager and the API response. Please try and let me know if it works for you.Ana,
Thanks for your help!
Already did the change you suggested and now I have all the information matching between Ads Manager and the API.
Best,
Santiago
Awesome, thanks for the update!
Hi There
I got the message: “Completed with errors – Server responded with an error (400)” When trying to connect to pull Facebook Ads marketing data… Any idea how to fix this?
The detailed error is here: “{“error”:{“message”:”Unsupported get request. Object with ID ‘act_123456789012345’ does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api”,”type”:”GraphMethodException”,”code”:100,”error_subcode”:33,”fbtrace_id”:”AHzSs70GnGnPvk7oXCBssF-“}}”
Based on that error it sounds like you’ve entered a wrong account ID or it doesn’t have permissions. Were you using a test app? If so, you can check what other people have said about resolving it here: https://stackoverflow.com/questions/47437362/what-does-it-mean-error-subcode-33-in-the-facebook-response-error
Hi Ana, This is really helpful and thank you for the great explanation.
I have one issue with filtering, it seems on certain dates where we have 0 value for metrics like ‘comment’, the API will not show that metric on google sheet, so it breaks the report format.
How do we add more filtering like the value should be >= 0 or make sure FB show all metrics although it’s 0?
Hey Ken, thanks for the comment. Yeah, Facebook doesn’t send back fields at all when their value is zero. Please click Edit Fields to map your fields to columns, that way it won’t matter what gets sent back.
Hi, i have some questions about your url builder.
1) Can i choose data only for one campaign or it is only possible for all of them at the time?
2) When i choose conversion (purchase) and try to get cost per action, action value and roas this data arent showing in my google sheet.
3) I got the this error several times in a row and exactly dont know how to solve this because my limit is now 500 {“error”:{“code”:1,”message”:”Please reduce the amount of data you’re asking for, then retry your request”}}
Can you help me with that?
1) You can use the
filtering
parameter to filter for a specific campaign.2) If those values don’t show up, it means those values don’t exist for the selected Action. You can test some of the other similar Actions (e.g. “Grouped Action: Purchases”) or make an API request to
https://graph.facebook.com/v10.0/act_YOUR_ACCOUNT_ID/insights?fields=cost_per_action_type,action_values,purchase_roas
to see what Actions are available for each of those metrics.3) That error message comes from Facebook, so unfortunately I can’t really say much more than they did: you’ll need to reduce the amount of data you’re requesting at once. You might need to reduce your date range or number of parameters, or try an even lower limit like 100. I would experiment with reducing your request until you do get data back, and then add complexity back to your query to see where it fails.
Hello, i’m having trouble using the pagination.
Ive used the excat same set-up described in the article but it does not work. can you help?
– added the &limit=5000 in the API request
– pagination : cursor
– Next token parameter : after
– Next token field : paging.cursors.after
Whend you say it doesn’t work, do you mean you get an error message? Which error message do you see?
I can having the same 25 first accounts, but it does not show the next page
If it’s only showing the first 25 requests, that likely means it’s not recognizing your
limit
parameter. Please double-check that you’ve added it correctly.Sorry, I was using the wrong API call it’s me/adaccounts and not me?fields=adaccounts 🙂 every thing is fine now
thanks again
Hi guys! Thanks for the tutorial, I followed all the steps but I get this error:
1) Completed with errors
– Server responded with an error (400) show response
{“error”:{“message”:”Unsupported get request. Object with ID ‘act_XXXXXXXXXXXXX’ does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api”,”type”:”GraphMethodException”,”code”:100,”error_subcode”:33,”fbtrace_id”:”AIn_XwAfTDga0rujxxxxxxxxx”}}
sorry I found the error in the id 🙂 now is ok!!
Hooray 😀 Thanks for the update, I’m glad it works now.
Hi,
I wanted to give this a shot but I’m stuck at the very first step. Whenever I try to connect the add on to facebook, I get an error message on facebook “Could not link API Connector for Ads to Facebook, You may not be connected to the network or we could not establish a connection with our server. Check your connection and try again later.”
Any idea why that is ?
Thanks
Hey Julien, I haven’t seen this before but I just Googled the error message and found some people saying it’s related to your browser settings. Could you please try with a different browser? Also I read that it can happen if you just created your Facebook account within the past hour, any chance it’s a new account?
Hi Ana, thanks for the very quick reply. I won’t get too much into boring details but indeed, I had to create a new facebook account for this. Went to get some lunch, came back, and it works now. Thanks again !
Hi Ana.
Please help me!
I get an error and cannot get the data today.
error message: {“error”:{“message”:”(#100) Missing permissions”,”type”:”OAuthException”,”code”:100,”fbtrace_id”:”A7Whs5ymYcefTVWxLamrwLv”}}
Thank you!
If the error just started, it could be a bug on Facebook’s side, or maybe your token has expired. Can you please paste your token into the access token debugger and see if it’s still valid?
https://developers.facebook.com/tools/debug/accesstoken/
Hi Ana,
I have a question I was hoping you could help me with. I manage ad placements for 100+ facebook/instagram accounts & I’d like to have their monthly spends populate automatically for me in one sheet instead of me manually going in each day and keying it in. I’m getting tripped up a little bit though with crafting my API URL path. I would like it to always pull in the current month without me having to go in and key in the new month each month, if that makes sense? So I need something like [current month] where google sheets knows what month we’re in instead of me saying “
{"since":"2021-10-01","until":"2021-10-31"}
“. I also noticed that when I put “{"since":"2021-10-01","until":"2021-10-31"}
” in my URL, that also populates in the cell. I want that to qualify the data I want, but don’t want to the date ranges pulling thru in the actual sheet…way to hide? Also, how do I get the API URL to add up the spends in the current month (assuming I have multiple campaigns running in a given month) instead of spitting out each campaigns data spend?Essentially need to know:
-How can I roll up all campaign spends in a given month to give me one lump sum number
-How to tell the URL I was the [current month] without actually qualifying what the current month is
-How to ONLY have the lump sum spend populate in my sheet
-How often does the data reload? Does it refresh automatically or do I have to run it daily?
this is url I was working with if this helps:
https://graph.facebook.com/v12.0/act_794801067272984/insights?fields=spend&time_increment=1&time_range={"since":"2021-10-01","until":"2021-10-31"}
Hi Paige!
-How can I roll up all campaign spends in a given month to give me one lump sum number
https://graph.facebook.com/v12.0/act_1111111111/insights?fields=account_id,account_name,spend&date_preset=last_month
-How to tell the URL I was the [current month] without actually qualifying what the current month is
You can either use date presets like this_month, last_month, etc., or you can set up your dates with functions in cells, and then use those cells in your requests, e.g.
https://graph.facebook.com/v12.0/act_88976240/insights?fields=account_id,account_name,spend&time_range={"since":"+++Sheet1!A1+++","until":"+++Sheet1!A2+++"}
-How to ONLY have the lump sum spend populate in my sheet
By default, API Connector will return whatever data comes back from the API, and Facebook sends back some “extra” fields like dates. If you only want to display certain fields, you could either pull the fields you need into a second summary sheet, or use a JMESPath expression to filter all the extra fields out. If you need help constructing that expression, feel free to send a message to support.
-How often does the data reload? Does it refresh automatically or do I have to run it daily?
You can refresh it manually by clicking Run or turn on scheduling to refresh automatically.
Hope that helps clarify, just let me know if you have any other questions.
Hi there! Is there also a way to pull the data from facebook lead ads directly in the sheet (name, email address, phone number,….)
Looking forward to your reply!
Sure, please check this article for info on that: https://mixedanalytics.com/knowledge-base/import-facebook-leads-to-google-sheets/
Oh man, this might just be a lifesaver; I’ve been trying to build my own FB Ads connector in Data Studio and I think this covers all the pain points I was stuck on. Thank you, thank you, thank you!
Haha, awesome. I think this method does cover it all, but if you get stuck feel free to write back here.
Hi Ana,
Yesterday I made my connection with Facebook and it worked. But today I see this error:
{“error”:{“message”:”(#200) Provide valid app ID”,”type”:”OAuthException”,”code”:200,”fbtrace_id”:”…
What should I do?
Thanks a lot
Please make sure you’ve included an access token or selected “Facebook Ads” from the authentication dropdown.
Hi Ana,
Can you please help with getting the daily spend of the account? What I want to see is day, spend from 2021-01-01 till 2022-01-31.
Sure, just include
spend
as the fields parameter, settime_increment
to 1, and set thetime_range
to the whole year.When I add the ad title
1) 2: Completed with errors
– We received an error from facebook.com (500) show response
{“error”:{“code”:1,”message”:”An unknown error occurred”,”error_subcode”:99}}
https://graph.facebook.com/v12.0/act_248762389092142/insights?fields=account_name,campaign_name,adset_name,ad_name,spend,impressions,clicks,ctr,actions,action_values,conversion_values,cost_per_inline_link_click,cpc,cpm,inline_link_click_ctr,inline_link_clicks,reach,purchase_roas,cost_per_action_type&limit=5000&time_increment=1&date_preset=yesterday&level=ad
Facebook doesn’t clearly define this error message but it seems to be associated with requesting too much data at once. It also tends to be an intermittent error, so you may be able to resolve it just by waiting and trying again, otherwise you’ll need to request less data from their server.
is there a limit with the api connector results? im trying to do last_30d or last_7d but the no. of rows remain only 26 rows. it doesn’t show me per day until today. how do i fix this limitation?
By default Facebook only returns 25 rows unless you set the
limit
parameter to something larger. Please see the section on pagination for more info.Thank you Ana. Appreciate your great work! One last thing, when I use last_3d or last_7d is there a tweak to include today’s date as well? I noticed that it means 3/7days excluding today.
You’re welcome, thank you for reading 🙂 You can see all the time parameters Facebook allows here (check the section called date_preset). I see some presets that might work for you, e.g. this_week_sun_today. Alternatively, you can pull in exactly the time period you want by using time range parameters instead of date presets, e.g.
&time_range={"since":"2022-02-14","until":"2022-02-16"}
Hi Ana, appreciate your help for the above. It is working great now. Thank you so much! One more favor, do you think you have a similar article for importing google adwords insights?
Sure, please see this article: https://mixedanalytics.com/knowledge-base/import-google-ads-data-to-google-sheets/
Do we need a business plan for importing facebook data or just a pro plan should work?
If you want to connect through the preset OAuth button, you’ll need a Business plan, otherwise you can do it for free with a token.
Thanks very much !
Hey Ana! Thank you for your work!
So, I’m trying to pull “budget_remaining” from “adset”, how can I do it?
Looks like you can do a request URL like
https://graph.facebook.com/v13.0/12345/?fields=account_id,campaign,name,adset_schedule,budget_remaining
, where you replace 12345 with your adset ID. Please check if that works for you.Is it possible to get results for date_preset (e.g. last_7d) along with previous period data?
maybe I have to add something to the following request in order to get the previous period results?
https://graph.facebook.com/v13.0/act_123456789012345/insights?fields=reach,impressions,clicks,spend&date_preset=last_7d
You can set your date_preset to last_14d, or run two requests where each one uses a different time_range parameter.
How can I have an Async request?
Sorry, we don’t support async requests, you need to receive the data when you make the request.
If the issue is that your request is timing out, could you try reducing the time range or number of metrics?
i need: Ad Delivery, Ad Set Delivery Campaign Delivery
how can i do ????
Not really sure what those are, don’t see them as metrics in Facebook.
Are you looking for ad/campaign status? If so you can try
https://graph.facebook.com/v13.0/act_111111/campaigns?fields=name,id,effective_status,updated_time
andhttps://graph.facebook.com/v13.0/act_111111/ads?fields=name,id,effective_status,updated_time
Hi!
is there a way to get only certain data? like on our ads, we name it if it is for “creative testing”, or “audience testing”, etc. We only want to get the creative testing ads, can you suggest a way to filter them out during the picking up of data?
TYIA
Sure, you can use the
filtering
parameter and enter your condition there. It sounds like you’ll want to select something likead.name CONTAIN testing
.What can I do about this?
-we received an error from facebook.com (400)
{“error”:{“message”:”(#100) param filtering must be an array.”,”type”:”OAuthException”,”code”:100,”fbtrace_id”:”AXSvNMncT8wqWwX7M0UEp_A”}}
Facebook is saying that there’s an error in the filtering parameter. Can you please share some info on how you filled it out or what you’re filtering for? If you’re using an IN operator, make sure the value is an array, e.g.
["link_click","post_reaction"]
Now i have some data, but they are not currently. How can i show you my problem?
My Values are not correct. It is impossible to have a clickrate of 2.966.507 xD. What am i Doing wrong?
Sounds like a locale issue. Facebook sends back data in US format (comma separators) but your sheet may be set to a format with period separators. You can resolve it by changing your sheet to US locale or through a formula that swaps periods and commas, e.g.
=substitute(substitute(substitute(A1;",";"#");".";",");"#";".")
I just want to see clicks, thruPlays, impressions, clickrate, spend and cost per klick for each campagin. What ever i do is wrong 🙁
Plsease Help 🙁
You should be able to just select those fields, set a date preset, choose level= campaign, and hit Run. If you’d like more specific help please contact support with some details about your current setup.
How can i see my clicks per campaign?? Also my spend and impressions?
Open the
fields
parameter and select your fields (campaign_name, clicks, spend, impressions), open thelevel
parameter and select campaign, and click Run.