Consuming the Case Assist API Using Apex

Coveo for Salesforce 4.7 (August 2020)

Please open a support case to enable this feature in your organization. Make sure to mention that you would like to enable Coveo Case Assist and to include your Coveo organization ID.

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 configuration ID to the CaseAssistApiClient as follows:

CoveoV2.CaseAssistApiClient client = CoveoV2.CaseAssistApiClient.getClient('YOUR CASE ASSIST CONFIGURATION 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 the 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 Configuration 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 Configuration ID Using the Coveo Administration Console

  1. Log in to the Coveo Administration Console.

  2. In the navigation menu on the left, under the Service section, select Case Assist.

  3. Double-click your Case Assist configuration to open it in edit mode.

  4. Retrieve your Case Assist configuration ID.

    In the browser URL, you’ll find your Case Assist configuration ID right after .../service/caseAssist/edit/. For example:

     https://platform.cloud.coveo.com/admin/#<MyOrganizationId>/service/caseAssist/edit/00000000-0000-0000-0000-000000000000
    

    where 00000000-0000-0000-0000-000000000000 is the Case Assist configuration ID.

Retrieving Your Case Assist Configuration ID Using the REST API

To find your Case Assist configuration 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 configuration ID.

    • My config represents the name of your Case Assist configuration.

Declaring the CaseAssistApiClient in Apex

Once you have your Case Assist configuration ID, you can now instantiate the CaseAssistApiClient.

  1. In Salesforce, access the Developer Console.

  2. Create the client instance as follows:

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

    We strongly recommend storing the Case Assist configuration 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?

Recommended Articles