Robo Robok
Robo Robok

Reputation: 22683

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:

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.

Upvotes: 8

Views: 9603

Answers (2)

David
David

Reputation: 1436

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"
    }
  ]
}

Upvotes: 20

Emortis
Emortis

Reputation: 61

Just a warning since this answer comes first on google search.

Since Facebook API v5.0 field "qualifiers" is removed and will throw an error.

Replace it with "questions" which is similar (if not exact) syntax as qualifiers. Found out the hard way on production server...

Upvotes: 6

Related Questions