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
Manoj MManoj M 

ChasitorInit : Session required but was invalid or not found

Creating sessionId is working fine:

https://developer.salesforce.com/docs/atlas.en-us.live_agent_rest.meta/live_agent_rest/live_agent_rest_SessionId.htm

I am trying to create a chat visitor session but I am getting the error: "Session required but was invalid or not found". 
https://developer.salesforce.com/docs/atlas.en-us.live_agent_rest.meta/live_agent_rest/live_agent_rest_ChasitorInit.htm

 

Headers:
  Authorization: 'Bearer xxxx',
    'X-LIVEAGENT-API-VERSION': '48',
    'X-LIVEAGENT-SESSION_KEY': 'xxxxxxxx', // key from sessionId request
    'X-LIVEAGENT-AFFINITY': 'xxxxxxxx', // affinityToken from sessionId 
    'X-LIVEAGENT-SEQUENCE': '1'

Request Body:
    sessionId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    organizationId: '00Dxxxxxxxxxxxxx',
    deploymentId: '572xxxxxxxxxxxx',
    buttonId: '573xxxxxxxxxxxx',
    userAgent: '',
    language: 'en-US',
    screenResolution: '2560x1440',
    visitorName: 'Test',
    prechatDetails: [],
    prechatEntities: [],
    receiveQueueUpdates: true,
    isPost: true
SwethaSwetha (Salesforce Developers) 
HI Manoj,

This error usually occurs if POST request to initiate chat session has not been done immediately after getting the response from the GET Request.

There's a timeout value for the session. It's recommended that you have two REST Console windows opened so that you can quickly change from one request to another.

Please mark this answer as best so that other community members can be helped.

Thank you
Sergey ChernetskySergey Chernetsky

I used to get the same issue despite I posted second request right after getting session ids. After spending a day of painful investigations I've finally found the problem: in this help article (https://developer.salesforce.com/docs/atlas.en-us.live_agent_rest.meta/live_agent_rest/live_agent_rest_ChasitorInit.htm)there is a bad header param description. It should be X-LIVEAGENT-SESSION-KEY header name, NOT X-LIVEAGENT-SESSION_KEY (dash instead of underscore!!!).

The problem is in 47,48 versions articles. Below 46 it written right.

Hope it helps!