# Get segments

GET https://services.leadconnectorhq.com/ad-publishing/google/segments

Retrieve Google Ads audience segments for a location. Without `limit` the response is a plain array. When `limit` is provided (max 100, default 100) the response is a paginated `{ segments, paging }` envelope; pass `pageToken` (from `paging.next`) to fetch the next batch.

## 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 | No | Segment type |
| `limit` | string | No | Page size for a paginated fetch (max 100, defaults to 100). When set, the response is a { segments, paging } envelope instead of a plain array. |
| `pageToken` | string | No | Opaque cursor for the next batch, taken from the previous response paging.next |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ad-publishing/google/segments": {
      "get": {
        "summary": "Get segments",
        "operationId": "getSegments",
        "description": "Retrieve Google Ads audience segments for a location. Without `limit` the response is a plain array. When `limit` is provided (max 100, default 100) the response is a paginated `{ segments, paging }` envelope; pass `pageToken` (from `paging.next`) to fetch the next batch.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "query",
            "description": "Location identifier",
            "schema": {
              "example": "loc_abc123",
              "type": "string"
            }
          },
          {
            "name": "type",
            "required": false,
            "in": "query",
            "description": "Segment type",
            "schema": {
              "example": "CUSTOM_SEGMENTS",
              "enum": [
                "CUSTOM_SEGMENTS",
                "DATA_SEGMENTS",
                "ALL"
              ],
              "type": "string"
            }
          },
          {
            "name": "limit",
            "required": false,
            "in": "query",
            "description": "Page size for a paginated fetch (max 100, defaults to 100). When set, the response is a { segments, paging } envelope instead of a plain array.",
            "schema": {
              "example": "100",
              "type": "string"
            }
          },
          {
            "name": "pageToken",
            "required": false,
            "in": "query",
            "description": "Opaque cursor for the next batch, taken from the previous response paging.next",
            "schema": {
              "example": "100",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A plain array of segments (default), or a { segments, paging } envelope when `limit` is provided",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetSegmentsResponse"
                }
              }
            }
          },
          "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": {
      "GetSegmentsResponse": {
        "oneOf": [
          {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "resourceName": {
                      "type": "string",
                      "description": "Google Ads resource name",
                      "example": "customers/6776452901/customAudiences/874396901"
                    },
                    "id": {
                      "type": "string",
                      "description": "Segment id",
                      "example": "874396901"
                    },
                    "name": {
                      "type": "string",
                      "description": "Segment name",
                      "example": "Running shoe shoppers"
                    },
                    "status": {
                      "type": "string",
                      "description": "Segment status",
                      "example": "ENABLED"
                    },
                    "type": {
                      "type": "string",
                      "description": "Always the literal `CUSTOM_SEGMENTS`. The service overwrites Google's own type with this constant so the value can be used as the discriminator that tells custom-audience entries apart from user-list entries in the merged `ALL` listing.",
                      "enum": [
                        "CUSTOM_SEGMENTS"
                      ],
                      "example": "CUSTOM_SEGMENTS"
                    },
                    "interestType": {
                      "type": "string",
                      "description": "Google's own custom-audience type, moved here because `type` is reused as the discriminator.",
                      "enum": [
                        "AUTO",
                        "INTEREST",
                        "PURCHASE_INTENT",
                        "SEARCH",
                        "UNKNOWN",
                        "UNSPECIFIED"
                      ],
                      "example": "AUTO"
                    },
                    "description": {
                      "type": "string",
                      "description": "Segment description",
                      "example": "Visitors interested in running shoes"
                    }
                  },
                  "required": [
                    "resourceName",
                    "id",
                    "name",
                    "status",
                    "type"
                  ],
                  "title": "GoogleCustomSegmentSummaryDTO"
                },
                {
                  "type": "object",
                  "properties": {
                    "resourceName": {
                      "type": "string",
                      "description": "Google Ads resource name",
                      "example": "customers/6776452901/userLists/9215680180"
                    },
                    "id": {
                      "type": "string",
                      "description": "User list id",
                      "example": "9215680180"
                    },
                    "name": {
                      "type": "string",
                      "description": "User list name",
                      "example": "Website visitors"
                    },
                    "type": {
                      "type": "string",
                      "description": "How the list is populated",
                      "enum": [
                        "CRM_BASED",
                        "WEBSITE_VISITOR",
                        "LOOKALIKE",
                        "LOGICAL",
                        "YOUTUBE"
                      ],
                      "example": "WEBSITE_VISITOR"
                    },
                    "status": {
                      "type": "string",
                      "description": "User list status",
                      "example": "ENABLED"
                    },
                    "membershipStatus": {
                      "type": "string",
                      "description": "Whether the list is open to new members",
                      "example": "OPEN"
                    },
                    "accessReason": {
                      "type": "string",
                      "description": "Whether the account owns the list or it was shared in",
                      "enum": [
                        "OWNED",
                        "SHARED"
                      ],
                      "example": "OWNED"
                    },
                    "accountUserListStatus": {
                      "type": "string",
                      "description": "Status of the list within this account",
                      "example": "ENABLED"
                    },
                    "readOnly": {
                      "type": "boolean",
                      "description": "Whether the list can be edited through the API",
                      "example": false
                    },
                    "sizeForDisplay": {
                      "type": "string",
                      "description": "Display-network size, returned as a string rather than a number",
                      "example": "0"
                    },
                    "sizeForSearch": {
                      "type": "string",
                      "description": "Search-network size, returned as a string rather than a number",
                      "example": "0"
                    },
                    "ruleBasedUserList": {
                      "description": "Rule metadata. Present only for rule-based lists such as WEBSITE_VISITOR and YOUTUBE.",
                      "example": {
                        "prepopulationStatus": "FINISHED"
                      },
                      "allOf": [
                        {
                          "type": "object",
                          "properties": {
                            "prepopulationStatus": {
                              "type": "string",
                              "description": "Whether Google has finished pre-populating the list from historical traffic",
                              "example": "FINISHED"
                            }
                          },
                          "required": [
                            "prepopulationStatus"
                          ],
                          "title": "GoogleRuleBasedUserListInfoDTO"
                        }
                      ]
                    },
                    "logicalUserList": {
                      "type": "object",
                      "description": "Combination metadata. Present only for LOGICAL lists, and returned empty.",
                      "additionalProperties": true,
                      "example": {}
                    }
                  },
                  "required": [
                    "resourceName",
                    "id",
                    "name",
                    "type",
                    "status",
                    "membershipStatus",
                    "accessReason",
                    "accountUserListStatus",
                    "readOnly",
                    "sizeForDisplay",
                    "sizeForSearch"
                  ],
                  "title": "GoogleDataSegmentDTO"
                }
              ]
            }
          },
          {
            "type": "object",
            "properties": {
              "segments": {
                "type": "array",
                "description": "Page of audience segments. Entries are custom audiences or user lists depending on the requested `type`; `ALL` returns both shapes in one array.",
                "items": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "resourceName": {
                          "type": "string",
                          "description": "Google Ads resource name",
                          "example": "customers/6776452901/customAudiences/874396901"
                        },
                        "id": {
                          "type": "string",
                          "description": "Segment id",
                          "example": "874396901"
                        },
                        "name": {
                          "type": "string",
                          "description": "Segment name",
                          "example": "Running shoe shoppers"
                        },
                        "status": {
                          "type": "string",
                          "description": "Segment status",
                          "example": "ENABLED"
                        },
                        "type": {
                          "type": "string",
                          "description": "Always the literal `CUSTOM_SEGMENTS`. The service overwrites Google's own type with this constant so the value can be used as the discriminator that tells custom-audience entries apart from user-list entries in the merged `ALL` listing.",
                          "enum": [
                            "CUSTOM_SEGMENTS"
                          ],
                          "example": "CUSTOM_SEGMENTS"
                        },
                        "interestType": {
                          "type": "string",
                          "description": "Google's own custom-audience type, moved here because `type` is reused as the discriminator.",
                          "enum": [
                            "AUTO",
                            "INTEREST",
                            "PURCHASE_INTENT",
                            "SEARCH",
                            "UNKNOWN",
                            "UNSPECIFIED"
                          ],
                          "example": "AUTO"
                        },
                        "description": {
                          "type": "string",
                          "description": "Segment description",
                          "example": "Visitors interested in running shoes"
                        }
                      },
                      "required": [
                        "resourceName",
                        "id",
                        "name",
                        "status",
                        "type"
                      ],
                      "title": "GoogleCustomSegmentSummaryDTO"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "resourceName": {
                          "type": "string",
                          "description": "Google Ads resource name",
                          "example": "customers/6776452901/userLists/9215680180"
                        },
                        "id": {
                          "type": "string",
                          "description": "User list id",
                          "example": "9215680180"
                        },
                        "name": {
                          "type": "string",
                          "description": "User list name",
                          "example": "Website visitors"
                        },
                        "type": {
                          "type": "string",
                          "description": "How the list is populated",
                          "enum": [
                            "CRM_BASED",
                            "WEBSITE_VISITOR",
                            "LOOKALIKE",
                            "LOGICAL",
                            "YOUTUBE"
                          ],
                          "example": "WEBSITE_VISITOR"
                        },
                        "status": {
                          "type": "string",
                          "description": "User list status",
                          "example": "ENABLED"
                        },
                        "membershipStatus": {
                          "type": "string",
                          "description": "Whether the list is open to new members",
                          "example": "OPEN"
                        },
                        "accessReason": {
                          "type": "string",
                          "description": "Whether the account owns the list or it was shared in",
                          "enum": [
                            "OWNED",
                            "SHARED"
                          ],
                          "example": "OWNED"
                        },
                        "accountUserListStatus": {
                          "type": "string",
                          "description": "Status of the list within this account",
                          "example": "ENABLED"
                        },
                        "readOnly": {
                          "type": "boolean",
                          "description": "Whether the list can be edited through the API",
                          "example": false
                        },
                        "sizeForDisplay": {
                          "type": "string",
                          "description": "Display-network size, returned as a string rather than a number",
                          "example": "0"
                        },
                        "sizeForSearch": {
                          "type": "string",
                          "description": "Search-network size, returned as a string rather than a number",
                          "example": "0"
                        },
                        "ruleBasedUserList": {
                          "description": "Rule metadata. Present only for rule-based lists such as WEBSITE_VISITOR and YOUTUBE.",
                          "example": {
                            "prepopulationStatus": "FINISHED"
                          },
                          "allOf": [
                            {
                              "type": "object",
                              "properties": {
                                "prepopulationStatus": {
                                  "type": "string",
                                  "description": "Whether Google has finished pre-populating the list from historical traffic",
                                  "example": "FINISHED"
                                }
                              },
                              "required": [
                                "prepopulationStatus"
                              ],
                              "title": "GoogleRuleBasedUserListInfoDTO"
                            }
                          ]
                        },
                        "logicalUserList": {
                          "type": "object",
                          "description": "Combination metadata. Present only for LOGICAL lists, and returned empty.",
                          "additionalProperties": true,
                          "example": {}
                        }
                      },
                      "required": [
                        "resourceName",
                        "id",
                        "name",
                        "type",
                        "status",
                        "membershipStatus",
                        "accessReason",
                        "accountUserListStatus",
                        "readOnly",
                        "sizeForDisplay",
                        "sizeForSearch"
                      ],
                      "title": "GoogleDataSegmentDTO"
                    }
                  ]
                },
                "example": [
                  {
                    "resourceName": "customers/6776452901/customAudiences/874396901",
                    "id": "874396901",
                    "name": "Running shoe shoppers",
                    "status": "ENABLED",
                    "type": "CUSTOM_SEGMENTS",
                    "interestType": "AUTO",
                    "description": "Visitors interested in running shoes"
                  }
                ]
              },
              "paging": {
                "description": "Pagination cursor",
                "example": {
                  "next": "100"
                },
                "allOf": [
                  {
                    "type": "object",
                    "properties": {
                      "next": {
                        "type": "string",
                        "description": "Cursor for the next page of results, or null when there are no more pages",
                        "example": "100",
                        "nullable": true
                      }
                    },
                    "required": [
                      "next"
                    ],
                    "title": "GoogleSegmentsPagingDTO"
                  }
                ]
              }
            },
            "required": [
              "segments",
              "paging"
            ],
            "title": "PaginatedGoogleSegmentsDTO"
          }
        ]
      },
      "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/google/segments?locationId=<LOCATIONID>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

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

try {
  const response = await fetch('https://services.leadconnectorhq.com/ad-publishing/google/segments?locationId=<LOCATIONID>', 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/google/segments"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

params = {
    "locationId": "<LOCATIONID>"
}

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/google/segments?locationId=<LOCATIONID>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/ad-publishing/google/segments?locationId=<LOCATIONID>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/ad-publishing/google/segments?locationId=<LOCATIONID>"
  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  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/google/segments?locationId=<LOCATIONID>")

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

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

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

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/ad-publishing/google/segments?locationId=<LOCATIONID>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
