End a Call
This endpoint terminates an active call and performs post-call processing including analysis and webhook notifications.Endpoint Details
- URL:
/calls/end
- Method:
POST
- Authentication: Required (
API KEY
orJWT Token
) - Source:
src/api/public_apis_v1/call/end_call/end_call_controller.rs
Request Headers
Header | Value | Description |
---|---|---|
Authorization | Bearer <api_key> | Your API KEY or JWT Token |
Content-Type | application/json | Request content type |
Request Body
Field | Type | Required | Description | Example |
---|---|---|---|---|
call_id | UUID | Yes | The unique identifier of the call to end | 550e8400-e29b-41d4-a716-446655440000 |
disconnect_reason | String | No | Custom reason for ending the call. Defaults to “Ended Via API call” | Customer requested to end call |
Example Request
cURL
JavaScript
Python
Node.js with Axios
Response
Success Response
Status Code:200 OK
Error Response
Status Code:200 OK
(with empty body)
When an error occurs, the endpoint may return an empty response body.
Post-Call Processing
When a call is ended through this endpoint, the following actions are automatically performed:1. Provider Termination
- The call is terminated with the telephony provider (e.g., Twilio) using the provider’s API
- Uses BYOT (Bring Your Own Twilio) credentials if configured
2. Resource Cleanup
- Echo room associated with the call is deleted
- Any temporary resources are cleaned up
3. Call Record Update
- The call’s
ended_at
timestamp is set to the current time - The
disconnect_reason
is updated with the provided reason or default - Call status is updated to reflect termination
4. Call Analysis
- Automatic call analysis is triggered after termination
- Sentiment analysis and other metrics are calculated
- Analysis results are stored in the call record
5. Webhook Notifications
- If configured, webhook notifications are sent with the call analysis results
- Webhooks include complete call data and analysis outcomes
Use Cases
1. Manual Call Termination
End an ongoing call when specific conditions are met or upon user request.2. Emergency Stop
Immediately terminate a call in case of issues or emergencies.3. Scheduled Termination
End calls that have exceeded time limits or met completion criteria.4. Quality Control
Terminate test calls or problematic calls detected by monitoring systems.5. Integration Workflows
End calls as part of automated workflows or third-party system integrations.Important Notes
- The endpoint requires the call to exist and be associated with a valid phone number
- The call must be active or in a state that allows termination
- Post-call analysis is performed asynchronously and may not be immediately available
- Webhook notifications are sent on a best-effort basis
- The
disconnect_reason
field is useful for tracking why calls were ended - If no
disconnect_reason
is provided, it defaults to “Ended Via API call” - The endpoint will attempt to end the call even if some cleanup operations fail
Error Handling
The endpoint handles various error scenarios:- Invalid call ID: Returns empty response
- Call not found: Returns empty response
- Provider termination failure: Continues with local cleanup
- Echo room deletion failure: Continues with other operations
- Analysis failure: Logged but doesn’t prevent call termination
Related Endpoints
GET /calls/{id}
- Get call details after endingGET /calls/query
- Query calls with specific end reasonsPOST /calls/make-call
- Initiate a new call
Authorizations
Bearer authentication header of the form Bearer <token>
, where <token>
is your auth token.
Body
application/json
Details to end the call