set cq:lastModified using curl command | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ShubhanshuSi2

@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();

 

 

4 replies

ShubhanshuSi2Community AdvisorAccepted solution
Community Advisor
June 16, 2023

@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();

 

 

aanchal-sikka
Community Advisor
Community Advisor
June 17, 2023

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
Shashi_Mulugu
Community Advisor
Community Advisor
June 18, 2023

@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..

joerghoh
Adobe Employee
Adobe Employee
June 18, 2023

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

Tanika02
Level 7
June 18, 2023

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