AEM graphql enpoint call by UI app with query payload | Community
Skip to main content
Level 2
June 2, 2025
Solved

AEM graphql enpoint call by UI app with query payload

  • June 2, 2025
  • 1 reply
  • 1211 views

Hi Team,

 

My UI app team wants to pass complete grapql query with endpoint shared by AEM team as headless cf models.so that Ui app team can reduce or modify content based on query passed in POST

 

 

 

can passing query as payload or url param is recommended?

Best answer by AmitVishwakarma

Hi @amitvishwakarma 

 

Thanks connection issue is resolved in postman it is showing response.

 

Really appreciate for this help.

 

one more issue i have  - after passing the above query the response,it  should not return all the fields in response as in payload query,  we passed only id fields but i am getting all fields data in response. I am using persistent query with endpoint format - aemcloud.com/graphql/execute.json/

 

any thing needs to be changed so that response can come based on query payload passed in request? 


Hi @aem_leadi6 ,

You're using Persistent Queries (via /graphql/execute.json/...), which are precompiled on AEM, and do not consider the request payload’s query.

Instead, AEM only executes the query as stored in the persisted query file. So even if you pass a different query in the POST body, it won’t be used.

 

To make the response match your dynamic query payload, you must use the standard GraphQL endpoint, not the persistent one.

Option 1: Use Standard GraphQL Endpoint (Supports Custom Queries)

Use:

https://<your-domain>.aemcloud.com/graphql/<endpoint-name>

With POST body:

{ "query": "query { test41List { items { id } } }", "variables": {} }

1 reply

SantoshSai
Community Advisor
Community Advisor
June 2, 2025

Hi @aem_leadi6,

It is recommended and supported to call the GraphQL endpoint using a POST request with the query passed in the request body (payload). This is the best practice, especially when working with dynamic or complex queries in client applications like your UI app.

POST request with query in payload

This approach allows flexibility and aligns with how AEM's GraphQL APIs are designed.

Example:

Endpoint (AEM Publish):

https://your-aem-domain/graphql/endpoint-name

HTTP POST body:

{
  "query": "query { articleList { items { title description } } }"
}

Headers:

Content-Type: application/json

Not Recommended: Query in URL parameters (GET)

  • GraphQL GET requests with query strings are supported, but not recommended for:

    • Long or dynamic queries (may hit URL length limits).

    • Sensitive or authenticated requests.

    • Better caching strategies that POST enables with edge/CDN.

Hope that helps!

Santosh Sai
Level 2
June 3, 2025

Thanks @santoshsai  for your response with example .

 

I tried this but not it is showing internal servler error 500 .

 

I passed the query in postman body with json and form data both in the below format - 

{
  "query""query { test41List{ items { id } } }"
}
AmitVishwakarma
Community Advisor
AmitVishwakarmaCommunity AdvisorAccepted solution
Community Advisor
June 3, 2025

Hi @amitvishwakarma 

 

Thanks connection issue is resolved in postman it is showing response.

 

Really appreciate for this help.

 

one more issue i have  - after passing the above query the response,it  should not return all the fields in response as in payload query,  we passed only id fields but i am getting all fields data in response. I am using persistent query with endpoint format - aemcloud.com/graphql/execute.json/

 

any thing needs to be changed so that response can come based on query payload passed in request? 


Hi @aem_leadi6 ,

You're using Persistent Queries (via /graphql/execute.json/...), which are precompiled on AEM, and do not consider the request payload’s query.

Instead, AEM only executes the query as stored in the persisted query file. So even if you pass a different query in the POST body, it won’t be used.

 

To make the response match your dynamic query payload, you must use the standard GraphQL endpoint, not the persistent one.

Option 1: Use Standard GraphQL Endpoint (Supports Custom Queries)

Use:

https://<your-domain>.aemcloud.com/graphql/<endpoint-name>

With POST body:

{ "query": "query { test41List { items { id } } }", "variables": {} }