Expand my Community achievements bar.

SOLVED

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

Avatar

Level 1

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.

 

 
Screenshot 2025-01-23 162541.png

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

 

Thanks in advance,

 

1 Accepted Solution

Avatar

Correct answer by
Level 7

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.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 7

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.

Avatar

Level 9

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/s...

 

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.

Avatar

Level 8

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='

sarav_prakash_0-1737662327151.png

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