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
Conteúdo Excluesivo para Assinantes
Uma Subscrição do Liferay Enterprise fornece acesso a mais de 1.500 artigos que incluem práticas recomendadas, solução de problemas e outras soluções valiosas. Faça login para obter acesso completo.
Entrar