Consuming the Case Assist API using Apex

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.

Enterprise Coveo for Salesforce 4.7 (August 2020)

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:

In the request path:

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, you must 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:

  1. 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 Authorization HTTP header:

    In the request path:

    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-000000000000 represents your Case Assist ID.

    • My config represents 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.

  1. In Salesforce, access the Developer Console.

  2. Create the client instance as follows:

     String caseAssistId = '00000000-0000-0000-0000-000000000000';
     CoveoV2.CaseAssistApiClient client = CoveoV2.CaseAssistApiClient.getClient(caseAssistId);
    

    We 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.

What’s next?