0

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
                });

1 Answer 1

0

Hope it helps

to the extent of my research, Salesforce does not allow rest call from vf page js (I May be wrong)

But the problem that you are facing is same as mine the workaround that I found is using salesforce AJAX Toolkit

Try this code this may work

sforce.connection.remoteFunction({
   url : "https://host.salesforceliveagent.com/chat/rest/System/SessionId",
   requestHeaders: {
       "Content-Type":"application/json",
       "X-LIVEAGENT-API-VERSION": "41",
       "X-LIVEAGENT-AFFINITY": "null"
      },
   method: "GET",
   onSuccess : function(response) {
          alert(response);
      },
   onFailure : function(response) {
          alert("Failed" + response)
      }
});

Note: this tag is to be included

<script src="../../soap/ajax/41.0/connection.js" type="text/javascript">

Note: this has to be run first for ajax toolkit authentication

sforce.connection.sessionId='{!GETSESSIONID()}';

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .