Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get form fields in Facebook Lead Ads API?

I'm using Facebook Lead Ads API. I need to retrieve all fields from a form by ID. I know I can:

  • get all forms by calling /<PAGE_ID>/leadgen_forms, but it doesn't return the fields
  • get a form by /<FORM_ID>, but it displays only the name and a few data, but not fields
  • get all leads by /<FORM_ID>/leads - it gives me the fields in each lead, but only if I have leads; there's also another problem with this solution - the order of the fields is random

Is there any dedicated way to retrieve leadgen form fields, even when there are no leads yet?

I found out that I can download the CSV and in the first row, it gives me all fields IDs (and some other columns). I'm not sure though how I can read the content of this file in PHP, because it gives me some HTML when I try to use get_file_contents() on it.

like image 482
Robo Robok Avatar asked Feb 27 '16 21:02

Robo Robok


People also ask

Where do I find lead forms in Facebook ads?

To access your leads, you have to: Navigate to your Facebook page and click on the Publishing Tools button. On the left-hand side, you will see the Lead Ads Forms section. From here, click on the Forms Library option.

How do I get form data on Facebook?

The leads data that is submitted through your Instant Form can be downloaded via a CSV export from Ads Manager. You can also download your leads from your Facebook Page, through the Faceboook API or access them through an integrated CRM system.

How do I extract leads from Facebook to excel?

Export Leads from your Facebook Publishing ToolsAccess the Facebook Page that has your desired leads. On your Manage Page sidebar, scroll down to Publishing Tools. On the new sidebar, click Forms Library. Locate your desired form on the table and click Download under the Leads column.


1 Answers

You can get these by adding non-default field questions, so the url becomes /<form_id>?fields=id,name,questions.

The official docs don't describe the fields available for reading but the questions field and its nested fields are described in the params used for creating a lead form.

Example output

{
  "id": "1234567890000",
  "name": "test form",
  "questions": [
    {
      "key": "name",
      "label": "Full Name",
      "type": "FULL_NAME",
      "id": "777888999000111"
    },
    {
      "key": "email",
      "label": "Email Address",
      "type": "EMAIL",
      "id": "111222333444555"
    }
  ]
}
like image 89
David Avatar answered Sep 25 '22 23:09

David