Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

set cq:lastModified using curl command

Avatar

Level 2

How to set cq:lastModified (2018-02-21T15:24:18.000Z) using curl command for a particular page eg(http://localhost:4502/content/xyz/language/en-us/abc/pqr/jcr:content)

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@hello299 . You may use Sling Post Servlet to update properties by POST call to jcr:content path. You may import the below curl command(update auth headers if needed) into Postman and execute it for batch if required.

 

curl --location --request POST 'http://localhost:4502/content/xyz/language/en-us/abc/pqr/jcr:content' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'cq:lastModified=2018-05-11T11:45:03.673+05:30' \
--data-urlencode 'cq:lastModified@TypeHint=Date'

 

But there is an observation when you update cq:lastModified property via Sling Post, it updates the property back again to current modified timestamp. AFAIK, you have to do some custom script development for your correction and use that endpoint.

 

ResourceResolver resourceResolver = request.getResourceResolver();
Resource resource = resourceResolver .getResource("<pagepath>/jcr:content");
ModifiableValueMap modifiableValueMap = resource.adaptTo(ModifiableValueMap.class);
modifiableValueMap.put("cq:lastModified", <date value>);
resourceResolver.commit();

 

 

View solution in original post

6 Replies

Avatar

Correct answer by
Community Advisor

@hello299 . You may use Sling Post Servlet to update properties by POST call to jcr:content path. You may import the below curl command(update auth headers if needed) into Postman and execute it for batch if required.

 

curl --location --request POST 'http://localhost:4502/content/xyz/language/en-us/abc/pqr/jcr:content' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'cq:lastModified=2018-05-11T11:45:03.673+05:30' \
--data-urlencode 'cq:lastModified@TypeHint=Date'

 

But there is an observation when you update cq:lastModified property via Sling Post, it updates the property back again to current modified timestamp. AFAIK, you have to do some custom script development for your correction and use that endpoint.

 

ResourceResolver resourceResolver = request.getResourceResolver();
Resource resource = resourceResolver .getResource("<pagepath>/jcr:content");
ModifiableValueMap modifiableValueMap = resource.adaptTo(ModifiableValueMap.class);
modifiableValueMap.put("cq:lastModified", <date value>);
resourceResolver.commit();

 

 

Avatar

Community Advisor

Curl command to add a property to a page is 

     curl -u admin:admin -FnavRoot="true" http://localhost:4502/content/we-retail/us/en/jcr:content

Here navRoot is property name and true is the value.

 


Aanchal Sikka

Avatar

Community Advisor

@hello299 no you can't change internal properties such as modified or created dates using any commands or controls.. they are managed by AEM/Sling/JCR. May I know what's your requirement behind this? May be we can guide better..

Avatar

Employee Advisor

of course you can change cq:lastModified. It's nothing special about this property.

Avatar

Community Advisor

Hello @hello299 

 

You can use below CURL command to set cq:lastModified (2018-02-21T15:24:18.000Z) using curl command for a particular page.

 

curl -u admin:admin -X POST \
-H "Content-Type: application/json" \
-d '{"cq:lastModified": "2018-02-21T15:24:18.000Z"}' \
http://localhost:4502/content/we-retail/us/en/men/jcr:content