Getting error while passing the content fragment path in the graphQL API end point | Community
Skip to main content
Level 2
April 11, 2024
Solved

Getting error while passing the content fragment path in the graphQL API end point

  • April 11, 2024
  • 3 replies
  • 1092 views

I have written graphQL Query to get the country data by path

 

Query : 

query getCountryData($path:ID!){
countryList(
filter:{
_path:{
_expressions:[{
value:$path
_operator:STARTS_WITH
}]
}
}

){
items{
countryName
countryCode
countryIsdCode
}
}
}

Request : 

{"path": "/content/dam/test/cf/country/en_UK/"}

API end point : 

http://localhost:4502/graphql/execute.json/sia/country;path=/content/dam/test/cf/country/en_UK/;

When I hit this end point  I'm getting error like the below

{"errors":[{"errorType":"ServletError","message":"Internal Servlet Failure","details":"Suffix: '/test/country/content/dam/test/cf/country/en_UK/' does not contain a path"}]}

 Do we have any solution for this

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by RikVanB

Hi Vignesh_K_S

 

Can you try to encode the path /content/dam/test/cf/country/en_UK? And add this as parameter value in your request. You can use this site to do it manually: https://www.urlencoder.org

 

That should make it work. I am assuming you'll use it in an application. If you do that they are functions that already exist that encode your values to pass it in your url. In JavaScript you can use the function encodeURIComponent, like mentioned in this topic: https://stackoverflow.com/questions/28915717/how-does-one-safely-pass-a-url-and-filename-as-part-of-a-query-string

3 replies

arunpatidar
Community Advisor
Community Advisor
April 11, 2024

Hi @vignesh_k_s 
The path does not look correct

/test/country/content/dam/test/content-fragment/country/en_UK/ 

 

It should be like /content/dam/test/content-fragment/country/en_UK/ 

Arun Patidar
Level 2
April 11, 2024

Yes, But in the request I'm passing the correct content fragment asset path 

/content/dam/test/cf/country/en_UK/. Internally it is trying to access the wrong path 

/test/country/content/dam/test/cf/country/en_UK/ 

 Can you please suggest how we can pass the asset path in graphQL API ?

arunpatidar
Community Advisor
Community Advisor
April 11, 2024
sravs
Community Advisor
Community Advisor
April 11, 2024

Hi @vignesh_k_s ,

 

In your query, it mentioned that the $path type as ID, try to change it to String and check as you are passing the string as a value. 

For more information refer https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/headless/graphql-api/content-fragments#graphql-variables

https://graphql.org/learn/queries/#variables

RikVanB
RikVanBAccepted solution
Level 2
April 11, 2024

Hi Vignesh_K_S

 

Can you try to encode the path /content/dam/test/cf/country/en_UK? And add this as parameter value in your request. You can use this site to do it manually: https://www.urlencoder.org

 

That should make it work. I am assuming you'll use it in an application. If you do that they are functions that already exist that encode your values to pass it in your url. In JavaScript you can use the function encodeURIComponent, like mentioned in this topic: https://stackoverflow.com/questions/28915717/how-does-one-safely-pass-a-url-and-filename-as-part-of-a-query-string