Failed to Configure the Organization Error When Trying to Switch Organization

In this article

Symptoms

In the Configuration section of the Command Center, you’re not able to switch to another organization and get the following message:

Failed to configure the organization: Error: Something went wrong. Please contact your administrator.

Also, in your Sitecore logs files, you see the following error message:

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 can’t be properly decrypted:

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

Cause

This issue occurs when you have an invalid API key in your configuration that isn’t recognized by the Coveo Platform.

Resolution

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

  1. Create a new API key (see Activate Coveo for Sitecore - Creating the API keys). You don’t need to create a new SearchApiKey.

  2. Set this API key directly in the Coveo.CloudPlatformClient.Custom.config file, inside the ApiKey node.

  3. In the Configuration section of the Command Center, try configuring your organization, as usual.

  4. Once your organization configured, you can safely delete the API key you created in Coveo.