# Agency Template Reporting

API URI

```bash
https://api.versal.one/<uuid>
```

```
POST /agency/template
```

#### **Description**

This API enables agencies to submit and track template information. The client must provide a valid `uuid` as a query parameter and include the template details in the request body. If the `wam_id` is not provided, the template will automatically be reported as failed.

---

#### **Request Headers**

<table id="bkmrk-header-type-descript"><thead><tr><th>Header</th><th>Type</th><th>Description</th><th>Constraints</th></tr></thead><tbody><tr><td>`Authorization`</td><td>String</td><td>Bearer token for authentication and authorization.</td><td>Required. Must be in the format `Bearer [token]`.</td></tr></tbody></table>

---

#### **Query Parameters**

<table id="bkmrk-field-type-descripti"><thead><tr><th>Parameter</th><th>Type</th><th>Description</th><th>Constraints</th></tr></thead><tbody><tr><td>`uuid`</td><td>String</td><td>Unique identifier for the agency.</td><td>Required. Must be a valid UUID format.</td></tr></tbody></table>

---

#### **Request Body Parameters**

<table id="bkmrk-field-type-descripti-1" style="width: 100%;"><thead><tr><th style="width: 15.1335%;">Field</th><th style="width: 16.1943%;">Type</th><th style="width: 58.6388%;">Description</th><th style="width: 10.0095%;">Constraints</th></tr></thead><tbody><tr><td style="width: 15.1335%;">`template_name`</td><td style="width: 16.1943%;">String</td><td style="width: 58.6388%;">Name of the template to be tracked.</td><td style="width: 10.0095%;">Required.</td></tr><tr><td style="width: 15.1335%;">`phone_number`</td><td style="width: 16.1943%;">String</td><td style="width: 58.6388%;">Phone number associated with the template.</td><td style="width: 10.0095%;">Required.</td></tr><tr><td style="width: 15.1335%;">`wam_id`</td><td style="width: 16.1943%;">String</td><td style="width: 58.6388%;">Unique identifier for the WhatsApp template. If not provided, the template will be reported as failed.</td><td style="width: 10.0095%;">Optional.</td></tr></tbody></table>

---

#### **Response Codes**

<table id="bkmrk-status-code-descript"><thead><tr><th>Status Code</th><th>Description</th></tr></thead><tbody><tr><td>`403`</td><td>Forbidden. Invalid HMAC signature.</td></tr><tr><td>`400`</td><td>Bad request. Missing `uuid` parameter or required fields in the request body.</td></tr><tr><td>`404`</td><td>No company found with the provided `uuid`.</td></tr><tr><td>`500`</td><td>Failed to save data to MongoDB or process the template data.</td></tr></tbody></table>

---

#### **Example Requests**

**Request (Track Template):**

```json
 POST 53d1bcd3-aaf0-45e1-9298-5395b6a27b61/agency/template
 Authorization: Bearer 5395b6a27b61
 {
  "template_name": "savetem",
  "phone_number": "6363978748",
  "wam_id": "wamkskdfj-lkskfdkskf"
 }
```

**Response (Success - 200):**

```json
 { "success": true, "message": "Template data processed successfully" } 
``` 

**Response (Missing UUID - 400):**

```json
 { "success": false, "message": "Bad Request: Missing uuid parameter" } 
``` 

**Response (Missing Fields - 400):**

```json
 { "success": false, "message": "Template name and phone number are required" } 
``` 

**Response (Invalid HMAC - 403):**

```json
 { "success": false, "message": "Forbidden: Invalid HMAC signature" } 
``` 

**Response (No Company Found - 404):**

```json
 { "success": false, "message": "No company found with the provided uuid" } 
``` 

**Response (MongoDB Failure - 500):**

```json
 { "success": false, "message": "Failed to save data in MongoDB. Please try again later." } 
``` 

**Response (Unexpected Error - 500):**

```json
 { "success": false, "message": "An unexpected error occurred while processing the template data. Please try again later." } 
``` 

---

#### **Notes**

- **Authentication**: The authorization token must be valid and properly formatted. Invalid or missing tokens will result in a 403 error.
- **Field Validation**: The `template_name` and `phone_number` fields are required for this request.
- **WAM ID Handling**: If `wam_id` is not provided, the template will automatically be reported as failed.
- **Error Handling**: For 500 errors, consult server logs for more details.