Invalid date error when creating content with date field using APIs

Issue

  • When using the Liferay API to create Web Content with a date field, using the "dd-MM-yyyy'T'HH:mm:ss'Z'" format results in the display of an "Invalid date" error.

curl \
-H "Content-Type: application/json" \
-H 'Accept-Language: en-US' \
-X POST \
"http://localhost:8080/o/headless-delivery/v1.0/sites/${1}/structured-contents" \
-d "{\"contentFields\": [{\"contentFieldValue\": {\"data\": \"2023-04-20T00:00:00Z\"}, \"name\": \"Date91701211\"}], \"contentStructureId\": \"${2}\", \"title\": \"Test Article 1\"}" \
-u "test@liferay.com:test"

Environment

  • Liferay DXP 7.4

Resolution

  • To solve the "Invalid date" error, we should format the date field as "dd-MM-yyyy" without including the time. This will ensure that the date is recognized as a valid date and can be used in the Web Content.

curl \
-H "Content-Type: application/json" \
-H 'Accept-Language: en-US' \
-X POST \
"http://localhost:8080/o/headless-delivery/v1.0/sites/${1}/structured-contents" \
-d "{\"contentFields\": [{\"contentFieldValue\": {\"data\": \"2023-04-20\"}, \"name\": \"Date91701211\"}], \"contentStructureId\": \"${2}\", \"title\": \"Test Article 2\"}" \
-u "test@liferay.com:test"

Additional Information

 

Was this article helpful?
1 out of 1 found this helpful