Thursday, April 29, 2021

Sitecore 10 - Error while getting client credentials token: invalid_client

 This is a very common error while working on Sitecore 10 with SCS, Today again I got this error so I thoughts it's good to write a blog on the error, here is the complete details

The full error is here

SerPush

========================================

Executing: .\CakeFiles\Serialization.ps1 -CMHost "https://yoursite.localhost" -IDHost "https://yoursite.localhost" -CLISecret "Bm1bGYPIO7s5Xt0F" -u

Error while getting client credentials token: invalid_client

Client credentials authentication configured without a client secret. Ensure to set the SITECORE_DEFAULT_CLIENT_SECRET environment variable before using this environment.

Login information has been saved.

Client Credentials: Client Secret was not defined. Must be added to default endpoint.

I tried to reset the config and now got the below error 

You are not authorized to perform the task you are attempting. You may need to be assigned additional permissions.

I restarted PowerShell and run under the admin mode (Although this was already under the Admin mode) that has resolved the issue

Wednesday, April 28, 2021

Sitecore 10 - Issue during the serialization (SCS) push - GraphQL.Common.Response.GraphQLResponse

 Recently, I got the below error while working on Sitecore 10 with content serialization.


Unhandled exception: System.Exception: Unhandled exception

 ---> System.AggregateException: One or more errors occurred. (Error converting value 404 to type 'GraphQL.Common.Response.GraphQLResponse'. Path '', line 1, position 3.) (Error converting value 404 to type 'GraphQL.Common.Response.GraphQLResponse'. Path '', line 1, position 3.) (Error converting value 404 to type 'GraphQL.Common.Response.GraphQLResponse'. Path '', line 1, position 3.) (Error converting value 404 to type 'GraphQL.Common.Response.GraphQLResponse'. Path '', line 1, position 3.) (Error converting value 404 to type 'GraphQL.Common.Response.GraphQLResponse'. Path '', line 1, position 3.) (Error converting value 404 to type 'GraphQL.Common.Response.GraphQLResponse'. Path '', line 1, position 3.)

 ---> Newtonsoft.Json.JsonSerializationException: Error converting value 404 to type 'GraphQL.Common.Response.GraphQLResponse'. Path '', line 1, position 3.

 ---> System.ArgumentException: Could not cast or convert from System.Int64 to GraphQL.Common.Response.GraphQLResponse.

   at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)

   at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)

   --- End of inner exception stack trace ---

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)

   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)

   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)

   at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)

   at GraphQL.Client.Http.Internal.GraphQLHttpHandler.ReadHttpResponseMessageAsync(HttpResponseMessage httpResponseMessage)

   at GraphQL.Client.Http.Internal.GraphQLHttpHandler.PostAsync(GraphQLRequest request, CancellationToken cancellationToken)

   at Sitecore.DevEx.Serialization.Client.Datasources.Sc.SitecoreApiClient.<>c__DisplayClass13_0.<<RunQuery>b__0>d.MoveNext() in C:\BA\4c1e764e9356dfd1\src\Sitecore.DevEx.Serialization.Client\Datasources\Sc\SitecoreApiClient.cs:line 127

--- End of stack trace from previous location where exception was thrown ---

   at Sitecore.DevEx.Configuration.Authentication.OidcAuthenticationProvider.MakeAuthenticatedRequestInternal(HttpClient client, Func`2 requestAction) in C:\BA\4c1e764e9356dfd1\src\Sitecore.DevEx.Configuration\Authentication\OidcAuthenticationProvider.cs:line 80

   at Sitecore.DevEx.Configuration.Authentication.OidcAuthenticationProvider.MakeAuthenticatedRequest(HttpClient client, Func`2 requestAction) in C:\BA\4c1e764e9356dfd1\src\Sitecore.DevEx.Configuration\Authentication\OidcAuthenticationProvider.cs:line 25

   at Sitecore.DevEx.Configuration.Authentication.ClientCredentialsAuthenticationProvider.MakeAuthenticatedRequest(HttpClient client, Func`2 requestAction) in C:\BA\4c1e764e9356dfd1\src\Sitecore.DevEx.Configuration\Authentication\ClientCredentialsAuthenticationProvider.cs:line 90

   at Sitecore.DevEx.Configuration.Models.EnvironmentConfiguration.MakeAuthenticatedRequest(HttpClient client, Func`2 requestAction) in C:\BA\4c1e764e9356dfd1\src\Sitecore.DevEx.Configuration\Models\EnvironmentConfiguration.cs:line 168

   at Sitecore.DevEx.Serialization.Client.Datasources.Sc.SitecoreApiClient.RunQuery(String servicePath, GraphQLRequest request, Boolean assertNoErrors, CancellationToken cancellationToken) in C:\BA\4c1e764e9356dfd1\src\Sitecore.DevEx.Serialization.Client\Datasources\Sc\SitecoreApiClient.cs:line 155

   at Sitecore.DevEx.Serialization.Client.Datasources.Sc.Query.SitecoreTreeDataStore.ExecuteSingleBatchQuery[T](String batchQueryFragment, TreeScope scope, ItemSpec[] specs, CancellationToken cancellationToken) in C:\BA\4c1e764e9356dfd1\src\Sitecore.DevEx.Serialization.Client\Datasources\Sc\Query\SitecoreTreeDataStore.cs:line 402

