Insights

How To Update A Coveo API Key's Configuration Via The Coveo Platform API

Updating The Configuration Of A Coveo API Key Using Coveo Platoform API

Recently we had a client that was looking to explore additional features within Coveo. As such, we looked at using a separate Access Token that had restricted permissions to ensure it could only be used for what it was intended.

One of the ways you can accomplish this is by restricting the API key to a specific Search Hub. Doing so is quite easy in the Platform Admin under API Keys > Privileges > Search > Limit the API Key Scope. However, we found an issue where the token couldn't be updated via the interface. It's not something that is common or is likely to happen to anyone else, but we needed another way. Enter the Coveo Platform API.

Get The API Details

First thing first, head on over to the Coveo Platform API and specifically you want to look at the Authorization Server definition. This should load up if you use the link and should resemble something like the following.

Coveo Platform API Keys

So first we're going to use the Show API key method.

Coveo Platform API GET command for API Key ID.

We will need the organizationId and the apiKeyId.You can retrieve these from the Platform Admin after clicking on the particular API key and then grabbing the values from the URL:

https://platform.cloud.coveo.com/admin/#<-- ORG ID -->/organization/api-access/<-- API KEY ID -->/configuration

Upon clicking Execute and you have access (via the Authorize button above), you should receive a response body containing all the details of the API key.

I will note that you could use a program like Postman, as long as you have an Access Token with the necessary rights.

Copy that response body to a separate file or text editor, where you can then make the appropriate changes.

In our case, because we wanted to update the searchHub so we made changes to the JSON to set the appropriate value.

...
"search": {
    "enforcedQueryPipelineConfiguration": {
      "searchHub": "recommendations"
    }
  }
},
...

Once the changes have been made, we can then move on to updating the API Key.

Updating The API Key Configuration

Find the method Update API key. It will look like the following:

Coveo Platform API PUT command for API Key ID.

Add back in the organizationId, apiKeyId, and in the apiKeyModel add back in the JSON you just updated.

Upon clicking Execute you should receive a response 201 indicating it has been updated.

To verify you have made the change successfully, you can go back to Get API Details above and repeat that process to obtain the hopefully updated configuration.

👋 Hey Sitecore Enthusiasts!

Sign up to our bi-weekly newsletter for a bite-sized curation of valuable insight from the Sitecore community.

What’s in it for you?

  • Stay up-to-date with the latest Sitecore news
  • New to Sitecore? Learn tips and tricks to help you navigate this powerful tool
  • Sitecore pro? Expand your skill set and discover troubleshooting tips
  • Browse open careers and opportunities
  • Get a chance to be featured in upcoming editions
  • Learn our secret handshake
  • And more!
Sitecore Snack a newsletter by Fishtank Consulting
 

Meet David Austin

Development Team Lead | Sitecore Technology MVP x 3

📷🕹️👪

David is a decorated Development Team Lead with Sitecore Technology MVP and Coveo MVP awards, as well as Sitecore CDP & Personalize Certified. He's worked in IT for 25 years; everything ranging from Developer to Business Analyst to Group Lead helping manage everything from Intranet and Internet sites to facility management and application support. David is a dedicated family man who loves to spend time with his girls. He's also an avid photographer and loves to explore new places.

Connect with David