function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Denys PeresDenys Peres 

SwitchServer response on Live Agent Rest API

We need ways to implement and test the code to handle the SwitchServer response in the Live Agent Rest API. The main questions we have are:
  • Which requests can throw this error? ChasitorInit is one, I suppose, but are there any others?
  • What is the error code returned along with it?
  • Is there any test endpoint we can use to simulate the response? I already tried to switch sandbox and production org ids and endpoints, but only got "503 - Service Unavailable".
  • How the mobile SDK handles it? I searched the github repo and found a reference in Feb 2017 release, but there was nothing about how it was handled.
Best Answer chosen by Denys Peres
Denys PeresDenys Peres
I was able to solve this question with help from support, and this is what I can share on the subject:
  • The response is thrown from Visitor/Availability request only. Seems obvious once you know the answer.
  • There is no error code.
  • In order to test, you will need support to point an alternative endpoint for you, one that has passed the migration process before. You won't be able to get this response swapping endpoints and org ids in your instance.
  • It seems that mobile SDK really solves this, so you only need to worry if you are using an hybrid SDK or custom code.
Here are samples of requests and responses:

OK REQUEST:
GET /chat/rest/Visitor/Availability?org_id=000000000000000&deployment_id=000000000000000&Availability.ids=000000000000000 HTTP/1.1
Host: [NEW_ENDPOINT]
X-LIVEAGENT-API-VERSION: 39
X-LIVEAGENT-AFFINITY: null
Content-Type: application/json

OK RESPONSE:
{"messages":[{"type":"Availability", "message":{"results":[{"id":"000000000000000"}]}}]}

...

SWITCH SERVER REQUEST:
GET /chat/rest/Visitor/Availability?org_id=000000000000000&deployment_id=000000000000000&Availability.ids=000000000000000 HTTP/1.1
Host: [OLD_INSTANCE_ENDPOINT]
X-LIVEAGENT-API-VERSION: 39
X-LIVEAGENT-AFFINITY: null
Content-Type: application/json

SWITCH SERVER RESPONSE:
{"messages":[{"type":"SwitchServer", "message":{"newUrl":"[NEW_ENDPOINT]"}}]}

All Answers

Denys PeresDenys Peres
I was able to solve this question with help from support, and this is what I can share on the subject:
  • The response is thrown from Visitor/Availability request only. Seems obvious once you know the answer.
  • There is no error code.
  • In order to test, you will need support to point an alternative endpoint for you, one that has passed the migration process before. You won't be able to get this response swapping endpoints and org ids in your instance.
  • It seems that mobile SDK really solves this, so you only need to worry if you are using an hybrid SDK or custom code.
Here are samples of requests and responses:

OK REQUEST:
GET /chat/rest/Visitor/Availability?org_id=000000000000000&deployment_id=000000000000000&Availability.ids=000000000000000 HTTP/1.1
Host: [NEW_ENDPOINT]
X-LIVEAGENT-API-VERSION: 39
X-LIVEAGENT-AFFINITY: null
Content-Type: application/json

OK RESPONSE:
{"messages":[{"type":"Availability", "message":{"results":[{"id":"000000000000000"}]}}]}

...

SWITCH SERVER REQUEST:
GET /chat/rest/Visitor/Availability?org_id=000000000000000&deployment_id=000000000000000&Availability.ids=000000000000000 HTTP/1.1
Host: [OLD_INSTANCE_ENDPOINT]
X-LIVEAGENT-API-VERSION: 39
X-LIVEAGENT-AFFINITY: null
Content-Type: application/json

SWITCH SERVER RESPONSE:
{"messages":[{"type":"SwitchServer", "message":{"newUrl":"[NEW_ENDPOINT]"}}]}
This was selected as the best answer
Zhicheng XieZhicheng Xie
Hi Salesforce team, I have the exact same question as this post, and there is no official document about which API shall return SwitchServer response.

Want to check if Denys's answer is still correct?
Also I am curious if handling SwitchServer should be used together with ReconnectSession API, as the session is reconnected, it should use the new server url provided by SwitchServer response I think?