# Update email message status

PUT https://services.leadconnectorhq.com/conversations/messages/email/{emailMessageId}/status

Update delivery events, per-recipient statuses, and the overall message status for an email sent via a custom conversation provider.

### Authorization
- Requires the `conversations/message.write` OAuth scope.
- The calling OAuth app must own the conversation provider that originally sent the email.
- Attempts to update emails sent via LC Email or Mailgun will return `403 Forbidden`.

### Updatable Fields
All request body fields are optional. Pass only what you need to update.

**`events`** — Aggregate delivery event counters (integers). Counters are merged into the existing values (not replaced). Setting a counter to `0` is treated as no-op and will **not** reset the stored value.

**`recipients`** — Per-recipient delivery statuses. Each entry maps a recipient email address to a `MessageStatus` value. Use `failReason` to capture bounce or rejection details when the status is `failed`.

**`status`** — The overall message status. Accepts any `MessageStatus` enum value.

### Event Inference
The API automatically infers related events to maintain data consistency:
- **`clicked`, `complained`, `unsubscribed`, or `replied`** → implies `opened` (set to 1 if not already provided and open tracking is enabled) and `delivered` (set to 1).
- **`opened`** → implies `delivered` (set to 1 if not provided).
- **`delivered`, `permanent_fail`, or `temporary_fail`** → implies `accepted` (set to 1 if not provided).

### Timestamps
The API automatically records server-side timestamps on first occurrence for `delivered`, `opened`, and `clicked` events. Subsequent updates to these counters do not overwrite the original timestamp.

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `emailMessageId` | string | Yes | Email Message Id |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/conversations/messages/email/{emailMessageId}/status": {
      "put": {
        "summary": "Update email message status",
        "operationId": "updateEmailMessageStatus",
        "description": "Update delivery events, per-recipient statuses, and the overall message status for an email sent via a custom conversation provider.\n\n### Authorization\n- Requires the `conversations/message.write` OAuth scope.\n- The calling OAuth app must own the conversation provider that originally sent the email.\n- Attempts to update emails sent via LC Email or Mailgun will return `403 Forbidden`.\n\n### Updatable Fields\nAll request body fields are optional. Pass only what you need to update.\n\n**`events`** — Aggregate delivery event counters (integers). Counters are merged into the existing values (not replaced). Setting a counter to `0` is treated as no-op and will **not** reset the stored value.\n\n**`recipients`** — Per-recipient delivery statuses. Each entry maps a recipient email address to a `MessageStatus` value. Use `failReason` to capture bounce or rejection details when the status is `failed`.\n\n**`status`** — The overall message status. Accepts any `MessageStatus` enum value.\n\n### Event Inference\nThe API automatically infers related events to maintain data consistency:\n- **`clicked`, `complained`, `unsubscribed`, or `replied`** → implies `opened` (set to 1 if not already provided and open tracking is enabled) and `delivered` (set to 1).\n- **`opened`** → implies `delivered` (set to 1 if not provided).\n- **`delivered`, `permanent_fail`, or `temporary_fail`** → implies `accepted` (set to 1 if not provided).\n\n### Timestamps\nThe API automatically records server-side timestamps on first occurrence for `delivered`, `opened`, and `clicked` events. Subsequent updates to these counters do not overwrite the original timestamp.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "emailMessageId",
            "required": true,
            "in": "path",
            "description": "Email Message Id",
            "schema": {
              "example": "ve9EPM428h8vShlRW1KT",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateEmailMessageStatusDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Email message status updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdateEmailMessageStatusResponseDto"
                }
              }
            }
          },
          "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": "Forbidden - status updates are only supported for custom conversation provider emails",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ForbiddenDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "conversations/message.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"
      }
    },
    "schemas": {
      "UpdateEmailMessageStatusDto": {
        "type": "object",
        "description": "Request body to update the delivery status of an email message. `status` is required. `events` and `recipients` are optional and may be included together with `status`.\n\n- Use `events` to report aggregate delivery metrics (delivered count, open count, etc.).\n- Use `recipients` to track per-recipient delivery outcomes for multi-recipient emails.\n- Use `status` to set the overall message status.\n\nMultiple calls are additive — event counters are merged, recipient statuses are upserted, and the message status is overwritten.",
        "required": [
          "status"
        ],
        "properties": {
          "events": {
            "description": "Aggregate delivery event counters. Counters are merged into existing values. The API automatically infers related events (e.g., reporting `clicked` will also set `opened` and `delivered` if not already present). See the endpoint description for the full inference rules.",
            "allOf": [
              {
                "type": "object",
                "description": "Aggregate delivery event counters for the email message. Values are merged into existing stored counters (additive update, not replacement). A value of `0` is treated as a no-op and will not reset the stored counter. Only include fields you want to update. Provider-specific counters such as `permanent_fail`, `temporary_fail`, and `esp_isp_block` may be sent using those snake_case keys.",
                "additionalProperties": {
                  "type": "integer",
                  "description": "Additional provider event counter (merged into stored values)."
                },
                "properties": {
                  "delivered": {
                    "type": "integer",
                    "description": "Number of successful deliveries — the recipient mail server accepted the message. Automatically inferred (set to 1) when `opened`, `clicked`, `complained`, `unsubscribed`, or `replied` events are reported.",
                    "example": 1
                  },
                  "opened": {
                    "type": "integer",
                    "description": "Number of unique open events (typically tracked via a tracking pixel). Automatically inferred (set to 1) when `clicked`, `complained`, `unsubscribed`, or `replied` events are reported, provided open tracking is enabled on the email.",
                    "example": 3
                  },
                  "clicked": {
                    "type": "integer",
                    "description": "Number of link click events within the email body. Triggers automatic inference of both `opened` and `delivered`.",
                    "example": 1
                  },
                  "replied": {
                    "type": "integer",
                    "description": "Number of reply events. Triggers automatic inference of both `opened` (if open tracking is enabled) and `delivered`.",
                    "example": 1
                  },
                  "failed": {
                    "type": "integer",
                    "description": "Total number of delivery failures (includes both permanent and temporary). For more granular failure tracking, use `permanent_fail` and `temporary_fail` instead.",
                    "example": 0
                  },
                  "accepted": {
                    "type": "integer",
                    "description": "Number of messages accepted by the receiving mail server for delivery. Automatically inferred (set to 1) when `delivered`, `permanent_fail`, or `temporary_fail` events are reported.",
                    "example": 1
                  },
                  "rejected": {
                    "type": "integer",
                    "description": "Number of messages rejected outright by the receiving mail server (before acceptance).",
                    "example": 0
                  },
                  "unsubscribed": {
                    "type": "integer",
                    "description": "Number of unsubscribe events triggered by the recipient. Triggers automatic inference of `opened` and `delivered`.",
                    "example": 0
                  },
                  "complained": {
                    "type": "integer",
                    "description": "Number of spam complaint events (e.g., recipient marked the email as spam). Triggers automatic inference of `opened` and `delivered`.",
                    "example": 0
                  },
                  "stored": {
                    "type": "integer",
                    "description": "Number of messages stored by the email service provider (ESP-specific event).",
                    "example": 0
                  }
                },
                "title": "EmailEventsDto"
              }
            ],
            "example": {
              "delivered": 1,
              "opened": 1
            }
          },
          "recipients": {
            "type": "array",
            "description": "Per-recipient delivery statuses. Each entry maps a recipient email address to a delivery status. Entries are upserted — if a recipient already has a status, it will be overwritten with the new value.",
            "items": {
              "type": "object",
              "description": "Delivery status for an individual recipient of a multi-recipient email. Each entry is keyed by the recipient's email address and tracks their specific delivery outcome independently from the aggregate event counters.",
              "properties": {
                "emailId": {
                  "type": "string",
                  "description": "The recipient's email address. This is used as the key to store and update the per-recipient status. Must match one of the original recipients of the email.",
                  "example": "john@doe.com"
                },
                "status": {
                  "type": "string",
                  "description": "The delivery status for this specific recipient. Common values for status updates: `delivered` (successfully delivered), `failed` (delivery failed — provide `failReason`), `opened` (recipient opened the email), `clicked` (recipient clicked a link).",
                  "enum": [
                    "pending",
                    "scheduled",
                    "sent",
                    "delivered",
                    "read",
                    "undelivered",
                    "connected",
                    "failed",
                    "opened",
                    "clicked"
                  ],
                  "example": "delivered"
                },
                "failReason": {
                  "type": "string",
                  "description": "Human-readable reason for the delivery failure. Only applicable when `status` is `failed`. Examples: \"Mailbox not found\", \"Quota exceeded\", \"Blocked by recipient server\".",
                  "example": "Mailbox not found"
                }
              },
              "required": [
                "emailId",
                "status"
              ],
              "title": "UpdateRecipientMessageStatusDto"
            },
            "example": [
              {
                "emailId": "john@example.com",
                "status": "delivered"
              }
            ]
          },
          "status": {
            "type": "string",
            "description": "The overall status of the email message. Required on every request. For emails with multiple recipients, consider using the `recipients` array for granular tracking and this field for the aggregate status.",
            "enum": [
              "pending",
              "scheduled",
              "sent",
              "delivered",
              "read",
              "undelivered",
              "connected",
              "failed",
              "opened",
              "clicked"
            ],
            "example": "delivered"
          }
        },
        "title": "UpdateEmailMessageStatusDto"
      },
      "UpdateEmailMessageStatusResponseDto": {
        "type": "object",
        "description": "Response returned after successfully updating the email message status.",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "Whether the status update was persisted successfully.",
            "example": true
          },
          "message": {
            "type": "string",
            "description": "Human-readable result message.",
            "example": "Updated email message successfully"
          }
        },
        "required": [
          "success",
          "message"
        ],
        "title": "UpdateEmailMessageStatusResponseDto"
      },
      "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"
      },
      "ForbiddenDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 403
          },
          "message": {
            "type": "string",
            "example": "You do not have permission to access this resource"
          },
          "error": {
            "type": "string",
            "example": "Forbidden"
          }
        },
        "title": "ForbiddenDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X PUT 'https://services.leadconnectorhq.com/conversations/messages/email/<emailMessageId>/status' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "events": {
    "delivered": 1,
    "opened": 1
  },
  "recipients": [
    {
      "emailId": "john@example.com",
      "status": "delivered"
    }
  ],
  "status": "delivered"
}'
```

**Node.js**

```javascript
const options = {
  method: 'PUT',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "events": {
        "delivered": 1,
        "opened": 1
      },
      "recipients": [
        {
          "emailId": "john@example.com",
          "status": "delivered"
        }
      ],
      "status": "delivered"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/conversations/messages/email/<emailMessageId>/status', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/conversations/messages/email/{emailMessageId}/status"

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

payload = {
    "events": {
        "delivered": 1,
        "opened": 1
    },
    "recipients": [
        {
            "emailId": "john@example.com",
            "status": "delivered"
        }
    ],
    "status": "delivered"
}

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

**PHP**

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

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/conversations/messages/email/<emailMessageId>/status',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "events": {
    "delivered": 1,
    "opened": 1
  },
  "recipients": [
    {
      "emailId": "john@example.com",
      "status": "delivered"
    }
  ],
  "status": "delivered"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .put("https://services.leadconnectorhq.com/conversations/messages/email/<emailMessageId>/status")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"events\":{\"delivered\":1,\"opened\":1},\"recipients\":[{\"emailId\":\"john@example.com\",\"status\":\"delivered\"}],\"status\":\"delivered\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/conversations/messages/email/<emailMessageId>/status"
  payload := strings.NewReader(`{
  "events": {
    "delivered": 1,
    "opened": 1
  },
  "recipients": [
    {
      "emailId": "john@example.com",
      "status": "delivered"
    }
  ],
  "status": "delivered"
}`)
  req, _ := http.NewRequest("PUT", 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/conversations/messages/email/<emailMessageId>/status")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "events": {
    "delivered": 1,
    "opened": 1
  },
  "recipients": [
    {
      "emailId": "john@example.com",
      "status": "delivered"
    }
  ],
  "status": "delivered"
}'

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

**PowerShell**

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

$body = '{
  "events": {
    "delivered": 1,
    "opened": 1
  },
  "recipients": [
    {
      "emailId": "john@example.com",
      "status": "delivered"
    }
  ],
  "status": "delivered"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/conversations/messages/email/<emailMessageId>/status' -Method 'PUT' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
