[beginner] Curl command gives a 302 error instead of 200 response while trying to fetch content fragment and making changes | Community
Skip to main content
Level 2
January 23, 2025
Solved

[beginner] Curl command gives a 302 error instead of 200 response while trying to fetch content fragment and making changes

  • January 23, 2025
  • 3 replies
  • 799 views

I was trying get content fragment list using the following documentation.

Sites API

 

However it always throws a 302 error instead of 200. I have tried both /content/dam path and /api/assets path but it still does not work.

 

 

I am unable to use the curl command to make changes in the content fragment. 

 

Thanks in advance,

 

Best answer by narendiran_ravi

Here's how you can retrieve fragments using the (AEM) Sites API:


curl -i -X GET "http://localhost:4502/adobe/sites/cf/fragments?limit=1&path=/content/dam/&references=direct" -H "Authorization: Basic YWRtaW46YWRtaW4="

Use the API URL provided in the documentation - https://developer.adobe.com/experience-cloud/experience-manager-apis/api/stable/sites/ 

path: This parameter specifies the DAM path under which you want to search for fragments. Replace /content/dam/ with the desired path in your AEM instance.

3 replies

narendiran_ravi
narendiran_raviAccepted solution
Level 6
January 23, 2025

Here's how you can retrieve fragments using the (AEM) Sites API:


curl -i -X GET "http://localhost:4502/adobe/sites/cf/fragments?limit=1&path=/content/dam/&references=direct" -H "Authorization: Basic YWRtaW46YWRtaW4="

Use the API URL provided in the documentation - https://developer.adobe.com/experience-cloud/experience-manager-apis/api/stable/sites/ 

path: This parameter specifies the DAM path under which you want to search for fragments. Replace /content/dam/ with the desired path in your AEM instance.

Tethich
Community Advisor
Community Advisor
January 23, 2025

Hi @vashishth47 

 

I believe this is the default AEM behaviour. If you can see, in the response you have the Location header which has a value different then the one you requested. A trailing / appeared in the end. That is because AEM adds it and makes a redirect to it.

I believe is because of line 185-189 from here:
https://github.com/apache/sling-org-apache-sling-servlets-get/blob/master/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRenderer.java

 

And everything starts because your request is extensionless. If you add a .html in your cUrl, you should be able to get 200 HTTP response.

sarav_prakash
Community Advisor
Community Advisor
January 23, 2025

Here is a working example to use CF OpenAPI 

curl 'http://localhost:4502/adobe/sites/cf/fragments?limit=1&references=direct-hydrated&path=%2Fcontent%2Fdam%2Fsuppliercontent%2Fitems%2Ftest' \ -H 'Authorization: Basic YWRtaW46YWRtaW4='

error is coz your fetch url is incorrect. change as per example and should work.