Search code examples
c#asp.netfacebook-graph-api

How to connect facebook forms with ad data - graph api


I have successfully created .net application for getting the leads from facebook using graph api.

These are the two URLs I am using:

https://graph.facebook.com/v16.0/{page-id}leadgen_forms?access_token={access-token}&limit=1000&fields=id,created_time,name,status,leads_count&filtering=[{field:%22status%22,operator:%22EQUAL%22,value:%22ACTIVE%22}]

https://graph.facebook.com/v16.0/{form-id}/leads?access_token={access-token}&limit=1000

First one is returning list of active forms, and second is returning a list of leads for a specific form id.

Now I have somehow to link form/lead with the campaign, adset and ad, so I need some help. I am able to call this https://graph.facebook.com/v16.0/act_{ad-account-id}/ads?access_token={access-token}&fields=name,campaign_id,adset_id so I can get aforementioned data, but I am not sure how to connect those data with forms data...


Solution

  • I have managed to do it, hope it will help someone with similar problem because the facebook docs is awful...

    I came to this solution after a lot of reading and constant try and fail... This is the URL which is returning the data about leads (Q&A), campaign, adset and ads.

    https://graph.facebook.com/v16.0/{form-id}/leads?level=campaign&level=adset&level=ads&fields=campaign_id,campaign_name,adset_id,adset_name,ad_id,ad_name,created_time,id,field_data&access_token={access-token}&limit=1000

    This is the preview of the response:

    respone_preview