Investigation - I did the git clean up and I think the cleanup has removed a few files or so

Steps -  I build the solution and it was working fine,  I ran the SerPush command again and now this time got the error that one of the scripts is missing from the Theme Component

did not exist in serialized items (66 subtrees) data store. An empty source indicates that you need to fill that source with data before attempting to push it into a destination. Usually, that means you need to pull an initial data set from Sitecore to fill serialized files before being able to push serialized data into Sitecore.

I restored the missing file and the issue got resolved.

Friday, April 9, 2021

Sitecore settings to open media library in a new tab

 Below are the settings to open the medial library in a separate tab.

        <mediaLibrary>

            <mediaTypes>

                <mediaType name="PDF file" extensions="pdf">

                    <forceDownload>false</forceDownload>

                </mediaType>

                <mediaType name="Word document" extensions="doc">

                    <forceDownload>false</forceDownload>

                </mediaType>

                <mediaType name="Word 2007 document" extensions="docx">

                    <forceDownload>false</forceDownload>

                </mediaType>

            </mediaTypes>

        </mediaLibrary>

Thursday, March 4, 2021

Sitecore 10 - ASP.NET Core Rendering with Docker and Sitecore 10 - Common issues and fixes.

Recently, I did two presentations on this topic, and during the local environment setup, I got a few errors. This blog post will mention those common issues and how I fixed them to make them work.


This error comes when we have the diff controller name (JSS rendering) the name should be the same and consistant,



Recreating the container resolve this issue - 

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

kill all running containers with docker kill $(docker ps -q)


Same as above, recreating the container.

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

kill all running containers with docker kill $(docker ps -q)


Same as above, recreating the container.

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

kill all running containers with docker kill $(docker ps -q)

Issue due to the naming inconsistency. After updating the JSS rendering name, the case got the fix.

Here is the link to my latest presentation - 

A few useful command - https://www.slideshare.net/JitendraSoni6/sitecore-10-aspnet-core-rendering-with-docker-and-sitecore-10

Docker
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker system prune
docker image prune
docker container prune
kill all running containers with docker kill $(docker ps -q)
delete all stopped containers with docker rm $(docker ps -a -q)
delete all images with docker rmi $(docker images -q)
update and stop a container that is in a crash-loop with docker update --restart=no && docker stop
Get docker container disk utilization: docker system df




Wednesday, March 3, 2021

Sitecore (Docker) - Fix for error response from daemon: conflict: unable to delete 77e0b9227773 (must be forced) - image is referenced in multiple repositories



Recently, I got the below error -

Error response from daemon: conflict: unable to delete 77e0b9227773 (must be forced) - image is referenced in multiple repositories

Error response from daemon: conflict: unable to delete 77e0b9227773 (must be forced) - image is referenced in multiple repositories

I checked that continer is already stopped and tried below command but that didn't resolve the issue

docker container prune

docker network prune

docker system prune

docker volume prune

docker builder prune

