I am facing an issue trying to establish the chat with chasitorinit api. It always comes back as "Request is not a valid ChasitorInit" (400-Bad Request).I am able to retrieve the SeesionId without any issues but the chasitorinit does not work I have tried many variations of json body and header parameters but it does not seem to work somehow.
I have referenced this article for the payload
400 Request is not a valid ChasitorInit - live agent rest api
Below is the structure of the code that I am using:
$.ajax({
url: 'https://hostname/chat/rest/System/SessionId',
type: 'Get',
dataType: 'json',
Accept: "text/plain; charset=utf-8",
contentType: 'application/x-www-form-urlencoded',
success: function (data) {sessionData=data;},
error: OnError,
beforeSend: function (xhr) {
xhr.setRequestHeader('X-LIVEAGENT-API-VERSION', 34);
xhr.setRequestHeader('X-LIVEAGENT-AFFINITY', null);
},
async: false
});
$.ajax({
url: 'https://hostname/chat/rest/Chasitor/ChasitorInit',
type: 'POST',
dataType: 'json',
data:{ "sessionId": sessionData.key, "organizationId": "00D58000000OwMB", "deploymentId": "57258000000L1mj", "buttonId": "57358000000L24F", "userAgent": "", "language": "en-US", "screenResolution": "1900x1080", "visitorName": "Test Visitor", "prechatDetails": [], "prechatEntities": [], "receiveQueueUpdates": true, "isPost": true },
Accept: "text/plain; charset=utf-8",
contentType: 'application/x-www-form-urlencoded',
success: function (data) {ChasitorData=data; alert('Success');},
error: OnError,
beforeSend: function (xhr) {
xhr.setRequestHeader('X-LIVEAGENT-API-VERSION', '34');
xhr.setRequestHeader('X-LIVEAGENT-AFFINITY', sessionData.affinityToken)
xhr.setRequestHeader('X-LIVEAGENT-SESSION-KEY', sessionData.key);
},
async: false
});