# Add Ticket API

## Create Ticket.

<mark style="color:green;">`POST`</mark> [https://\<sub domain>.kapturecrm.com/add-ticket-from-other-source.html/v.2.0](https://devapi.kapturecrm.com/add-ticket-from-other-source.html/v.2.0)

{% hint style="info" %}

```
NOTE: Please replace with your sub domain name in the API.
```

{% endhint %}

### Authentication:

To access this API endpoint, you need to include your API key in the request headers. For authentication, use the following header:

```
Basic <Your Token>
```

### Request Body

The request body should be a JSON object containing the details of the ticket to be added. Here are the  list of parameters.

<table><thead><tr><th>Name</th><th width="125">Mandatory</th><th width="111">Type</th><th>Description</th></tr></thead><tbody><tr><td>title<mark style="color:red;">*</mark></td><td>Yes</td><td>string</td><td>The title of the ticket</td></tr><tr><td>ticket_details</td><td>No</td><td>string</td><td>The description of the ticket</td></tr><tr><td>due_date</td><td>No</td><td>date</td><td>The closure date of the ticket</td></tr><tr><td>email_id</td><td>No</td><td>string</td><td>The Email Id of the customer to be tagged in the ticket</td></tr></tbody></table>

{% tabs %}
{% tab title="Body Request" %}

```json
[
    {
        "title": "",
        "ticket_details": "",
        "due_date": "",
        "email_id": "xyz@gmail.com"
    }
]
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Please map in the request body if there's any extra associate body according to your use case.**
{% endhint %}

### Response Body

The API responds with a JSON object containing the details of the added ticket. If successful, the response will include the ticket ID and other relevant information.

| Response                                            | Response Messages                                                                    |
| --------------------------------------------------- | ------------------------------------------------------------------------------------ |
| { ..., "status": "success"}                         | Ticket created successfully.                                                         |
| {"message": "Invalid Auth Key","status": "failed"}  | Authorization key is either not passed in header, or incorrect, or expired/disabled. |
| {"message": "title is missing", "status": "failed"} | title field is either missing or empty in request body.                              |

{% tabs %}
{% tab title="Response" %}

```json
{
    "ticket": {
        "id": 530348198,
        "type": "O",
        "email": "",
        "phone": "",
        "status": "P",
        "orderId": "",
        "queueKey": "",
        "ticketId": "713516551148",
        "folderId": 0,
        "detail": "",
        "isUnread": true,
        "isOutOfSLA": false,
        "priority": 0,
        "isCallBack": false,
        "creatorId": 0,
        "enquiryId": 0,
        "contactId": 0,
        "substatus": "US",
        "productId": 0,
        "erpOrderId": "",
        "referenceId": 0,
        "ticketEmail": "",
        "assignedToId": 0,
        "pendingTaskId": 0,
        "agencyBriefId": 0,
        "twitterUserId": "",
        "facebookUserId": "",
        "associativefile": "",
        "statusName": "Pending",
        "customerFeedback": 0,
        "playStoreReviewId": "",
        "lastConversationId": 0,
        "lastConversationType": "O",
        "lastConversationTime": 1713516551152,
        "date": "2024-04-19 14:19:11",
        "totalConversationCount": 0,
        "taskTitle": "TEST 1",
        "typeName": "Mobile App",
        "taskEnddate": "2024-04-19 14:19:11",
        "lastFollowUp": "2024-04-19 14:19:11",
        "nextFollowUp": "2024-04-19 14:19:11",
        "substatusName": "Unattended",
        "encryptedPhone": "",
        "encryptedEmail": "",
        "lastConversationTypeName": "Mobile App",
        "ticketURL": "/employee/view-task-detail.html?detail=5/530348198/713516551148",
        "ticketCreatorURL": "/employee/view-task-detail.html?detail=5/530348198/713516551148",
        "isEscalated": true,
        "folders": [
            "Inbox"
        ],
        "queueName": "",
        "creatorName": "",
        "folderColor": "red",
        "assignedToName": "",
        "assignedToPhone": "",
        "assignedToEmail": "",
        "mergeTicketId": "",
        "skuCode": "",
        "productName": ""
    },
    "Additional_details": {},
    "due_date": "2024-04-19 14:19:11",
    "title": "TEST 1",
    "customer_id": 0,
    "ticket_id": "713516551148",
    "Ticket Id": "713516551148",
    "ticket_url": "https://devapi.kapturecrm.com/employee/view-task-detail.html?detail=5/530348198/713516551148",
    "status": "success"
}
```

{% endtab %}
{% endtabs %}

### Error Codes

| Error Codes | Description                                      |
| ----------- | ------------------------------------------------ |
| 400         | Bad Request - Invalid parameters or missing data |
| 401         | Unauthorized - Invalid or missing API key        |
| 403         | Forbidden - Insufficient permissions             |
| 404         | Not Found - Resource or endpoint not found       |
| 500         | Internal Server Error - Server-side issue        |

### Example of a working curl

{% tabs %}
{% tab title="cURL" %}

```json
curl --location 'https://devapi.kapturecrm.com/add-ticket-from-other-source.html/v.2.0' \
--header 'Authorization: Basic <Your Token>' \
--header 'Content-Type: application/json' \
--header 'Cookie: JSESSIONID=; _KAPTURECRM_SESSION=' \
--data '[
    {
        "title": "TEST 1",
        "ticket_details": "",
        "due_date": "",
        "email_id": ""
    }
]'
```

{% endtab %}

{% tab title="Python" %}

```python
import http.client
import json

conn = http.client.HTTPSConnection("devapi.kapturecrm.com")
payload = json.dumps([
  {
    "title": "TEST 1",
    "ticket_details": "",
    "due_date": "",
    "email_id": ""
  }
])
headers = {
  'Authorization': 'Basic <Your Token>',
  'Content-Type': 'application/json',
  'Cookie': 'JSESSIONID=; _KAPTURECRM_SESSION='
}
conn.request("POST", "/add-ticket-from-other-source.html/v.2.0", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="Node.js" %}

```
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://devapi.kapturecrm.com/add-ticket-from-other-source.html/v.2.0',
  'headers': {
    'Authorization': 'Basic <Your Token>',
    'Content-Type': 'application/json',
    'Cookie': 'JSESSIONID=; _KAPTURECRM_SESSION='
  },
  body: JSON.stringify([
    {
      "title": "TEST 1",
      "ticket_details": "",
      "due_date": "",
      "email_id": ""
    }
  ])

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

{% endtab %}
{% endtabs %}
