# Get segment by ID

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

Retrieve a specific Google Ads audience segment by ID

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `segmentId` | string | Yes | Segment identifier |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location identifier |
| `type` | string | Yes | Segment type |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "v4"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ad-publishing/google/segments/{segmentId}": {
      "get": {
        "summary": "Get segment by ID",
        "operationId": "getSegmentById",
        "description": "Retrieve a specific Google Ads audience segment by ID",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v4"
              ]
            }
          },
          {
            "name": "segmentId",
            "required": true,
            "in": "path",
            "description": "Segment identifier",
            "schema": {
              "example": "seg_abc123",
              "type": "string"
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "query",
            "description": "Location identifier",
            "schema": {
              "example": "HChooFuiyPpVYzeJ4HMe",
              "type": "string"
            }
          },
          {
            "name": "type",
            "required": true,
            "in": "query",
            "description": "Segment type",
            "schema": {
              "example": "CUSTOM_SEGMENTS",
              "enum": [
                "CUSTOM_SEGMENTS",
                "DATA_SEGMENTS"
              ],
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The segment, shaped by the requested `type`. `CUSTOM_SEGMENTS` returns a custom audience with `status` and `members`; `DATA_SEGMENTS` returns a Google user list with rules, sizes, access metadata, and an optional `extras` block holding this product's own record.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetSegmentByIdResponse"
                }
              }
            }
          },
          "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": {
      "GetSegmentByIdResponse": {
        "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"
              },
              "status": {
                "type": "string",
                "description": "Segment status",
                "example": "ENABLED"
              },
              "name": {
                "type": "string",
                "description": "Segment name",
                "example": "Running shoe shoppers"
              },
              "type": {
                "type": "string",
                "description": "Google custom-audience type. `AUTO` is the default applied when none is supplied on create.",
                "example": "AUTO"
              },
              "members": {
                "description": "Keywords, URLs and apps that define the segment",
                "example": [
                  {
                    "memberType": "KEYWORD",
                    "keyword": "running shoes",
                    "url": "www.example.com",
                    "app": "app.example.com"
                  }
                ],
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "memberType": {
                      "type": "string",
                      "description": "Which member field is populated on this entry",
                      "enum": [
                        "KEYWORD",
                        "URL",
                        "APP"
                      ],
                      "example": "KEYWORD"
                    },
                    "keyword": {
                      "type": "string",
                      "description": "Keyword, present when memberType is KEYWORD",
                      "example": "running shoes"
                    },
                    "url": {
                      "type": "string",
                      "description": "URL, present when memberType is URL",
                      "example": "www.example.com"
                    },
                    "app": {
                      "type": "string",
                      "description": "App identifier, present when memberType is APP",
                      "example": "app.example.com"
                    }
                  },
                  "required": [
                    "memberType"
                  ],
                  "title": "GoogleSegmentMemberDTO"
                }
              }
            },
            "required": [
              "resourceName",
              "id",
              "status",
              "name",
              "type",
              "members"
            ],
            "title": "GoogleSegmentDetailDTO"
          },
          {
            "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. Unlike the listing endpoint, this value is not remapped.",
                "enum": [
                  "CRM_BASED",
                  "RULE_BASED",
                  "LOOKALIKE",
                  "LOGICAL",
                  "EXTERNAL_REMARKETING",
                  "SIMILAR"
                ],
                "example": "RULE_BASED"
              },
              "description": {
                "type": "string",
                "description": "User list description",
                "example": "Visitors in the last 30 days"
              },
              "readOnly": {
                "type": "boolean",
                "description": "Whether the list can be edited through the API",
                "example": false
              },
              "accessReason": {
                "type": "string",
                "description": "Whether the account owns the list or it was shared in",
                "enum": [
                  "OWNED",
                  "SHARED"
                ],
                "example": "OWNED"
              },
              "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"
              },
              "basicUserList": {
                "type": "object",
                "description": "Tag actions backing a basic list. Present for basic user lists only.",
                "additionalProperties": true,
                "example": {
                  "actions": [
                    {
                      "conversionAction": "customers/6776452901/conversionActions/7618389481"
                    }
                  ]
                }
              },
              "ruleBasedUserList": {
                "type": "object",
                "description": "Rule definition and pre-population status. Present for rule-based lists, and carries the flexible-rule operands when the list uses them.",
                "additionalProperties": true,
                "example": {
                  "prepopulationStatus": "FINISHED"
                }
              },
              "crmBasedUserList": {
                "type": "object",
                "description": "Source app for a CRM-based list. Present for CRM_BASED lists only.",
                "additionalProperties": true,
                "example": {
                  "uploadKeyType": "CONTACT_INFO",
                  "dataSourceType": "FIRST_PARTY"
                }
              },
              "logicalUserList": {
                "type": "object",
                "description": "Combination rules. Present for LOGICAL lists only.",
                "additionalProperties": true,
                "example": {
                  "rules": [
                    {
                      "operator": "ALL",
                      "ruleOperands": [
                        {
                          "userList": "customers/6776452901/userLists/9215680180"
                        }
                      ]
                    }
                  ]
                }
              },
              "lookalikeUserList": {
                "type": "object",
                "description": "Seed lists, country codes, and expansion level. Present for LOOKALIKE lists only.",
                "additionalProperties": true,
                "example": {
                  "seedUserListIds": [
                    "9215680180"
                  ],
                  "countryCodes": [
                    "US"
                  ],
                  "expansionLevel": "BALANCED"
                }
              },
              "extras": {
                "type": "object",
                "description": "This product's own record of the list, merged in when one exists locally. Absent for lists this service did not create.",
                "additionalProperties": true,
                "example": {
                  "locationId": "ve9EPM428h8vShlRW1KT",
                  "segmentId": "9215680180",
                  "source": "smartList"
                }
              }
            },
            "required": [
              "resourceName",
              "id",
              "name",
              "type"
            ],
            "title": "GoogleDataSegmentDetailDTO"
          }
        ]
      },
      "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/<segmentId>?locationId=<LOCATIONID>&type=<TYPE>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v4'
```

**Node.js**

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

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

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

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

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

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

**Java**

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

**Go**

```go
package main

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

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

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

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

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

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

**PowerShell**

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

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