# Agency Campaign Creation

API URI

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

```
POST /agency/createCampaign
``` 

#### **Description**

This API allows agencies to create a campaign by specifying a name, schedule type, and other campaign details. The client must provide a valid `uuid` as a query parameter. Only accepted variables will be processed, and all user-defined variables must match the expected format.

---

#### **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"><thead><tr><th>Field</th><th>Type</th><th>Description</th><th>Constraints</th></tr></thead><tbody><tr><td>`name`</td><td>String</td><td>Campaign name.</td><td>Required. Must be unique.</td></tr><tr><td>`template_payload`</td><td>Object</td><td>Template details for the campaign.</td><td>Required. Must include user-defined variables matching `body_variable` and `header_variable`.</td></tr><tr><td>`schedule_type`</td><td>String</td><td>Type of schedule for the campaign.</td><td>Required. Allowed values: `"once"`, `"recurring"`.</td></tr><tr><td>`days`</td><td>Object</td><td>Days and times for a recurring schedule.</td><td>Required for `"recurring"` schedules. Must include days (e.g., `"monday"`) with an array of times.</td></tr><tr><td>`schedule`</td><td>String</td><td>Date and time for the campaign.</td><td>Required. Must follow a valid datetime format.</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>`201`</td><td>Campaign successfully created.</td></tr><tr><td>`400`</td><td>Bad request. Missing required fields, invalid `schedule_type`, or user-defined variables mismatch.</td></tr><tr><td>`403`</td><td>Forbidden. Invalid HMAC signature.</td></tr><tr><td>`404`</td><td>No company found with the provided `uuid`.</td></tr><tr><td>`409`</td><td>Conflict. Campaign name already exists.</td></tr><tr><td>`500`</td><td>Internal server error while saving the campaign.</td></tr></tbody></table>

---

#### **Example Requests**

**Request (Carousel Template):**

```json
 POST /53d1bcd3-aaf0-45e1-9298-5395b6a27b61/agency/createCampaign
 Authorization: Bearer 5395b6a27b61
 {
  "name": "temp3",
  "template_payload": {
    "cards": [
      {
        "card_image_url": "https://example.com/image1.jpg",
        "card_body_variables": []
      },
      {
        "card_image_url": "https://example.com/image2.jpg",
        "card_body_variables": []
      }
    ],
    "image_url": "",
    "group_name": "test_group",
    "body_variable": [],
    "template_name": "carousel_milk",
    "header_variable": []
  },
  "schedule_type": "recurring",
  "days": {
    "monday": [
      "10:00"
    ],
    "wednesday": [
      "10:00"
    ]
  },
  "schedule": "2025-01-15 14:50"
}
```

**Request (Header and Body Variables):**

```json
 POST /53d1bcd3-aaf0-45e1-9298-5395b6a27b61/agency/createCampaign
 Authorization: Bearer 5395b6a27b61
 {
  "name": "temp3",
  "template_payload": {
    "image_url": "",
    "group_name": "Team Testing",
    "body_variable": [
      "world"
    ],
    "template_name": "test_template_1",
    "header_variable": [
      "hello"
    ]
  },
  "schedule_type": "once",
  "schedule": "2025-01-15 14:50"
}
```

**Response (Created - 201):**

```json
 { "success": true, "message": "Campaign successfully created" } 
``` 

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

```json
 { "success": false, "message": "Name and Template payload are required for the campaign creation" } 
``` 

**Response (Invalid Schedule Type - 400):**

```json
 { "success": false, "message": "Schedule type should include only 'once' and 'recurring'." } 
``` 

**Response (Days Required for Recurring - 400):**

```json
 { "success": false, "message": "Days and Times are required for a recurring schedule." } 
``` 

**Response (Conflict - 409):**

```json
 { "success": false, "message": "Name already exists" } 
``` 

**Response (Internal Server Error - 500):**

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

---

#### **Notes**

- **Authentication**: A valid authorization token is required for all requests.
- **Validation**: All user-defined variables must exactly match the template's `body_variable` and `header_variable`.
- **Recurring Schedules**: `days` and `times` must be included for `recurring` schedules; otherwise, the request will fail.
- **Conflict Handling**: Campaign names must be unique.