Newer Version Available
ReconnectSession
This request should only be made if you receive a 503 response status code, indicating that the affinity token has changed for your Live Agent session. When you receive a 503 response status code, you must cancel any existing inbound or outbound requests.
The data in outbound requests will be temporarily stored and resent once the session is reestablished. Upon receiving the response for the ReconnectSession request, you can start polling for messages.
The first response will be a ChasitorSessionData message containing the data from the previous session that will be restored once the session is reestablished. After receiving that message, you can proceed to send the existing messages that were canceled upon receiving the 503 response status code.
Syntax
- URI
- https://hostname/chat/rest/System/ReconnectSession
- Available since release
- This resource is available in API versions 37.0 and later.
- Formats
- JSON
- HTTP methods
- GET
- Request headers
- X-LIVEAGENT-API-VERSION
- X-LIVEAGENT-AFFINITY
- X-LIVEAGENT-SESSION-KEY
- Request parameters
-
Name Type Description ReconnectSession.offset Number The event offset from the most recent Messages request that your client received. - Query parameters
- None
- Request body
- None
- Response body
- ReconnectSession
Example
Your REST client can get a 503 Invalid Affinity Token response, for example, to a long poll request (/chat/rest/System/Messages).
No matter which kind of request gets the 503 response, you must send a /chat/rest/System/ReconnectSession request to finish the handover process.
1Method: GET
2 URL:
3 https://MyDomainNamemy.salesforcescrt.com/chat/rest/System/
4 ReconnectSession?ReconnectSession.offset=54647226
5 Headers:
6 X-LIVEAGENT-AFFINITY:
7 null [the literal string “null”]
8 X-LIVEAGENT-API-VERSION:
9 42
10 X-LIVEAGENT-SESSION-KEY:
11 4eb90106-3410-4dd0-8f04-c4facf90a929!1519169434766!IbjEwmJkIIyqalZS3YBU8WO3nSM=The ReconnectSession.offset query parameter has to be set to the “offset” parameter of the most recent long poll response that actually contained messages. Empty long poll responses don’t come with an “offset”.
The response to this ReconnectSession request looks like this:
1{
2 "messages": [
3 {
4 "type": "ReconnectSession",
5 "message": {
6 "resetSequence": true, [This may be undefined]
7 "affinityToken": "efae1fa0"
8 }
9 }
10 ]
11}The resetSequence is always set to true. Therefore, reset the sequence number of the next request and store the value in affinityToken to use in the X-LIVEAGENT-AFFINITY header for all future requests. Once another handover process occurs the resetSequence is updated again.
Testing
To test that your client handles this process correctly, check that your client sends a ReconnectSession request when it receives a 503 response from the server. You can use a proxy tool of your choice to mimic the 503 response or you can wait until the Salesforce server sends one. When the proxy tool sends a 503 response, you can test that your client sends the ReconnectSession request and reconnects the chat session to a new server, as expected. To get an actual 503 response from the server, you can leave a session connected and wait until the server is restarted during scheduled maintenance. Then see if the chat session reconnects to a new server. However, the maintenance schedule is not announced in advance.