# Estimate Recipients

POST https://services.leadconnectorhq.com/emails/locations/{locationId}/campaigns/recipients/estimate

Count how many contacts match an audience right now (contact, tag, segment, smart_list, custom_segment or all) and get a one-line summary to confirm with the user before scheduling. The count is before send-time suppression: do-not-disturb, unsubscribed and contacts without a valid email are skipped at send, so tell the user it is the most that can receive the campaign, not a delivery count. Returns the count only, never contact ids. Write-scoped because an exact count for any filter would otherwise let a read-only token enumerate contacts.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `emails/campaigns.write`

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location ID |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/emails/locations/{locationId}/campaigns/recipients/estimate": {
      "post": {
        "summary": "Estimate Recipients",
        "operationId": "estimateRecipients",
        "description": "Count how many contacts match an audience right now (contact, tag, segment, smart_list, custom_segment or all) and get a one-line summary to confirm with the user before scheduling. The count is before send-time suppression: do-not-disturb, unsubscribed and contacts without a valid email are skipped at send, so tell the user it is the most that can receive the campaign, not a delivery count. Returns the count only, never contact ids. Write-scoped because an exact count for any filter would otherwise let a read-only token enumerate contacts.",
        "parameters": [
          {
            "name": "locationId",
            "required": true,
            "in": "path",
            "description": "Location ID",
            "schema": {
              "example": "ve9EPM428h8vShlRW1KT",
              "type": "string"
            }
          },
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CampaignAudiencePublicV3Dto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EstimateRecipientsPublicV3ResponseDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "403": {
            "description": "The token does not have access to this location",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvalidLocationDTO"
                }
              }
            }
          },
          "422": {
            "description": "The audience cannot resolve, e.g. an empty tag list",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - rate limit exceeded; retry after a short delay"
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InternalServerErrorDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "emails/campaigns.write"
            ]
          }
        ]
      }
    }
  },
  "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": {
      "CampaignAudiencePublicV3Dto": {
        "type": "object",
        "properties": {
          "contactIds": {
            "description": "Required when type is contact",
            "example": [
              "8eHQB5vTbGKdK9UWXL3G"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "tagIds": {
            "description": "Required when type is tag",
            "example": [
              "6YMlGPn0LHi5OmJaXdLB"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "segment": {
            "type": "string",
            "description": "Required when type is segment",
            "enum": [
              "engaged_last_7_days",
              "engaged_last_30_days",
              "engaged_last_60_days",
              "engaged_last_5_campaigns",
              "unengaged_last_5_campaigns"
            ],
            "example": "engaged_last_30_days"
          },
          "smartListIds": {
            "description": "Required when type is smart_list. Only the first is used.",
            "example": [
              "f2a6b1c4-3d1e-4c8e-9a7b-2f4c6e8d0a1b"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "conditions": {
            "description": "Required when type is custom_segment",
            "example": [
              {
                "kind": "tag",
                "values": [
                  "6YMlGPn0LHi5OmJaXdLB"
                ],
                "negate": false
              }
            ],
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "description": "What this row matches on",
                  "enum": [
                    "contact",
                    "tag",
                    "smart_list",
                    "segment"
                  ],
                  "example": "tag"
                },
                "values": {
                  "description": "Contact ids, tag ids, smart list ids, or one segment type",
                  "example": [
                    "6YMlGPn0LHi5OmJaXdLB"
                  ],
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "negate": {
                  "type": "boolean",
                  "description": "`is-not`. Unsupported for smart lists.",
                  "example": false
                },
                "join": {
                  "type": "string",
                  "description": "Operator joining this row to the previous one",
                  "enum": [
                    "and",
                    "or"
                  ],
                  "example": "and"
                }
              },
              "title": "AudienceConditionDto"
            }
          },
          "freezeList": {
            "type": "boolean",
            "description": "Freeze the contact list at schedule time",
            "example": false
          },
          "type": {
            "type": "string",
            "description": "Who receives the campaign: contact (contactIds), tag (tagIds), segment, smart_list (smartListIds; first is used), custom_segment (conditions) or all (every contact in the location).",
            "enum": [
              "contact",
              "tag",
              "segment",
              "smart_list",
              "custom_segment",
              "all"
            ],
            "example": "smart_list"
          }
        },
        "required": [
          "type"
        ],
        "title": "CampaignAudiencePublicV3Dto"
      },
      "EstimateRecipientsPublicV3ResponseDto": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "Audience type that was estimated.",
            "enum": [
              "contact",
              "tag",
              "segment",
              "smart_list",
              "custom_segment",
              "all"
            ],
            "example": "smart_list"
          },
          "count": {
            "type": "number",
            "description": "Contacts matching this audience right now, before send-time suppression. Contacts with email do-not-disturb, unsubscribed, or without a valid email are skipped when the campaign sends, so fewer may receive it.",
            "example": 1240
          },
          "description": {
            "type": "string",
            "description": "One-line summary to show the user before scheduling.",
            "example": "Smart list"
          }
        },
        "required": [
          "type",
          "count"
        ],
        "title": "EstimateRecipientsPublicV3ResponseDto"
      },
      "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"
      },
      "InvalidLocationDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "description": "HTTP status code for invalid location access",
            "example": 403
          },
          "message": {
            "type": "string",
            "description": "Error message describing the location access failure",
            "example": "The token does not have access to this location"
          }
        },
        "title": "InvalidLocationDTO"
      },
      "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 POST 'https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/recipients/estimate' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "contactIds": [
    "8eHQB5vTbGKdK9UWXL3G"
  ],
  "tagIds": [
    "6YMlGPn0LHi5OmJaXdLB"
  ],
  "segment": "engaged_last_30_days",
  "smartListIds": [
    "f2a6b1c4-3d1e-4c8e-9a7b-2f4c6e8d0a1b"
  ],
  "conditions": [
    {
      "kind": "tag",
      "values": [
        "6YMlGPn0LHi5OmJaXdLB"
      ],
      "negate": false
    }
  ],
  "freezeList": false,
  "type": "smart_list"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "contactIds": [
        "8eHQB5vTbGKdK9UWXL3G"
      ],
      "tagIds": [
        "6YMlGPn0LHi5OmJaXdLB"
      ],
      "segment": "engaged_last_30_days",
      "smartListIds": [
        "f2a6b1c4-3d1e-4c8e-9a7b-2f4c6e8d0a1b"
      ],
      "conditions": [
        {
          "kind": "tag",
          "values": [
            "6YMlGPn0LHi5OmJaXdLB"
          ],
          "negate": false
        }
      ],
      "freezeList": false,
      "type": "smart_list"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/recipients/estimate', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/emails/locations/{locationId}/campaigns/recipients/estimate"

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