Finally, I tried the below command that help me to resolve the issue. I attempted to pass the -f parameter (I didn't find that details during the search)

docker image rm 77e0b9227773 --f

77e0b9227773  - this is the Id of the image.

I hope that will help to others.

Saturday, February 13, 2021

Sitecore 10 - SXA based query for the droplink to show data from shared and main site based on the SXA token.

Scenario - Need to fill the drop link to show the style folder from the global and current site as combined same like when we choose data source through the experience editor for the SXA component,  It seems pretty simple, because we have a similar query in the SXA OOTB components, as mentioned below -


query:$site/*[@@name='Data']/*[@@templatename='Promo Folder']|query:$sharedSites/*[@@name='Data']/*[@@templatename='Promo Folder']


When we use the same query in drop link - 


Result as an error


ield control has failed to render: Invalid lookup source "query:$site/*[@@name='Data']/*[@@templatename='Promo Folder']|query:$sharedSites/*[@@name='Data']/*[@@templatename='Promo Folder']": End of string expected at position 88..Details

Sitecore.Exceptions.LookupSourceException: Invalid lookup source "query:$site/*[@@name='Data']/*[@@templatename='Promo Folder']|query:$sharedSites/*[@@name='Data']/*[@@templatename='Promo Folder']": End of string expected at position 88.. ---> Sitecore.Data.Query.ParseException: End of string expected at position 88. at Sitecore.Data.Query.QueryParser.Raise(String error) at Sitecore.Data.Query.QueryParser.DoParse(String query) at Sitecore.Data.Query.Query..ctor(String query) at Sitecore.Data.Query.Query.SelectItems(String query, QueryContext contextNode, Database database) at Sitecore.Data.DefaultDatabase.SelectItems(String query) at Sitecore.XA.Foundation.Multisite.Pipelines.GetLookupSourceItems.ExpandVirtualItems.Process(GetLookupSourceItemsArgs args) at (Object , Object ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) at Sitecore.Web.UI.HtmlControls.Data.LookupSources.GetItems(Item current, String source) --- End of inner exception stack trace --- at Sitecore.Web.UI.HtmlControls.Data.LookupSources.GetItems(Item current, String source) at Sitecore.Shell.Applications.ContentEditor.LookupEx.GetItems(Item current) at Sitecore.Shell.Applications.ContentEditor.LookupEx.DoRender(HtmlTextWriter output) at Sitecore.Web.UI.WebControl.Render(HtmlTextWriter output) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at Sitecore.Shell.Applications.ContentEditor.EditorFieldContainer.RenderChildren(HtmlTextWriter writer)

I tried a few more query but it didn't work,   Although the individual query was working fine, means reading data from one source using the SXA token but whenever I combined it throws the error

query:$sharedSites/Presentation/Styles|query:$sharedSites/Presentation/Styles

query:$site/Presentation/Styles//*[@@name='Icons']//*, query:$site/Presentation/Styles//*[@@name='Icons']//*

query:$site/*[@@name='Data']/*[@@templatename='Banner Folder']//*and query:$sharedSites/*[@@name='Data']/*[@@templatename='Banner Folder']//*

query:$site/*[@@name='Presentation']/*[@@templatename='Style']|query:$sharedSites/*[@@name='Presentation']/*[@@templatename='Style']

query:$site/*[@@name='Data']/*[@@templatename='Styles']|query:$sharedSites/*[@@name='Data']/*[@@templatename='Styles']

query:$sharedSites/Presentation/Styles//*[@@templatename='Style']

query:$sharedSites/Presentation/Styles//*[@@name='Icons']//*[@@templatename='Styles']

query:$site/*[@@name='Data']/*[@@templatename='Banner Folder']|query:$sharedSites/*[@@name='Data']/*[@@templatename='Banner Folder']

query:$sharedSites/Presentation/Styles//*[@@templatename='Style'] - Working

query:$sites/Presentation/Styles//*[@@name='Icons']//*[@@templatename='Style']  - Working

Solution - After checking the OOTB SXA component query, I found it's using or close with the complete query like below -


query:$site/*[@@name='Data']/*[@@templatename='Promo Folder']|query:$sharedSites/*[@@name='Data']/*[@@templatename='Promo Folder']


I changed the query to below and it worked for me

query:$site/*[@@name='Data']/*[@@templatename='Promo Folder']|$sharedSites/*[@@name='Data']/*[@@templatename='Promo Folder']

Here is the outcome - You can see the second drop link field with the updated query



I hope that will help others.

Saturday, February 6, 2021

Sitecore 10 - (Sitecore + Octopus ) - How to configure the environment variable, site group setting.




I think this is very common requirement to configure the enviroment variable driven from the octopus, example below


We can configure this in the site gropu and based on sitecore serialization folder structure we will have the .yml file for the above settings as example below

the configuration (yml file) will look like this 


Now, Create a new step in octopus and replace this yml file (Substitute variable in Files) - You can define the wild card syntex like 

#{Path}\src\Project\abc\**\*.yml

Define the variable and value in octopus, in this example for "#{abc.hostname}" and that's it during the deploymnet based on target environment and variable value, Octopus will replace the file and upload into the sitecore, we can use the similar feature for other site settings like analytics key or any sft/ftp configuration etc.