Sunday, January 15, 2023

Troubleshooting Sitecore JSS: Resolving the "Provided SSC API Key is Not Valid" Error

 

Recently, while doing another setup, I got this error 


Solution - First try to hit this URL 

It's related with the Jss API, make sure that you have created a new API key here 


Try to this this URL to confirm if the GraphQL service is running

https://sitecore103sc.dev.local/api/graph/items/master/ui?sc_apikey={AC48C51E-DDFF-48E5-BA2A-1884CE9CCBF2}

When I hit this URL, I got below error 


Follow this document to setup the GraphQL - https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-headless-development/start-using-sitecore-graphql-api.html

Here are the steps


1. Update this configuration to true 

<compilation debug="true">.


Enable the master GraphQL file 




After this change, I got a different error while browing GraphQL service

Now, at this stage, try to hit the GraphQL UI

https://sitecore103sc.dev.local/sitecore/api/graph/items/master/ui

I go this error 
{"errors":[{"message":"Authentication required."}]}



Make below change to Sitecore.Services.GraphQL.config

Finally to make it work, you have to make the below change  (This was the main change in my scenario)

Go to 
C:\inetpub\wwwroot\Sitecore103sc.dev.local\App_Config\Sitecore\Owin.Authentication\Sitecore.Owin.Authentication.config

add this line 
<path>/sitecore/api/graph/items</path> under       </siteNeutralPaths>


After that change, I can browser the GraphQL through the UI

Please note, it's recommned that you should not enable these GraphQL end point on prodution for the security purpose, all these changes I'm doing is just for the local setup.

but still, I got the authentication error , I'm running below query


query {
  # path can be an item tree path or GUID-based id
  item(path: "/sitecore/content/Experience-Edge/home", language: "en") {
    # items can be cast to a Template type with inline fragments
    ... on AppRoute {
      pageTitle {
        value
      }
    }
    # fields can be cast to a Field type with inline fragments
    field(name: "pageTitle") {
      ... on TextField {
        value
      }
    }
  }
}



I made the below changes to the API key, related to the CORS but it didn't help 




After this change, I start the  JSS application but got the below error 




rror: GraphQL.ExecutionError: Error trying to resolve layout. ---> System.ArgumentNullException: Value cannot be null. Parameter name: root at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName) at Sitecore.Data.ItemResolvers.ItemPathResolver.ResolveItem(String path, Item root) at Sitecore.Services.GraphQL.EdgeSchema.Queries.LayoutQuery.Resolve(ResolveFieldContext context) at Sitecore.Services.GraphQL.Schemas.RootFieldType`2.Intercept(ResolveFieldContext context) at GraphQL.Resolvers.FuncFieldResolver`1.GraphQL.Resolvers.IFieldResolver.Resolve(ResolveFieldContext context) at GraphQL.Execution.ExecutionStrategy.<ExecuteNodeAsync>d__7.MoveNext() --- End of inner exception stack trace ---: {"response":{"data":{"layout":null},"errors":[{"message":"GraphQL.ExecutionError: Error trying to resolve layout. ---> System.ArgumentNullException: Value cannot be null.\r\nParameter name: root\r\n at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName)\r\n at Sitecore.Data.ItemResolvers.ItemPathResolver.ResolveItem(String path, Item root)\r\n at Sitecore.Services.GraphQL.EdgeSchema.Queries.LayoutQuery.Resolve(ResolveFieldContext context)\r\n at Sitecore.Services.GraphQL.Schemas.RootFieldType`2.Intercept(ResolveFieldContext context)\r\n at GraphQL.Resolvers.FuncFieldResolver`1.GraphQL.Resolvers.IFieldResolver.Resolve(ResolveFieldContext context)\r\n at GraphQL.Execution.ExecutionStrategy.<ExecuteNodeAsync>d__7.MoveNext()\r\n --- End of inner exception stack trace ---","locations":[{"line":2,"column":7}],"path":["layout"],"extensions":{"code":"ARGUMENT_NULL"}}],"status":200,"headers":{}},"request":{"query":"query {\n layout(site:\"sitecore-jss-app\", routePath:\"/\", language:\"en\"){\n item {\n rendered\n }\n }\n }"}}

\


After this change, I restated my system and it started working

Monday, January 9, 2023

Resolving "curl: (6) Could not resolve host: nodejs.org" Error in Dockerized Headless Setup


Encountering errors during the configuration of a headless setup using Docker can be a stumbling block for developers. In this blog post, we'll address a specific issue where the error "curl: (6) Could not resolve host: nodejs.org" surfaced and explore a straightforward solution to overcome this hurdle.

Error Details:

The error manifested while attempting to run a headless setup with Docker. Despite successfully accessing the Dockerfile at \docker\build\nodejs\Dockerfile through a web browser, the persistent issue persisted, causing frustration and hindering progress.


Error Log:

curl: (6) Could not resolve host: nodejs.org

Solution:

To resolve this issue, follow these steps:

Inspect Dockerfile Path:

Confirm that the path to the Dockerfile (\docker\build\nodejs\Dockerfile) is correct and accessible. Ensure there are no typos or misconfigurations in the file path.

Check Docker Compose Settings:

Validate your Docker Compose settings. Specifically, ensure that the Docker Compose V2 option is not checked. Additionally, make sure that the "Use the WSL 2 based engine" option is checked in Docker Desktop.

Conclusion:

Addressing the "curl: (6) Could not resolve host: nodejs.org" error involves a careful examination of Docker Compose settings. By ensuring that Docker Compose V2 is unchecked and the WSL 2 based engine is selected in Docker Desktop, you can mitigate this issue and proceed with your headless setup seamlessly.

Note: This solution is based on the specific environment and conditions encountered. It is recommended to adapt these steps as needed, considering the unique aspects of your development setup.