# Search targeting options

GET https://services.leadconnectorhq.com/ad-publishing/facebook/targeting/search

Search Facebook targeting options for ad set audience building. `type` selects which taxonomy is searched and determines the response shape: `geolocation` returns places, `interest` returns interests, behaviours, and demographics, and `language` returns locales. Geolocation and interest results are passed through from Facebook, so their fields are snake_case.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `adPublishing.readonly`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | No | Location identifier |
| `type` | string | Yes | Targeting search type |
| `query` | string | Yes | Search query string |
| `searchType` | string | No | Specific search subtype |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "2021-04-15"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ad-publishing/facebook/targeting/search": {
      "get": {
        "summary": "Search targeting options",
        "operationId": "searchTargetingOptions",
        "description": "Search Facebook targeting options for ad set audience building. `type` selects which taxonomy is searched and determines the response shape: `geolocation` returns places, `interest` returns interests, behaviours, and demographics, and `language` returns locales. Geolocation and interest results are passed through from Facebook, so their fields are snake_case.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "2021-04-15"
              ]
            }
          },
          {
            "name": "locationId",
            "required": false,
            "in": "query",
            "description": "Location identifier",
            "schema": {
              "example": "loc_abc123",
              "type": "string"
            }
          },
          {
            "name": "type",
            "required": true,
            "in": "query",
            "description": "Targeting search type",
            "schema": {
              "example": "interest",
              "enum": [
                "geolocation",
                "interest",
                "language"
              ],
              "type": "string"
            }
          },
          {
            "name": "query",
            "required": true,
            "in": "query",
            "description": "Search query string",
            "schema": {
              "example": "fitness",
              "type": "string"
            }
          },
          {
            "name": "searchType",
            "required": false,
            "in": "query",
            "description": "Specific search subtype",
            "schema": {
              "example": "adgeolocation",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching targeting options. The item shape follows the requested `type`: geo results for `geolocation`, interest/behaviour/demographic results for `interest` (sorted by estimated reach, largest first), and locales for `language`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchTargetingOptionsResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InternalServerErrorDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "adPublishing.readonly"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "SearchTargetingOptionsResponse": {
        "type": "array",
        "items": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "description": "Facebook geo key, used as the targeting id",
                  "example": "1045272"
                },
                "name": {
                  "type": "string",
                  "description": "Location name",
                  "example": "Thane"
                },
                "type": {
                  "type": "string",
                  "description": "Location granularity",
                  "example": "city",
                  "enum": [
                    "country",
                    "region",
                    "city",
                    "subcity",
                    "neighborhood",
                    "zip",
                    "geo_market",
                    "electoral_district"
                  ]
                },
                "country_code": {
                  "type": "string",
                  "description": "ISO country code",
                  "example": "IN"
                },
                "country_name": {
                  "type": "string",
                  "description": "Country name",
                  "example": "India"
                },
                "region": {
                  "type": "string",
                  "description": "Region or state name",
                  "example": "Maharashtra"
                },
                "region_id": {
                  "type": "number",
                  "description": "Numeric region id",
                  "example": 1735
                },
                "supports_region": {
                  "type": "boolean",
                  "description": "Whether region-level targeting is available here",
                  "example": true
                },
                "supports_city": {
                  "type": "boolean",
                  "description": "Whether city-level targeting is available here",
                  "example": true
                },
                "geo_hierarchy_level": {
                  "type": "string",
                  "description": "Position in the geo hierarchy. Absent on plain cities.",
                  "example": "NEIGHBORHOOD"
                },
                "geo_hierarchy_name": {
                  "type": "string",
                  "description": "Hierarchy label. Can differ from `geo_hierarchy_level` — a SUBCITY reports CITY here.",
                  "example": "CITY"
                }
              },
              "required": [
                "key",
                "name",
                "type"
              ],
              "title": "FacebookGeoTargetingSearchResultDTO"
            },
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Facebook targeting id",
                  "example": "6003195226065"
                },
                "name": {
                  "type": "string",
                  "description": "Display name",
                  "example": "Tabletop game"
                },
                "type": {
                  "type": "string",
                  "description": "Targeting field this entry must be sent under when building an ad set audience",
                  "example": "interests",
                  "enum": [
                    "interests",
                    "behaviors",
                    "demographics",
                    "education_majors",
                    "education_schools",
                    "work_employers",
                    "work_positions"
                  ]
                },
                "subText": {
                  "type": "string",
                  "description": "Category label for grouping in a picker. `interests` for the interest taxonomy, otherwise the source class.",
                  "example": "interests",
                  "enum": [
                    "interests",
                    "behaviors",
                    "demographics"
                  ]
                },
                "path": {
                  "description": "Taxonomy breadcrumb from the root to this entry",
                  "example": [
                    "Interests",
                    "Technology",
                    "Computers",
                    "Tablet computers"
                  ],
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "description": {
                  "type": "string",
                  "description": "Explanation of who the entry matches. Empty string or null when Facebook has no copy for it.",
                  "example": "People who primarily access Facebook using a tablet",
                  "nullable": true
                },
                "audience_size_lower_bound": {
                  "type": "number",
                  "description": "Lower bound of the estimated reach",
                  "example": 512619285
                },
                "audience_size_upper_bound": {
                  "type": "number",
                  "description": "Upper bound of the estimated reach",
                  "example": 602840280
                },
                "topic": {
                  "type": "string",
                  "description": "Broad topic the interest sits under",
                  "example": "Technology"
                },
                "disambiguation_category": {
                  "type": "string",
                  "description": "Qualifier Facebook adds when the name alone is ambiguous",
                  "example": "Computers (Brand)"
                },
                "real_time_cluster": {
                  "type": "boolean",
                  "description": "Facebook internal clustering flag, on behaviour entries only",
                  "example": false
                }
              },
              "required": [
                "id",
                "name",
                "type",
                "subText",
                "path",
                "description"
              ],
              "title": "FacebookInterestTargetingSearchResultDTO"
            },
            {
              "type": "object",
              "properties": {
                "key": {
                  "type": "number",
                  "description": "Facebook locale id, used as the targeting value",
                  "example": 1004
                },
                "name": {
                  "type": "string",
                  "description": "Language name",
                  "example": "Chinese (All)"
                }
              },
              "required": [
                "key",
                "name"
              ],
              "title": "FacebookLanguageTargetingSearchResultDTO"
            }
          ]
        }
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      },
      "InternalServerErrorDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "description": "HTTP status code for an unexpected server error",
            "example": 500
          },
          "message": {
            "type": "string",
            "description": "Error message describing the server failure",
            "example": "Internal Server Error"
          }
        },
        "title": "InternalServerErrorDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/ad-publishing/facebook/targeting/search?type=<TYPE>&query=<QUERY>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: 2021-04-15'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: '2021-04-15'
  }
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/ad-publishing/facebook/targeting/search?type=<TYPE>&query=<QUERY>', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/ad-publishing/facebook/targeting/search"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "2021-04-15"
}

params = {
    "type": "<TYPE>",
    "query": "<QUERY>"
}

response = requests.get(url, params=params, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/ad-publishing/facebook/targeting/search?type=<TYPE>&query=<QUERY>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: 2021-04-15',
  ],
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/ad-publishing/facebook/targeting/search?type=<TYPE>&query=<QUERY>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "2021-04-15")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
)

func main() {
  url := "https://services.leadconnectorhq.com/ad-publishing/facebook/targeting/search?type=<TYPE>&query=<QUERY>"
  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "2021-04-15")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/ad-publishing/facebook/targeting/search?type=<TYPE>&query=<QUERY>")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "2021-04-15"

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "2021-04-15"
}

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/ad-publishing/facebook/targeting/search?type=<TYPE>&query=<QUERY>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