payload = {
    "contactIds": [
        "8eHQB5vTbGKdK9UWXL3G"
    ],
    "tagIds": [
        "6YMlGPn0LHi5OmJaXdLB"
    ],
    "segment": "engaged_last_30_days",
    "smartListIds": [
        "f2a6b1c4-3d1e-4c8e-9a7b-2f4c6e8d0a1b"
    ],
    "conditions": [
        {
            "kind": "tag",
            "values": [
                "6YMlGPn0LHi5OmJaXdLB"
            ],
            "negate": false
        }
    ],
    "freezeList": false,
    "type": "smart_list"
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

**PHP**

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

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/recipients/estimate',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "contactIds": [
    "8eHQB5vTbGKdK9UWXL3G"
  ],
  "tagIds": [
    "6YMlGPn0LHi5OmJaXdLB"
  ],
  "segment": "engaged_last_30_days",
  "smartListIds": [
    "f2a6b1c4-3d1e-4c8e-9a7b-2f4c6e8d0a1b"
  ],
  "conditions": [
    {
      "kind": "tag",
      "values": [
        "6YMlGPn0LHi5OmJaXdLB"
      ],
      "negate": false
    }
  ],
  "freezeList": false,
  "type": "smart_list"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/recipients/estimate")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"contactIds\":[\"8eHQB5vTbGKdK9UWXL3G\"],\"tagIds\":[\"6YMlGPn0LHi5OmJaXdLB\"],\"segment\":\"engaged_last_30_days\",\"smartListIds\":[\"f2a6b1c4-3d1e-4c8e-9a7b-2f4c6e8d0a1b\"],\"conditions\":[{\"kind\":\"tag\",\"values\":[\"6YMlGPn0LHi5OmJaXdLB\"],\"negate\":false}],\"freezeList\":false,\"type\":\"smart_list\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/recipients/estimate"
  payload := strings.NewReader(`{
  "contactIds": [
    "8eHQB5vTbGKdK9UWXL3G"
  ],
  "tagIds": [
    "6YMlGPn0LHi5OmJaXdLB"
  ],
  "segment": "engaged_last_30_days",
  "smartListIds": [
    "f2a6b1c4-3d1e-4c8e-9a7b-2f4c6e8d0a1b"
  ],
  "conditions": [
    {
      "kind": "tag",
      "values": [
        "6YMlGPn0LHi5OmJaXdLB"
      ],
      "negate": false
    }
  ],
  "freezeList": false,
  "type": "smart_list"
}`)
  req, _ := http.NewRequest("POST", url, payload)
  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/emails/locations/<locationId>/campaigns/recipients/estimate")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "contactIds": [
    "8eHQB5vTbGKdK9UWXL3G"
  ],
  "tagIds": [
    "6YMlGPn0LHi5OmJaXdLB"
  ],
  "segment": "engaged_last_30_days",
  "smartListIds": [
    "f2a6b1c4-3d1e-4c8e-9a7b-2f4c6e8d0a1b"
  ],
  "conditions": [
    {
      "kind": "tag",
      "values": [
        "6YMlGPn0LHi5OmJaXdLB"
      ],
      "negate": false
    }
  ],
  "freezeList": false,
  "type": "smart_list"
}'

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

**PowerShell**

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

$body = '{
  "contactIds": [
    "8eHQB5vTbGKdK9UWXL3G"
  ],
  "tagIds": [
    "6YMlGPn0LHi5OmJaXdLB"
  ],
  "segment": "engaged_last_30_days",
  "smartListIds": [
    "f2a6b1c4-3d1e-4c8e-9a7b-2f4c6e8d0a1b"
  ],
  "conditions": [
    {
      "kind": "tag",
      "values": [
        "6YMlGPn0LHi5OmJaXdLB"
      ],
      "negate": false
    }
  ],
  "freezeList": false,
  "type": "smart_list"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/recipients/estimate' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
