# Validate Email Campaign Before Sending

POST https://services.leadconnectorhq.com/emails/locations/{locationId}/campaigns/emails/{campaignId}/validate

Inspect rendered HTML and intended sender metadata for missing subject, sender, unsubscribe link, broken placeholders, merge field syntax the send cannot parse (INVALID_MERGE_FIELD_SYNTAX) and unresolved fields. Optional overrides are checked without saving. ready means no content errors. Warns with SENDER_DOMAIN_NOT_VERIFIED when the sender is not on a location sending domain (see List Sending Domains); it does not verify delivery.

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location ID |
| `campaignId` | string | Yes | Campaign 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/emails/{campaignId}/validate": {
      "post": {
        "summary": "Validate Email Campaign Before Sending",
        "operationId": "validateEmailCampaignBeforeSending",
        "description": "Inspect rendered HTML and intended sender metadata for missing subject, sender, unsubscribe link, broken placeholders, merge field syntax the send cannot parse (INVALID_MERGE_FIELD_SYNTAX) and unresolved fields. Optional overrides are checked without saving. ready means no content errors. Warns with SENDER_DOMAIN_NOT_VERIFIED when the sender is not on a location sending domain (see List Sending Domains); it does not verify delivery.",
        "parameters": [
          {
            "name": "locationId",
            "required": true,
            "in": "path",
            "description": "Location ID",
            "schema": {
              "example": "ve9EPM428h8vShlRW1KT",
              "type": "string"
            }
          },
          {
            "name": "campaignId",
            "required": true,
            "in": "path",
            "description": "Campaign ID",
            "schema": {
              "example": "67f15c2ae99226d5bcccb8f3",
              "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/EmailSendOverridesPublicV3Dto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidateEmailCampaignPublicV3ResponseDto"
                }
              }
            }
          },
          "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"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NotFoundDTO"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "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.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": {
      "EmailSendOverridesPublicV3Dto": {
        "type": "object",
        "properties": {
          "subject": {
            "type": "string",
            "description": "Subject to use for this request. Omit to use the stored subject; an empty string fails send validation.",
            "example": "Holiday sale starts now"
          },
          "fromName": {
            "type": "string",
            "description": "Sender display name for this request. Defaults to the stored sender name; empty string omits the display name.",
            "example": "Anz Studio"
          },
          "fromEmail": {
            "type": "string",
            "description": "Sender email address for this request. Must be a valid email address. Defaults to the stored fromAddress.",
            "example": "hello@anzstudio.com"
          }
        },
        "title": "EmailSendOverridesPublicV3Dto"
      },
      "ValidateEmailCampaignPublicV3ResponseDto": {
        "type": "object",
        "properties": {
          "ready": {
            "type": "boolean",
            "description": "True only when there are no errors. This is a content check, not a delivery or sender-domain verification guarantee.",
            "example": false
          },
          "errors": {
            "description": "Blocking issues that must be corrected before sending.",
            "example": [
              {
                "code": "MISSING_SUBJECT",
                "message": "Add an email subject."
              }
            ],
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "description": "Stable machine-readable check code, for example MISSING_SUBJECT or INVALID_LINK.",
                  "example": "INVALID_LINK"
                },
                "message": {
                  "type": "string",
                  "description": "Explanation of the problem and what to correct before sending.",
                  "example": "Replace the empty, unsafe or placeholder link."
                },
                "detail": {
                  "type": "string",
                  "description": "Offending URL or unresolved merge token. Empty string identifies an empty URL.",
                  "example": "#"
                },
                "variationIndex": {
                  "type": "number",
                  "description": "A/B version the issue belongs to (1 = version B, 2 = version C, ...). Omitted for version A.",
                  "example": 1
                }
              },
              "required": [
                "code",
                "message"
              ],
              "title": "EmailPresendIssuePublicV3Dto"
            }
          },
          "warnings": {
            "description": "Non-blocking issues worth reviewing before sending.",
            "example": [
              {
                "code": "INSECURE_LINK",
                "message": "Use HTTPS for this link.",
                "detail": "http://shop.test",
                "variationIndex": 1
              }
            ],
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "description": "Stable machine-readable check code, for example MISSING_SUBJECT or INVALID_LINK.",
                  "example": "INVALID_LINK"
                },
                "message": {
                  "type": "string",
                  "description": "Explanation of the problem and what to correct before sending.",
                  "example": "Replace the empty, unsafe or placeholder link."
                },
                "detail": {
                  "type": "string",
                  "description": "Offending URL or unresolved merge token. Empty string identifies an empty URL.",
                  "example": "#"
                },
                "variationIndex": {
                  "type": "number",
                  "description": "A/B version the issue belongs to (1 = version B, 2 = version C, ...). Omitted for version A.",
                  "example": 1
                }
              },
              "required": [
                "code",
                "message"
              ],
              "title": "EmailPresendIssuePublicV3Dto"
            }
          },
          "summary": {
            "description": "Effective metadata and counts for the inspected rendered HTML.",
            "example": {
              "subject": "Holiday sale starts now",
              "fromName": "Anz Studio",
              "fromEmail": "hello@anzstudio.com",
              "linkCount": 4,
              "imageCount": 2
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "subject": {
                    "type": "string",
                    "description": "Effective subject after applying request overrides.",
                    "example": "Holiday sale starts now"
                  },
                  "fromName": {
                    "type": "string",
                    "description": "Effective sender display name after applying request overrides.",
                    "example": "Anz Studio"
                  },
                  "fromEmail": {
                    "type": "string",
                    "description": "Effective sender email after applying request overrides.",
                    "example": "hello@anzstudio.com"
                  },
                  "linkCount": {
                    "type": "number",
                    "description": "Number of anchor elements in the rendered HTML, including unsubscribe links.",
                    "example": 4
                  },
                  "imageCount": {
                    "type": "number",
                    "description": "Number of image elements in the rendered HTML.",
                    "example": 2
                  }
                },
                "required": [
                  "subject",
                  "fromName",
                  "fromEmail",
                  "linkCount",
                  "imageCount"
                ],
                "title": "EmailPresendSummaryPublicV3Dto"
              }
            ]
          },
          "unresolvedMergeFields": {
            "description": "All distinct {{...}} tokens found, including standard send-time tokens which do not produce warnings.",
            "example": [
              "{{contact.first_name}}"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "ready",
          "errors",
          "warnings",
          "summary",
          "unresolvedMergeFields"
        ],
        "title": "ValidateEmailCampaignPublicV3ResponseDto"
      },
      "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"
      },
      "NotFoundDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "description": "HTTP status code for not found",
            "example": 404
          },
          "message": {
            "type": "string",
            "description": "Error message describing the not found failure",
            "example": "Not Found"
          },
          "error": {
            "type": "string",
            "description": "Error type identifier",
            "example": "The requested resource was not found"
          }
        },
        "title": "NotFoundDTO"
      },
      "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/emails/<campaignId>/validate' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "subject": "Holiday sale starts now",
  "fromName": "Anz Studio",
  "fromEmail": "hello@anzstudio.com"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "subject": "Holiday sale starts now",
      "fromName": "Anz Studio",
      "fromEmail": "hello@anzstudio.com"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/emails/<campaignId>/validate', 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/emails/{campaignId}/validate"

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

payload = {
    "subject": "Holiday sale starts now",
    "fromName": "Anz Studio",
    "fromEmail": "hello@anzstudio.com"
}

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/emails/<campaignId>/validate',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "subject": "Holiday sale starts now",
  "fromName": "Anz Studio",
  "fromEmail": "hello@anzstudio.com"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/emails/<campaignId>/validate")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"subject\":\"Holiday sale starts now\",\"fromName\":\"Anz Studio\",\"fromEmail\":\"hello@anzstudio.com\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/emails/<campaignId>/validate"
  payload := strings.NewReader(`{
  "subject": "Holiday sale starts now",
  "fromName": "Anz Studio",
  "fromEmail": "hello@anzstudio.com"
}`)
  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/emails/<campaignId>/validate")

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 = '{
  "subject": "Holiday sale starts now",
  "fromName": "Anz Studio",
  "fromEmail": "hello@anzstudio.com"
}'

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

**PowerShell**

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

$body = '{
  "subject": "Holiday sale starts now",
  "fromName": "Anz Studio",
  "fromEmail": "hello@anzstudio.com"
}'

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