Reputation: 22683
I'm using Facebook Lead Ads API. I need to retrieve all fields from a form by ID. I know I can:
/<PAGE_ID>/leadgen_forms
, but it doesn't return the fields/<FORM_ID>
, but it displays only the name and a few
data, but not fields/<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 randomIs 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
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
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