Coveo for Sitecore 5 is now available!

Exception When Trying to Switch Organization

Symptoms

Whether through the Command Center or the Coveo Search section of the Sitecore Control Panel, you are not able to switch to another cloud organization. Instead, you get the following message in your Sitecore log files:

29116 09:44:53 INFO  Could not retrieve license from Coveo cloud.
Exception: Coveo.Framework.Exceptions.CriticalException
Message: ACCESS_DENIED
Source: Coveo.Framework
   at Coveo.Framework.Connection.CriticalExceptionHandler.HandleException(HttpClientException p_Exception, String p_Message)
   at Coveo.CloudPlatformClientBase.CloudPlatformClient.HandleInvalidTokenError(HttpClientException p_Exception)
   at Coveo.CloudPlatformClientBase.CloudPlatformClient.PerformPlatformCallWithErrorHandling(String p_RequestMethod, String p_RequestUri, String p_RequestContent, Boolean p_SkipAccessDeniedValidation)
   at Coveo.CloudPlatformClientBase.CloudPlatformClient.GetLicense(String p_OrganizationId)
   at Coveo.CloudPlatformClientBase.CloudPlatformClient.GetFullLicense(String p_OrganizationId)
   at Coveo.SearchProvider.Licensing.CloudLicenseRetriever.GetCloudLicense()
Nested Exception
Exception: Coveo.Framework.Utils.Rest.HttpClientException
Message: Failed to obtain resource located at '[COVEO_CLOUD_URL]'.
[BEGIN RESPONSE BODY]{"message":"Invalid access token.","errorCode":"INVALID_TOKEN","requestID":"..."}[END RESPONSE BODY]
Source: Coveo.Framework
   at Coveo.Framework.Utils.Rest.HttpClient.HandleResponseException(WebException p_Exception, String p_Url, Int64 p_CallId)
   at Coveo.Framework.Utils.Rest.HttpClient.ExecuteRequest(String p_Url, Func`2 p_CreateRequest, Int64 p_CallId)
   at Coveo.Framework.Utils.Rest.HttpClient.GetRaw(String p_Url)
   at Coveo.Framework.Utils.Rest.HttpClient.Get(String p_Url)
   at Coveo.CloudPlatformClientBase.CloudPlatformClient.PerformPlatformGetCall(String p_OperationUri)
   at Coveo.CloudPlatformClientBase.CloudPlatformClient.PerformPlatformCall(String p_HttpMethod, String p_OperationUri, String p_RequestContent)
   at Coveo.CloudPlatformClientBase.CloudPlatformClient.PerformPlatformCallWithErrorHandling(String p_RequestMethod, String p_RequestUri, String p_RequestContent, Boolean p_SkipAccessDeniedValidation)
Nested Exception
Exception: System.Net.WebException
Message: The remote server returned an error: (401) Unauthorized.
Source: System
   at System.Net.HttpWebRequest.GetResponse()
   at Coveo.Framework.Utils.Rest.HttpClient.ExecuteRequest(String p_Url, Func`2 p_CreateRequest, Int64 p_CallId)

You can also see the following message if the configured API key cannot be properly decrypted:

An error occurred while decrypting the ApiKey configuration element value. The element value will be used as is assuming it is unencrypted.

Cause

This issue occurs when you have an invalid API key in your configuration that is not recognized by Coveo Cloud.

Resolution

You need to regenerate a temporary API key in Coveo Cloud to switch organization.

  1. Create a new API key (see Activating Coveo for Sitecore - Creating the API keys). You do not need to create a new SearchApiKey.
  2. Set this API key directly in the Coveo.CloudPlatformClient.Custom.config file, inside the ApiKey node.
  3. Try configuring your organization, as usual.
  4. Once your organization configured, you can safely delete the API key you created in Coveo Cloud.