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

No comments:

Post a Comment