简体   繁体   中英

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.

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

I haven't found it anywhere in the official docs though. But it is quite common for new FB features to be poorly documented.

Example output

{
  "id": "1234567890000",
  "name": "test form",
  "qualifiers": [
    {
      "field_key": "first_name",
      "label": "First Name",
      "question": "First name",
      "id": "777888999000111"
    },
    {
      "field_key": "last_name",
      "label": "Last Name",
      "question": "Last name",
      "id": "111222333444555"
    }
  ]
}

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...

How do we suppose to get lead through form-id or ad-group-id?

First of all, to find those id is a problem as we are introduced to FB API first time. No Fb doc has this information how to get these ID or may some terminology issue to find these id. Not sure how to get these ids. any one know about this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM