# Webhook Response Documentation

Webhooks send **POST requests** to your configured endpoint with JSON payloads based on the notification type.

---

## Notification Types

### 1. Delivery Status Update

Notifies about changes in the delivery status of a consignment.

**Example Payload**

```json
{
    "notification_type": "delivery_status",
    "consignment_id": 12345,
    "invoice": "INV-67890",
    "cod_amount": 1500.00,
    "status": "Delivered",
    "delivery_charge": 100.00,
    "tracking_message": "Your package has been delivered successfully.",
    "updated_at": "2025-03-02 12:45:30"
}
```

**Field Details**

| Field Name | Type | Description |
|---|---|---|
| `notification_type` | string | Fixed value: `"delivery_status"` |
| `consignment_id` | integer | Unique ID of the consignment |
| `invoice` | string | Invoice number associated with the consignment |
| `cod_amount` | float | Cash on delivery (COD) amount |
| `status` | string | Current delivery status — see values below |
| `delivery_charge` | float | Delivery charge applied |
| `tracking_message` | string | Status update message |
| `updated_at` | string (datetime) | Timestamp of the last update (`YYYY-MM-DD HH:MM:SS`) |

**Possible `status` Values**

| Value | Description |
|---|---|
| `pending` | Consignment is awaiting processing |
| `delivered` | Successfully delivered to recipient |
| `partial_delivered` | Only part of the order was delivered |
| `cancelled` | Delivery was cancelled |
| `unknown` | Status could not be determined |

---

### 2. Tracking Update

Sends tracking updates for a consignment as it moves through the delivery pipeline.

**Example Payload**

```json
{
    "notification_type": "tracking_update",
    "consignment_id": 12345,
    "invoice": "INV-67890",
    "tracking_message": "Package arrived at the sorting center.",
    "updated_at": "2025-03-02 13:15:00"
}
```

**Field Details**

| Field Name | Type | Description |
|---|---|---|
| `notification_type` | string | Fixed value: `"tracking_update"` |
| `consignment_id` | integer | Unique ID of the consignment |
| `invoice` | string | Invoice number associated with the consignment |
| `tracking_message` | string | Update message related to the package tracking |
| `updated_at` | string (datetime) | Timestamp of the last update (`YYYY-MM-DD HH:MM:SS`) |

---

## Webhook Headers

| Header Name | Value |
|---|---|
| `Content-Type` | `application/json` |
| `Authorization` | `Bearer {your_api_key}` *(if authentication is required)* |

---

## Response Handling

Your server must respond with **HTTP 200 OK** if the webhook is processed successfully.

### Success Response

```json
{
    "status": "success",
    "message": "Webhook received successfully."
}
```

### Error Response

```json
{
    "status": "error",
    "message": "Invalid consignment ID."
}
```

> **Note:** If your server does not return a `200 OK`, the webhook may be retried depending on the platform's retry policy. Ensure your endpoint handles duplicate events gracefully (idempotency).
