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
NICHOLAS BLANCHARDNICHOLAS BLANCHARD 

Live Agent Rest API using cURL

Hi,

I'm currently testing out Live Agent in development. If I understand correctly I should be able to test out the rest API by executing some cURL commands and passing the correct information. I'm able to execute the System/SessionId request and get back the response with the key, id, and affinity token. However when I try to execute the Chasitor/ChasitorInit request it fails with this:

"An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. Error ID: 1312603297-5809 (119858002)"

Here's the command that I'm using for the request, with the deployment specific fields omitted.
curl -i --header 'Content-Type: application/json' —-header 'X-LIVEAGENT-AFFINITY: affinitytoken' --header 'X-LIVEAGENT-API-VERSION: 29' --header 'X-LIVEAGENT-SESSION-KEY: sessionkey' --header 'X-LIVEAGENT-SEQUENCE:sequence' -X POST -d "{ 'sessionId':'sessionid', 'organizationId': 'orgid', 'buttonId': 'buttonid', 'deploymentId': 'deploymentid', 'userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36', 'language': 'en-US', 'screenResolution': '1920x1080', 'prechatDetails': [], 'visitorName': 'John A.', 'receiveQueueUpdates': true, 'isPost': true, 'prechatEntities':[]}" https://endpoint/chat/rest/Chasitor/ChasitorInit

Is there something that I might be missing here?
Thanks.
ShashankShashank (Salesforce Developers) 
If you are still facing this issue, please let me know the date and time of the last occurance of this error and the error number in the last occurance.
NICHOLAS BLANCHARDNICHOLAS BLANCHARD
Hey Shashank,
I just replicated (6/11 2:43pm MDT) this issue slightly differently, this is the error I'm getting now:
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. Error ID: 1396150787-2806 (2074802041)

This happens when I add the prechatDetails to the curl request like this:
curl -v -H 'X-LIVEAGENT-AFFINITY: affinitytoken' -H 'X-LIVEAGENT-API-VERSION: 29' -H 'X-LIVEAGENT-SESSION-KEY: sessionkey' -H 'Content-Type: application/json' https://d.la3-c1-was.salesforceliveagent.com/chat/rest/Chasitor/ChasitorInit -d '{ "sessionId":"sessionId", "organizationId": "org_id", "buttonId": "button_id", "deploymentId": "deployment_id", "userAgent": "", "language": "en-US", "screenResolution": "1920x1080", "visitorName": "John A.", "prechatDetails": [{"label":"contactFirstName","value":"Bob","transcriptFields":["contactFirstName__c"],"displayToAgent":true}], "prechatEntities":[], "receiveQueueUpdates": true, "isPost": true }'

Do you see anything wrong with the way the prechatDetails is defined here?
Thanks.
ShashankShashank (Salesforce Developers) 
This is most probably because of this known issue: https://success.salesforce.com/issues_view?id=a1p300000008XZZAA2

Please see if the workaround provided works for you until it is fixed.
NICHOLAS BLANCHARDNICHOLAS BLANCHARD
That worked, thanks!
NICHOLAS BLANCHARDNICHOLAS BLANCHARD
I have an additional question here. Using this rest API and cUrl would I be able to create a case? If so how would that look in terms of the prechatDetails and prechatEntities? I haven't found any documentation around this and have been unsuccessful trying to fill the prechatEntities fields. Thanks.
Marcel dos SantosMarcel dos Santos
Yes, you would. You have to include an array with prechat entities you want for your chat. In the example below, I'm creating a case and setting a contact to it, if a contact is found.
 
{
    "organizationId":"##",
    "deploymentId":"###",
    "buttonId":"###",
    "sessionId":"###",
    "userAgent":"###",
    "language":"en-US",
    "screenResolution":"1920x1080",
    "visitorName":"John",
    "prechatDetails":[
        {
            "label":"Email",
            "value":"john@somecompany.com",
            "entityMaps":[
                {
                    "entityName":"Contact",
                    "fieldName":"Email"
                }
            ],
            "transcriptFields":[
                "Email__c"
            ],
            "displayToAgent":true
        },
        {
            "label":"Subject",
            "value":"Case Subject",
            "entityMaps":[
                {
                    "entityName":"Case",
                    "fieldName":"Subject"
                }
            ],
            "transcriptFields":[
                "Case_Subject__c"
            ],
            "displayToAgent":true
        },
        {
            "label":"Subject",
            "value":"Chat Subject",
            "entityMaps":[
                {
                    "entityName":"Case",
                    "fieldName":"Subject"
                }
            ],
            "transcriptFields":[
                "Case_Subject__c"
            ],
            "displayToAgent":true
        },
        {
            "label":"Origin",
            "value":"Live Chat",
            "entityMaps":[
                {
                    "entityName":"Case",
                    "fieldName":"Origin"
                }
            ],
            "transcriptFields":[
                "Case_Origin__c"
            ],
            "displayToAgent":true
        }
    ],
    "prechatEntities":[
        {
            "entityName":"Contact",
            "showOnCreate":true,
            "linkToEntityName":"Case",
            "linkToEntityField":"ContactId",
            "saveToTranscript":"Contact",
            "entityFieldsMaps":[
                {
                    "fieldName":"Email",
                    "label":"Email",
                    "doFind":true,
                    "isExactMatch":true,
                    "doCreate":false
                }
            ]
        },
        {
            "entityName":"Case",
            "showOnCreate":true,
            "linkToEntityName":null,
            "linkToEntityField":null,
            "saveToTranscript":"Case",
            "entityFieldsMaps":[
                {
                    "fieldName":"Subject",
                    "label":"Subject",
                    "doFind":false,
                    "isExactMatch":false,
                    "doCreate":true
                },
                {
                    "fieldName":"Origin",
                    "label":"Origin",
                    "doFind":false,
                    "isExactMatch":false,
                    "doCreate":true
                },
                {
                    "fieldName":"Description",
                    "label":"Body",
                    "doFind":false,
                    "isExactMatch":false,
                    "doCreate":true
                }
            ]
        }
    ],
    "receiveQueueUpdates":true,
    "isPost":true
}