# Add an external outbound call

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

Post the necessary fields for the API to add a new outbound call.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `conversations/message.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/messages/outbound": {
      "post": {
        "summary": "Add an external outbound call",
        "operationId": "addAnExternalOutboundCall",
        "description": "Post the necessary fields for the API to add a new outbound call.",
        "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/ProcessOutboundMessageBodyDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Created the message",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProcessMessageResponseDto"
                }
              }
            }
          },
          "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/message.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": {
      "ProcessOutboundMessageBodyDto": {
        "type": "object",
        "description": "One of conversationId or contactId must be provided. When conversationId is omitted, the conversation is resolved or created from contactId.",
        "properties": {
          "type": {
            "type": "string",
            "description": "Message Type",
            "example": "Call",
            "enum": [
              "Call"
            ]
          },
          "attachments": {
            "description": "Array of attachments",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "conversationId": {
            "type": "string",
            "description": "Conversation Id. Provide either conversationId or contactId.",
            "example": "ve9EPM428h8vShlRW1KT"
          },
          "contactId": {
            "type": "string",
            "description": "Contact Id. When provided without conversationId, the conversation is resolved or created from this contact.",
            "example": "ve9EPM428h8vShlRW1KT"
          },
          "conversationProviderId": {
            "type": "string",
            "description": "Conversation Provider Id",
            "example": "61d6d1f9cdac7612faf80753"
          },
          "altId": {
            "type": "string",
            "description": "external mail provider's message id",
            "example": "61d6d1f9cdac7612faf80753"
          },
          "date": {
            "format": "date-time",
            "type": "string",
            "description": "Date of the outbound message"
          },
          "call": {
            "description": "Phone call dialer and receiver information",
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "to": {
                    "type": "string",
                    "description": "Phone number of the receiver",
                    "example": "+15037081210"
                  },
                  "from": {
                    "type": "string",
                    "description": "Phone number of the dialer",
                    "example": "+15037081210"
                  },
                  "status": {
                    "type": "string",
                    "description": "Call status",
                    "example": "completed",
                    "enum": [
                      "pending",
                      "completed",
                      "answered",
                      "busy",
                      "no-answer",
                      "failed",
                      "canceled",
                      "voicemail"
                    ]
                  }
                },
                "title": "CallDataDTO"
              }
            ]
          }
        },
        "required": [
          "type",
          "conversationProviderId"
        ],
        "title": "ProcessOutboundMessageBodyDto"
      },
      "ProcessMessageResponseDto": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "conversationId": {
            "type": "string",
            "description": "Conversation ID.",
            "example": "ABC12h2F6uBrIkfXYazb"
          },
          "messageId": {
            "type": "string",
            "description": "This is the main Message ID",
            "example": "t22c6DQcTDf3MjRhwf77"
          },
          "message": {
            "type": "string"
          },
          "contactId": {
            "type": "string"
          },
          "dateAdded": {
            "format": "date-time",
            "type": "string"
          },
          "emailMessageId": {
            "type": "string"
          }
        },
        "required": [
          "success",
          "conversationId",
          "messageId",
          "message"
        ],
        "title": "ProcessMessageResponseDto"
      },
      "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/messages/outbound' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "type": "Call",
  "attachments": [],
  "conversationId": "ve9EPM428h8vShlRW1KT",
  "contactId": "ve9EPM428h8vShlRW1KT",
  "conversationProviderId": "61d6d1f9cdac7612faf80753",
  "altId": "61d6d1f9cdac7612faf80753",
  "call": {
    "to": "+15037081210",
    "from": "+15037081210",
    "status": "completed"
  }
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "type": "Call",
      "attachments": [],
      "conversationId": "ve9EPM428h8vShlRW1KT",
      "contactId": "ve9EPM428h8vShlRW1KT",
      "conversationProviderId": "61d6d1f9cdac7612faf80753",
      "altId": "61d6d1f9cdac7612faf80753",
      "call": {
        "to": "+15037081210",
        "from": "+15037081210",
        "status": "completed"
      }
  })
};

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

**Python**

```python
import requests

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

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

payload = {
    "type": "Call",
    "attachments": [],
    "conversationId": "ve9EPM428h8vShlRW1KT",
    "contactId": "ve9EPM428h8vShlRW1KT",
    "conversationProviderId": "61d6d1f9cdac7612faf80753",
    "altId": "61d6d1f9cdac7612faf80753",
    "call": {
        "to": "+15037081210",
        "from": "+15037081210",
        "status": "completed"
    }
}

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/messages/outbound',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "type": "Call",
  "attachments": [],
  "conversationId": "ve9EPM428h8vShlRW1KT",
  "contactId": "ve9EPM428h8vShlRW1KT",
  "conversationProviderId": "61d6d1f9cdac7612faf80753",
  "altId": "61d6d1f9cdac7612faf80753",
  "call": {
    "to": "+15037081210",
    "from": "+15037081210",
    "status": "completed"
  }
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/conversations/messages/outbound")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"type\":\"Call\",\"attachments\":[],\"conversationId\":\"ve9EPM428h8vShlRW1KT\",\"contactId\":\"ve9EPM428h8vShlRW1KT\",\"conversationProviderId\":\"61d6d1f9cdac7612faf80753\",\"altId\":\"61d6d1f9cdac7612faf80753\",\"call\":{\"to\":\"+15037081210\",\"from\":\"+15037081210\",\"status\":\"completed\"}}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/conversations/messages/outbound"
  payload := strings.NewReader(`{
  "type": "Call",
  "attachments": [],
  "conversationId": "ve9EPM428h8vShlRW1KT",
  "contactId": "ve9EPM428h8vShlRW1KT",
  "conversationProviderId": "61d6d1f9cdac7612faf80753",
  "altId": "61d6d1f9cdac7612faf80753",
  "call": {
    "to": "+15037081210",
    "from": "+15037081210",
    "status": "completed"
  }
}`)
  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/messages/outbound")

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 = '{
  "type": "Call",
  "attachments": [],
  "conversationId": "ve9EPM428h8vShlRW1KT",
  "contactId": "ve9EPM428h8vShlRW1KT",
  "conversationProviderId": "61d6d1f9cdac7612faf80753",
  "altId": "61d6d1f9cdac7612faf80753",
  "call": {
    "to": "+15037081210",
    "from": "+15037081210",
    "status": "completed"
  }
}'

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

**PowerShell**

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

$body = '{
  "type": "Call",
  "attachments": [],
  "conversationId": "ve9EPM428h8vShlRW1KT",
  "contactId": "ve9EPM428h8vShlRW1KT",
  "conversationProviderId": "61d6d1f9cdac7612faf80753",
  "altId": "61d6d1f9cdac7612faf80753",
  "call": {
    "to": "+15037081210",
    "from": "+15037081210",
    "status": "completed"
  }
}'

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