---
schema_version: "1"
id: 5fc5dbfee8553c2875a292af241457112e1e4f2e8540042f5d3bca18880dafbf
title: End or Inactivate a Messaging Session
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/interaction-service-api/references/api-messagingsession.md
canonical_url: https://developer.salesforce.com/docs/service/interaction-service-api/references/interaction-service-reference/api-messagingsession.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 1138cf2a810731f61e0d843a2ee4a98053569b68fa8cc7c193abd7b44f417981
products:
  - Interaction Service API
  - Service Cloud Developer Content
---
# End or Inactivate a Messaging Session

Ends or suspends a messaging session.

Use this API to end or suspend a messaging session while noting whether the action came from a Messaging End User or your partner system. The End or Inactivate a Messaging Session API doesn’t rely on an End Chat UI component interaction in Salesforce or the session inactivation timeout set by the Salesforce admin in the Messaging Channel. The partner system uses this API to notify Salesforce if a chat has ended or become inactive. The rep can then receive a status notification, start After Conversation Work, if enabled, and move on to the next session or work item.

This API applies to the following products:

- Bring Your Own Channel for Contact Center as a Service
- Bring Your Own Channel for Messaging

This API is available in version 65.0 and later.

## URI

`v1/messagingSession`

## HTTP Method

POST

## Headers

### Authorization (User-Level Authentication)

**Format:** `Bearer <Salesforce Access Token>`  
String. Standard header. Used to authenticate the user, where `<Salesforce Access Token>` is the Salesforce access token used as the bearer token to make requests to the Interaction Service APIs. Required.

### Content-Type

**Format:** `application/json`  
String. Standard header. Format of the request payload. Required for any request that includes a body.

### OrgId

**Format:** `<Salesforce Org ID>`  
String. Custom header. The Salesforce org. `<Salesforce Org ID>` is the 15-character Org ID of the Salesforce org. Required.

### RequestId

**Format:** `<UUID>`  
String. Custom header. Universally Unique Identifier (`<UUID>`) that references and tracks this request. Required.

### AuthorizationContext

**Format:** `<AuthorizationContext>`  
String. Custom header. Additional information for the request authorization used to authenticate and validate requests against the connected app scopes.

- For Bring Your Own Channel for CCaaS, set `<AuthorizationContext>` to the developer name of the ConversationChannelDefinition record. For example, Partner1_ChannelDefinition1. Required.
- For Bring Your Own Channel for Messaging, set `<AuthorizationContext>` to the developer name of the ConversationChannelDefinition record. For example, Partner1_ChannelDefinition1. Required.


### Sample Header

```
-H $'Authorization: Bearer 00DSG000009SWby\!...LN8XxeRIxGe' \
-H "content-type: application/json" \
-H "OrgId: 00DSG000009SWby" \
-H "AuthorizationContext: Partner1_ChannelDefinition1" \
-H "RequestId: a1b23c45-c06a-4784-c96c-cb95d3321bda" \
```

## Parameters

| Property Name            | Type   | Description                                                                                                                                     | Required |
| :----------------------- | :----- | :---------------------------------------------------------------------------------------------------------------------------------------------- | :------- |
| channelAddressIdentifier | string | The globally unique ID (GUID) for the conversation channel (`MessagingChannel.ChannelAddressIdentifier`) field. Maximum size is 240 characters. | Yes      |
| endUserClientId          | string | The end user client identifier. This value comes from the partner system and can be up to 240 characters long.                                  | Yes      |
| conversationIdentifier   | string | The unique ID for the conversation channel.                                                                                                     | Yes      |
| sessionId                | string | The messaging session ID.                                                                                                                       | No       |
| operation                | string | Specifies the action to take on the messaging session. Valid values are: <br/>- **End** <br/>- **Inactivate**                                   | Yes      |
| operationBy              | string | Specifies where the operation originated from. Valid values are: <br/>- **EndUser** <br/>- **System**                                           | No       |

## Examples

### Request

```json
{
  "channelAddressIdentifier": "<channelAddressIdentifier>",
  "endUserClientId": "<EndUser>",
  "conversationIdentifier": "<ConversationIdentifier>",
  "operation": "End",
  "operationBy": "<EndUser / System>"
}
```

```json
{
 "channelAddressIdentifier": "<channelAddressIdentifier>",
 "endUserClientId": "<EndUser>",
 "sessionId" : "<messagingSessionId>",
 "conversationIdentifier": "<ConversationIdentifier>",
 "operation": "Inactivate",
 "operationBy": "<EndUser / System>"
}
```

### Response

```json
{
   "success": true
}
```

```json
{
   "success": false,
   "ErrorReason": ACTIVE_CONVERSATION_NOT_FOUND
}
```

If `success` is `false`, `ErrorReason` lists the reason why the Messaging session wasn’t successfully ended or inactivated. Valid values are:

- `ACTIVE_CONVERSATION_NOT_FOUND`
- `END_SESSION_FAILED`
- `INTERNAL_ERROR`
- `PERMISSION_DENIED`
- `CHANNEL_ADDRESS_NOT_FOUND`
- `SESSION_NOT_FOUND`
- `END_USER_NOT_FOUND`
- `ORG_NOT_FOUND`
- `CONVERSATION_PRECONDITION_FAILED`
- `CONVERSATION_PROCESSING_ABORTED`
- `CHANNEL_ADDRESS_IS_INACTIVE`
- `CUSTOMER_ERROR`

## See Also

- _GitHub_: [Interaction Service APIs](https://github.com/salesforce-misc/interaction-service-apis)
