Expand my Community achievements bar.

SOLVED

Passing Params to Persisted Query Endpoint AEM GQL

Avatar

Level 5

I know that we can use POST method to make normal GQL query and perform GQL Ops but I wanted to know how can we achieve the same for persisted query, when I make a POST call with variables, I get an error:

spidey1405_0-1664458088163.png

 



When I copy URL which takes variables AEM gives URL which looks like this:

https://<DOMAIN>/graphql/execute.json/GetArticlesByID;filterExpressions=

 

and here's how my variable looks like:

 

{
  "filterExpressions": {"_logOp":"OR","_expressions":[{"value":"422322","_operator":"EQUALS"},{"value":"422321","_operator":"EQUALS"}]}
}

 

 

when I pass it directly in filterExpressions, it gives me error saying:

"Variable 'filterExpressions' has an invalid value : Expected type 'Map' but was 'String'. Variables for input objects must be an instance of type 'Map'."
 
I am not sure why endpoint is designed the the way it is? Is it possible to pass in params in get call as query params or does it have to be in some other way?
1 Accepted Solution

Avatar

Correct answer by
Level 5

I needed to encode my parameters using URIEncode after which it worked fine.

View solution in original post

5 Replies

Avatar

Community Advisor

You can pass the parameters like this

 

Query variables can be used with Persisted Queries. The query variables are appended to the request prefixed with a semicolon (;) using the variable name and value. Multiple variables are separated by semicolons.

The pattern looks like the following:

<AEM_HOST>/graphql/execute.json/<PERSISTENT_QUERY_PATH>;variable1=value1;variable2=value2
 

 Check the example given here

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap... 

Avatar

Correct answer by
Level 5

I needed to encode my parameters using URIEncode after which it worked fine.

Avatar

Level 1

Could you please provide the complete url (non-encoded and encoded)? Even after encoding, I still get the error.

Avatar

Level 2

Hey @spidey1405 @rakesh_h 

I'm having exactly the same issue, would be great if you can share more details if you resolved it.

Thanks

Avatar

Level 1

For me it works when I changed the url to 

https://<HOST>/graphql/execute.json/<GRAPHQL_ENDPOINT>/<PERSISTED_QUERY>%3B%2F%3Bid%3D123456%3Blocal%3Den
 
Note: My query started working after adding ;/ before variable declaration. 
......QUERY;/;variable1=value1;variable2=value2