# Create Conversation

POST https://services.leadconnectorhq.com/conversations/

Creates a new conversation with the data provided

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/conversations/": {
      "post": {
        "summary": "Create Conversation",
        "operationId": "createConversation",
        "description": "Creates a new conversation with the data provided",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateConversationDto"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateConversationSuccessResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "conversations.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": {
      "CreateConversationDto": {
        "type": "object",
        "properties": {
          "locationId": {
            "type": "string",
            "description": "Location ID as string",
            "example": "tDtDnQdgm2LXpyiqYvZ6"
          },
          "contactId": {
            "type": "string",
            "description": "Contact ID as string",
            "example": "tDtDnQdgm2LXpyiqYvZ6"
          }
        },
        "required": [
          "locationId",
          "contactId"
        ],
        "title": "CreateConversationDto"
      },
      "CreateConversationSuccessResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "Indicates whether the API request was successful.",
            "example": true
          },
          "conversation": {
            "description": "Conversation data of the provided conversation ID.",
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Unique identifier for the conversation",
                    "example": "tDtDnQdgm2LXpyiqYvZ6"
                  },
                  "dateUpdated": {
                    "type": "string",
                    "description": "Date when the conversation was last updated",
                    "example": "2023-10-01T12:00:00Z"
                  },
                  "dateAdded": {
                    "type": "string",
                    "description": "Date when the conversation was created",
                    "example": "2023-10-01T12:00:00Z"
                  },
                  "deleted": {
                    "type": "boolean",
                    "description": "Flag indicating if this conversation has been deleted",
                    "example": false
                  },
                  "contactId": {
                    "type": "string",
                    "description": "Unique identifier of the contact associated with this conversation",
                    "example": "ve9EPM428kjkvShlRW1KT"
                  },
                  "locationId": {
                    "type": "string",
                    "description": "Unique identifier of the business location where this conversation takes place",
                    "example": "ve9EPM428kjkvShlRW1KT"
                  },
                  "lastMessageDate": {
                    "type": "string",
                    "description": "Date of the last message in the conversation",
                    "example": "2023-10-01T12:00:00Z"
                  },
                  "assignedTo": {
                    "type": "string",
                    "description": "Unique identifier of the team member assigned to this conversation",
                    "example": "ve9EPM428kjkvShlRW1KT"
                  }
                },
                "required": [
                  "id",
                  "dateUpdated",
                  "dateAdded",
                  "deleted",
                  "contactId",
                  "locationId",
                  "lastMessageDate"
                ],
                "title": "ConversationCreateResponseDto"
              }
            ]
          }
        },
        "required": [
          "success",
          "conversation"
        ],
        "title": "CreateConversationSuccessResponse"
      },
      "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"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/conversations/' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "locationId": "tDtDnQdgm2LXpyiqYvZ6",
  "contactId": "tDtDnQdgm2LXpyiqYvZ6"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "locationId": "tDtDnQdgm2LXpyiqYvZ6",
      "contactId": "tDtDnQdgm2LXpyiqYvZ6"
  })
};

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

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/conversations/"

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

payload = {
    "locationId": "tDtDnQdgm2LXpyiqYvZ6",
    "contactId": "tDtDnQdgm2LXpyiqYvZ6"
}

response = requests.post(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/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "locationId": "tDtDnQdgm2LXpyiqYvZ6",
  "contactId": "tDtDnQdgm2LXpyiqYvZ6"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/conversations/")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"locationId\":\"tDtDnQdgm2LXpyiqYvZ6\",\"contactId\":\"tDtDnQdgm2LXpyiqYvZ6\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/conversations/"
  payload := strings.NewReader(`{
  "locationId": "tDtDnQdgm2LXpyiqYvZ6",
  "contactId": "tDtDnQdgm2LXpyiqYvZ6"
}`)
  req, _ := http.NewRequest("POST", 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/")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "locationId": "tDtDnQdgm2LXpyiqYvZ6",
  "contactId": "tDtDnQdgm2LXpyiqYvZ6"
}'

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

**PowerShell**

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

$body = '{
  "locationId": "tDtDnQdgm2LXpyiqYvZ6",
  "contactId": "tDtDnQdgm2LXpyiqYvZ6"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/conversations/' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
