# Get entities

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

Retrieve campaigns, ad sets, or ads for a location. `entityType` selects which, and each returns a `{ data }` envelope whose item shape differs — the id key is `campaignId`, `adSetId`, or `adId` respectively, and the status fields differ too: campaigns carry both `status` and `effectiveStatus`, ad sets only `effectiveStatus`, and ads only `status`. `next` is returned only when the branch pages through Meta, so treat its absence as the end of the results rather than assuming a cursor. For `CAMPAIGN`, `type=INTEGRATION` queries Meta while `type=AD_MANAGER` reads campaigns this service published, filtered to `PAUSED` and `PUBLISHED`. `ADSET` requires `campaignId`; `AD` accepts `adSetId` for a single ad set or `campaignId` to page across the campaign.

## 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 | Yes | Location identifier |
| `type` | string | Yes | Integration source type |
| `next` | string | No | Pagination cursor |
| `fetchAll` | string | No | Fetch all entities |
| `campaignId` | string | No | Campaign identifier |
| `adSetId` | string | No | Ad set identifier |
| `entityType` | string | Yes | Entity type to fetch |
| `searchId` | string | No | Search identifier |
| `selectedAdAccountId` | string | No | Selected ad account ID |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "2021-07-28"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ad-publishing/facebook/entity": {
      "get": {
        "summary": "Get entities",
        "operationId": "getEntities",
        "description": "Retrieve campaigns, ad sets, or ads for a location. `entityType` selects which, and each returns a `{ data }` envelope whose item shape differs — the id key is `campaignId`, `adSetId`, or `adId` respectively, and the status fields differ too: campaigns carry both `status` and `effectiveStatus`, ad sets only `effectiveStatus`, and ads only `status`. `next` is returned only when the branch pages through Meta, so treat its absence as the end of the results rather than assuming a cursor. For `CAMPAIGN`, `type=INTEGRATION` queries Meta while `type=AD_MANAGER` reads campaigns this service published, filtered to `PAUSED` and `PUBLISHED`. `ADSET` requires `campaignId`; `AD` accepts `adSetId` for a single ad set or `campaignId` to page across the campaign.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "2021-07-28"
              ]
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "query",
            "description": "Location identifier",
            "schema": {
              "example": "loc_abc123",
              "type": "string"
            }
          },
          {
            "name": "type",
            "required": true,
            "in": "query",
            "description": "Integration source type",
            "schema": {
              "example": "AD_MANAGER",
              "enum": [
                "AD_MANAGER",
                "INTEGRATION"
              ],
              "type": "string"
            }
          },
          {
            "name": "next",
            "required": false,
            "in": "query",
            "description": "Pagination cursor",
            "schema": {
              "example": "cursor_abc",
              "type": "string"
            }
          },
          {
            "name": "fetchAll",
            "required": false,
            "in": "query",
            "description": "Fetch all entities",
            "schema": {
              "example": "true",
              "type": "string"
            }
          },
          {
            "name": "campaignId",
            "required": false,
            "in": "query",
            "description": "Campaign identifier",
            "schema": {
              "example": "camp_123",
              "type": "string"
            }
          },
          {
            "name": "adSetId",
            "required": false,
            "in": "query",
            "description": "Ad set identifier",
            "schema": {
              "example": "adset_123",
              "type": "string"
            }
          },
          {
            "name": "entityType",
            "required": true,
            "in": "query",
            "description": "Entity type to fetch",
            "schema": {
              "example": "CAMPAIGN",
              "enum": [
                "CAMPAIGN",
                "ADSET",
                "AD"
              ],
              "type": "string"
            }
          },
          {
            "name": "searchId",
            "required": false,
            "in": "query",
            "description": "Search identifier",
            "schema": {
              "example": "search_123",
              "type": "string"
            }
          },
          {
            "name": "selectedAdAccountId",
            "required": false,
            "in": "query",
            "description": "Selected ad account ID",
            "schema": {
              "example": "act_123456",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Campaigns, ad sets, or ads, matching the requested `entityType`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetEntitiesResponse"
                }
              }
            }
          },
          "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": {
      "GetEntitiesResponse": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "data": {
                "description": "Campaigns, shaped by the requested `type`",
                "example": [
                  {
                    "campaignId": "120250392416560122",
                    "name": "AutomationTest718084",
                    "status": "ACTIVE",
                    "effectiveStatus": "ACTIVE",
                    "adAccountId": "act_357046700569338",
                    "locationId": "fRMewNQIxSyZ5R4nQyit"
                  }
                ],
                "type": "array",
                "items": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "campaignId": {
                          "type": "string",
                          "description": "Meta campaign id. Note the key is `campaignId`, not `id`.",
                          "example": "120250392416560122"
                        },
                        "name": {
                          "type": "string",
                          "description": "Campaign name",
                          "example": "AutomationTest718084"
                        },
                        "status": {
                          "type": "string",
                          "description": "Configured status on the campaign",
                          "example": "ACTIVE"
                        },
                        "effectiveStatus": {
                          "type": "string",
                          "description": "Status Meta actually delivers under. Equals `status` at campaign level, since a campaign has no parent to inherit from.",
                          "example": "ACTIVE"
                        },
                        "adAccountId": {
                          "type": "string",
                          "description": "Ad account the campaign belongs to",
                          "example": "act_357046700569338"
                        },
                        "locationId": {
                          "type": "string",
                          "description": "Location the lookup was scoped to",
                          "example": "fRMewNQIxSyZ5R4nQyit"
                        }
                      },
                      "required": [
                        "campaignId",
                        "name",
                        "status",
                        "effectiveStatus",
                        "adAccountId",
                        "locationId"
                      ],
                      "title": "FacebookEntityCampaignDTO"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "campaignId": {
                          "type": "string",
                          "description": "Meta campaign id of the published campaign",
                          "example": "120250392416560122"
                        },
                        "name": {
                          "type": "string",
                          "description": "Campaign name as stored locally",
                          "example": "Spring Promo"
                        },
                        "status": {
                          "type": "string",
                          "description": "Local publishing status, not a Meta status",
                          "enum": [
                            "PAUSED",
                            "PUBLISHED"
                          ],
                          "example": "PUBLISHED"
                        },
                        "adAccountId": {
                          "type": "string",
                          "description": "Ad account the campaign belongs to",
                          "example": "act_357046700569338"
                        },
                        "locationId": {
                          "type": "string",
                          "description": "Owning location",
                          "example": "fRMewNQIxSyZ5R4nQyit"
                        }
                      },
                      "required": [
                        "campaignId",
                        "name",
                        "status",
                        "adAccountId",
                        "locationId"
                      ],
                      "title": "FacebookAdManagerEntityCampaignDTO"
                    }
                  ]
                }
              },
              "next": {
                "type": "string",
                "description": "Cursor for the next page, to be passed back as `next`. Present only on the `INTEGRATION` branch, and absent once the last page is reached.",
                "example": "QVFIVFdHQTJVV1Vod3hVZAlRDLUpSM19HVjVScGNDMXozTU5RVkk1NWt6MnNISmZAtMVpMcVU5dVYwRU00R0xfVTh5c3AZD"
              }
            },
            "required": [
              "data"
            ],
            "title": "FacebookEntityCampaignsResponseDTO"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "description": "Ad sets under the requested campaign",
                "example": [
                  {
                    "adSetId": "120222443174530122",
                    "name": "Jenni prod ad  5 adset",
                    "effectiveStatus": "CAMPAIGN_PAUSED",
                    "adAccountId": "act_357046700569338",
                    "locationId": "fRMewNQIxSyZ5R4nQyit"
                  }
                ],
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "adSetId": {
                      "type": "string",
                      "description": "Meta ad set id. Note the key is `adSetId`, not `id`.",
                      "example": "120222443174530122"
                    },
                    "name": {
                      "type": "string",
                      "description": "Ad set name",
                      "example": "Jenni prod ad  5 adset"
                    },
                    "effectiveStatus": {
                      "type": "string",
                      "description": "Status Meta delivers under, including inheritance. `CAMPAIGN_PAUSED` means the parent campaign is paused rather than this ad set.",
                      "example": "CAMPAIGN_PAUSED"
                    },
                    "adAccountId": {
                      "type": "string",
                      "description": "Ad account the ad set belongs to",
                      "example": "act_357046700569338"
                    },
                    "locationId": {
                      "type": "string",
                      "description": "Location the lookup was scoped to",
                      "example": "fRMewNQIxSyZ5R4nQyit"
                    }
                  },
                  "required": [
                    "adSetId",
                    "name",
                    "effectiveStatus",
                    "adAccountId",
                    "locationId"
                  ],
                  "title": "FacebookEntityAdsetDTO"
                }
              }
            },
            "required": [
              "data"
            ],
            "title": "FacebookEntityAdsetsResponseDTO"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "description": "Ads under the requested ad set or campaign",
                "example": [
                  {
                    "adId": "120222443178700122",
                    "name": "Jenni prod ad  5 ad",
                    "status": "PAUSED",
                    "adAccountId": "act_357046700569338",
                    "locationId": "fRMewNQIxSyZ5R4nQyit"
                  }
                ],
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "adId": {
                      "type": "string",
                      "description": "Meta ad id. Note the key is `adId`, not `id`.",
                      "example": "120222443178700122"
                    },
                    "name": {
                      "type": "string",
                      "description": "Ad name",
                      "example": "Jenni prod ad  5 ad"
                    },
                    "status": {
                      "type": "string",
                      "description": "Configured status on the ad. Delivery state is not reported here — no `effectiveStatus` is fetched for ads.",
                      "example": "PAUSED"
                    },
                    "adAccountId": {
                      "type": "string",
                      "description": "Ad account the ad belongs to",
                      "example": "act_357046700569338"
                    },
                    "locationId": {
                      "type": "string",
                      "description": "Location the lookup was scoped to",
                      "example": "fRMewNQIxSyZ5R4nQyit"
                    }
                  },
                  "required": [
                    "adId",
                    "name",
                    "status",
                    "adAccountId",
                    "locationId"
                  ],
                  "title": "FacebookEntityAdDTO"
                }
              },
              "next": {
                "type": "string",
                "description": "Cursor for the next page. Present only when paging by `campaignId`; absent when `adSetId` was given.",
                "example": "QVFIUlpB..."
              }
            },
            "required": [
              "data"
            ],
            "title": "FacebookEntityAdsResponseDTO"
          }
        ]
      },
      "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/entity?locationId=<LOCATIONID>&type=<TYPE>&entityType=<ENTITYTYPE>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: 2021-07-28'
```

**Node.js**

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

try {
  const response = await fetch('https://services.leadconnectorhq.com/ad-publishing/facebook/entity?locationId=<LOCATIONID>&type=<TYPE>&entityType=<ENTITYTYPE>', 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/entity"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "2021-07-28"
}

params = {
    "locationId": "<LOCATIONID>",
    "type": "<TYPE>",
    "entityType": "<ENTITYTYPE>"
}

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/entity?locationId=<LOCATIONID>&type=<TYPE>&entityType=<ENTITYTYPE>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: 2021-07-28',
  ],
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/ad-publishing/facebook/entity?locationId=<LOCATIONID>&type=<TYPE>&entityType=<ENTITYTYPE>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "2021-07-28")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/ad-publishing/facebook/entity?locationId=<LOCATIONID>&type=<TYPE>&entityType=<ENTITYTYPE>"
  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "2021-07-28")

  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/entity?locationId=<LOCATIONID>&type=<TYPE>&entityType=<ENTITYTYPE>")

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-07-28"

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

**PowerShell**

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

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/ad-publishing/facebook/entity?locationId=<LOCATIONID>&type=<TYPE>&entityType=<ENTITYTYPE>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
