# Get Campaign Statistics

GET https://services.leadconnectorhq.com/emails/locations/{locationId}/campaigns/stats/{source}/{sourceId}

Get statistics for email campaigns, workflows, or bulk actions

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location ID |
| `source` | string | Yes | Source type: email-campaigns, workflow-campaigns, or bulk-actions |
| `sourceId` | string | Yes | Source ID of the email campaign, workflow campaign, or bulk action |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `subSourceId` | string | No | Workflow action ID. Only valid when source is `workflow-campaigns` |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/emails/locations/{locationId}/campaigns/stats/{source}/{sourceId}": {
      "get": {
        "summary": "Get Campaign Statistics",
        "operationId": "getCampaignStatistics",
        "description": "Get statistics for email campaigns, workflows, or bulk actions",
        "parameters": [
          {
            "name": "locationId",
            "required": true,
            "in": "path",
            "description": "Location ID",
            "schema": {
              "example": "ve9EPM428h8vShlRW1KT",
              "type": "string"
            }
          },
          {
            "name": "source",
            "required": true,
            "in": "path",
            "description": "Source type: email-campaigns, workflow-campaigns, or bulk-actions",
            "schema": {
              "example": "email-campaigns",
              "enum": [
                "email-campaigns",
                "workflow-campaigns",
                "bulk-actions"
              ],
              "type": "string"
            }
          },
          {
            "name": "sourceId",
            "required": true,
            "in": "path",
            "description": "Source ID of the email campaign, workflow campaign, or bulk action",
            "schema": {
              "example": "abc123",
              "type": "string"
            }
          },
          {
            "name": "subSourceId",
            "required": false,
            "in": "query",
            "description": "Workflow action ID. Only valid when source is `workflow-campaigns`",
            "schema": {
              "example": "step001",
              "type": "string"
            }
          },
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetCampaignStatsPublicV2ResponseDto"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "emails/stats.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": {
      "GetCampaignStatsPublicV2ResponseDto": {
        "type": "object",
        "properties": {
          "locationId": {
            "type": "string",
            "description": "Location ID",
            "example": "abc123"
          },
          "source": {
            "type": "string",
            "description": "Source type",
            "enum": [
              "email-campaigns",
              "workflow-campaigns",
              "bulk-actions"
            ],
            "example": "email-campaigns"
          },
          "sourceId": {
            "type": "string",
            "description": "Source ID",
            "example": "campaign123"
          },
          "subSourceId": {
            "type": "string",
            "description": "Workflow action ID",
            "example": "step001"
          },
          "stats": {
            "description": "Email performance metrics",
            "example": {
              "sent": 1020,
              "accepted": 5,
              "delivered": 1000,
              "opened": 450,
              "clicked": 120,
              "unsubscribed": 5,
              "complained": 2,
              "permanentFail": 15,
              "temporaryFail": 3,
              "rejected": 10,
              "failed": 5,
              "replied": 25,
              "openRate": 45,
              "clickRate": 12,
              "unsubscribeRate": 0.5,
              "complaintRate": 0.2,
              "bounceRate": 1.76,
              "replyRate": 2.5
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "sent": {
                    "type": "number",
                    "description": "Total emails sent (delivered + accepted + bounced)",
                    "example": 1020
                  },
                  "accepted": {
                    "type": "number",
                    "description": "Emails accepted by the mail server",
                    "example": 5
                  },
                  "delivered": {
                    "type": "number",
                    "description": "Emails delivered to inbox",
                    "example": 1000
                  },
                  "opened": {
                    "type": "number",
                    "description": "Emails opened",
                    "example": 450
                  },
                  "clicked": {
                    "type": "number",
                    "description": "Links clicked",
                    "example": 120
                  },
                  "unsubscribed": {
                    "type": "number",
                    "description": "Unsubscribes",
                    "example": 5
                  },
                  "complained": {
                    "type": "number",
                    "description": "Spam complaints",
                    "example": 2
                  },
                  "permanentFail": {
                    "type": "number",
                    "description": "Hard bounces",
                    "example": 15
                  },
                  "temporaryFail": {
                    "type": "number",
                    "description": "Soft bounces",
                    "example": 3
                  },
                  "rejected": {
                    "type": "number",
                    "description": "Rejected emails",
                    "example": 10
                  },
                  "failed": {
                    "type": "number",
                    "description": "Failed emails",
                    "example": 5
                  },
                  "replied": {
                    "type": "number",
                    "description": "Replies received",
                    "example": 25
                  },
                  "openRate": {
                    "type": "number",
                    "description": "Open rate as percentage of delivered",
                    "example": 45
                  },
                  "clickRate": {
                    "type": "number",
                    "description": "Click rate as percentage of delivered",
                    "example": 12
                  },
                  "unsubscribeRate": {
                    "type": "number",
                    "description": "Unsubscribe rate as percentage of delivered",
                    "example": 0.5
                  },
                  "complaintRate": {
                    "type": "number",
                    "description": "Complaint rate as percentage of delivered",
                    "example": 0.2
                  },
                  "bounceRate": {
                    "type": "number",
                    "description": "Bounce rate as percentage of sent",
                    "example": 1.76
                  },
                  "replyRate": {
                    "type": "number",
                    "description": "Reply rate as percentage of delivered",
                    "example": 2.5
                  }
                },
                "required": [
                  "sent",
                  "accepted",
                  "delivered",
                  "opened",
                  "clicked",
                  "unsubscribed",
                  "complained",
                  "permanentFail",
                  "temporaryFail",
                  "rejected",
                  "failed",
                  "replied",
                  "openRate",
                  "clickRate",
                  "unsubscribeRate",
                  "complaintRate",
                  "bounceRate",
                  "replyRate"
                ],
                "title": "EmailStatsNumbersPublicV2Dto"
              }
            ]
          },
          "traceId": {
            "type": "string",
            "description": "Trace ID of the request",
            "example": "019e4ef5-a65e-4198-8cf9-8e93dca9bda4"
          }
        },
        "required": [
          "locationId",
          "source",
          "sourceId",
          "stats"
        ],
        "title": "GetCampaignStatsPublicV2ResponseDto"
      },
      "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"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/stats/<source>/<sourceId>' \
  -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/emails/locations/<locationId>/campaigns/stats/<source>/<sourceId>', 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/stats/{source}/{sourceId}"

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

response = requests.get(url, 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/stats/<source>/<sourceId>',
  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/emails/locations/<locationId>/campaigns/stats/<source>/<sourceId>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/emails/locations/<locationId>/campaigns/stats/<source>/<sourceId>"
  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/emails/locations/<locationId>/campaigns/stats/<source>/<sourceId>")

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/emails/locations/<locationId>/campaigns/stats/<source>/<sourceId>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
