Consume the Case Assist API using Apex
Consume the Case Assist API using Apex
|
|
Note
While this article remains available for backward compatibility purposes, we now recommend using Coveo Quantic Case Assist components to leverage the Case Assist API. The Quantic components can greatly simplify your implementation in general. |
|
|
Available since
This feature was introduced in the August 2020 release of Coveo for Salesforce version 4.7. |
The purpose of the Case Assist feature set is to improve the efficiency of customer service agents by streamlining the case creation process. It provides various tools to increase case deflection and also helps end users create cases that are more accurate and complete.
How can you leverage these features using Apex?
The CaseAssistApiClient is the answer.
It’s a simple Apex client that lets you query the Case Assist API.
The main advantage is that it handles all security details for you.
That way, you can focus on other priorities.
To query the Case Assist API, pass your Case Assist ID to the CaseAssistApiClient as follows:
CoveoV2.CaseAssistApiClient client = CoveoV2.CaseAssistApiClient.getClient('YOUR CASE ASSIST ID GOES HERE');
If you don’t already have a Case Assist configuration, see Creating your Case Assist configuration.
Creating your Case Assist configuration
The preferred way of creating a Case Assist configuration is using the Coveo Administration Console (see Manage Case Assist Configurations). However, you can also create it using the REST API, if necessary.
Creating your Case Assist configuration using the REST API
To create your Case Assist configuration, you need an access token and an organization ID.
At a minimum, you’re required to pass a name for your Case Assist configuration. For example:
{
"name": "My config"
}
You can then use the following snippet to issue a request:
curl -X POST /
--header 'Authorization: Bearer <MyAccessToken>' /
--header 'Content-Type: application/json' /
--header 'Accept: application/json' /
-d '{ "name": "My config" }' /
'https://platform.cloud.coveo.com/rest/organizations/<MyOrganizationId>/caseassists'
In the Authorization HTTP header:
-
Replace
<MyAccessToken>with a valid Coveo access token. See Get your Coveo access token.
In the request path:
-
Replace
<MyOrganizationId>with the actual ID of the target Coveo organization. See Retrieve the organization ID.
Retrieving your Case Assist ID
Once you’ve created your Case Assist configuration, you can retrieve it using the Coveo Administration Console. You can also retrieve it using the REST API, if necessary.
Retrieving your Case Assist ID using the REST API
To find your Case Assist ID, first retrieve all the Case Assist configurations. Then, by finding the name of your Case Assist configuration, you’ll be able to extract its ID.
To retrieve all the Case Assist configurations:
-
Issue the following request:
curl -X GET / --header 'Authorization: Bearer <MyAccessToken>' / --header 'Accept: application/json' / 'https://platform.cloud.coveo.com/rest/organizations/<MyOrganizationId>/caseassists'In the
AuthorizationHTTP header:-
Replace
<MyAccessToken>with a valid Coveo access token. See Get your Coveo access token.
In the request path:
-
Replace
<MyOrganizationId>with the actual ID of the target Coveo organization. See Retrieve the organization ID.
-
The request returns a JSON document similar to this one:
{
"configurations": [
{
"id": "00000000-0000-0000-0000-000000000000",
"name": "My config"
}
],
"totalCount": 1
}
Where:
-
00000000-0000-0000-0000-000000000000represents your Case Assist ID. -
My configrepresents the name of your Case Assist configuration.
Declaring the CaseAssistApiClient in Apex
Once you have your Case Assist ID, you can now instantiate the CaseAssistApiClient.
-
In Salesforce, access the Developer Console.
-
Create the client instance as follows:
String caseAssistId = '00000000-0000-0000-0000-000000000000'; CoveoV2.CaseAssistApiClient client = CoveoV2.CaseAssistApiClient.getClient(caseAssistId);NoteWe strongly recommend storing the Case Assist ID in a Salesforce setting. This will let you use different configurations in different environments. It will also let you reference a different configuration without having to redeploy your Apex code.