Adding structured-content through headless API (part2)
Adding structured-content through headless API (part2)
https://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=120450987
2024-03-29T00:04:26Z
2024-03-29T00:04:26Z
RE: RE: Adding structured-content through headless API (part2)
Jonathan HELL
https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=122456242
2024-03-08T15:36:59Z
2024-03-08T13:19:13Z
<p>Thank you Fernando, you answer helped me a lot.</p>
<p>I came across another issue giving me an error message "Invalid
available locales set for field name". For those wondering what
is going on, the structure you are using MUST be translated in order
for the API call to work. I don't know why but Liferay seems to check
if the structure locales match the contentFieldValue locales. I
doesn't make sense but it works.</p>
<p>So if you get the message "Invalid available locales set for
field name", be sure to:</p>
<ol>
<li>Send the correct Accept-Language header</li>
<li>Have translations available for the structure you are using (contentStructureId)</li>
</ol>
<p>Jonathan.</p>
Jonathan HELL
2024-03-08T13:19:13Z
RE: Adding structured-content through headless API (part2)
Fernando Fernandez
https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=120474625
2020-11-26T22:41:58Z
2020-11-26T22:41:58Z
<html><head></head><body><p>The problem was, finally, a bug on the handling of non US default
languages, but also the need of sending the Accept-languages header
with the default language selection.</p>
<p>This post works:</p>
<p> </p>
<pre><code class="language-javascript">{
"availableLanguages": ["en-US","pt-PT"],
"taxonomyCategoryIds":[40745],
"contentStructureId": 40463,
"siteId": 40428,
"title": "Lorem lacinia sed amet culpa integer",
"title_i18n": {
"pt-PT": "Rem cubilia, turpis eos",
"en-US": "Lorem lacinia sed amet culpa integer"
},
"description": "&lt;p&gt;Summary&lt;/p&gt;",
"description_i18n": {
"pt-PT": "&lt;p&gt;Sumário&lt;/p&gt;",
"en-US": "&lt;p&gt;Summary&lt;/p&gt;"
},
"contentFields": [
{
"contentFieldValue": { "data": "Lorem lacinia sed amet" },
"contentFieldValue_i18n": {
"pt-PT": {"data": "Rem cubilia, turpis eos"},
"en-US": {"data": "Lorem lacinia sed amet"}
},
"name": "Titulo"
},
{
"contentFieldValue": {"data": ""},
"contentFieldValue_i18n": {
"pt-PT": {"data": ""},
"en-US": {"data": ""}
},
"name": "Subtitulo"
},
{
"contentFieldValue": {"data": "2020-11-17T00:00:00Z"},
"contentFieldValue_i18n": {
"pt-PT": {"data": "2020-11-17T00:00:00Z"},
"en-US": {"data": "2020-11-17T00:00:00Z"}
},
"name": "Data"
},
{
"contentFieldValue": {
"image": {"id": 41239}
},
"contentFieldValue_i18n": {
"pt-PT": {"image": {"id": 41236}},
"en-US": {"image": {"id": 41239}}
},
"name": "Imagens"
},
{
"contentFieldValue": {
"data": "&lt;p&gt;Lorem lacinia sed amet.&lt;/p&gt;"
},
"contentFieldValue_i18n": {
"pt-PT": {"data": "&lt;p&gt;Rem cubilia, turpis eos! &lt;/p&gt;"},
"en-US": {"data": "&lt;p&gt;Lorem lacinia sed amet. /p&gt;"}
},
"name": "Corpo"
},
{
"contentFieldValue": {"data": ""},
"contentFieldValue_i18n": {
"pt-PT": {"data": ""},
"en-US": {"data": ""}
},
"name": "idVideo"
}
]
}</code></pre>
<p> </p>
<p>Hope this helps</p></body></html>
Fernando Fernandez
2020-11-26T22:41:58Z
RE: RE: Adding structured-content through headless API (part2)
Fernando Fernandez
https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=120452032
2020-11-16T11:18:06Z
2020-11-16T11:18:06Z
<p>Meanwhile, Javier, I've opened a ticket for your coleagues in
support. Just letting you know, so there's no double work.</p>
<p>Thanks</p>
<p> </p>
<p>Fernando</p>
Fernando Fernandez
2020-11-16T11:18:06Z
RE: RE: Adding structured-content through headless API (part2)
Fernando Fernandez
https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=120451932
2020-11-16T10:23:16Z
2020-11-16T10:23:16Z
<html><head></head><body><p>Hi Javier,</p>
<p>I've gone back to the intended config and tried again (so forget the
previous code), with the same result.</p>
<p>At this point:</p>
<ul>
<li>default language in portal-ext-properties is company.default.locale=pt_PT</li>
<li>default language for the instance (in control panel) is pt-PT,
with pt-PT and en-US available</li>
<li>default language for site is pt-PT with pt-PT and en-US available</li>
<li>default language for structure is pt_PT and pt_PT and en_US
available (struct source below)</li>
<li>both locales are being sent in i18n attributes on POST (see below)</li>
<li>I'm not sending the Accept-Language with the POST</li></ul>
<p>(I'm not sure what you mean by "the default language configured
in the Portal" so I'm assuming you're referring to the instance configuration)</p>
<p> </p>
<p>Thanks</p>
<p>Fernando</p>
<p> </p>
<p>Structure code:</p>
<pre><code class="language-javascript">{
"availableLanguageIds": [
"pt_PT",
"en_US"
],
"defaultLanguageId": "pt_PT",
"fields": [
{
"label": {
"pt_PT": "Titulo",
"en_US": "Title"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "string",
"indexType": "keyword",
"localizable": true,
"name": "Titulo",
"readOnly": false,
"repeatable": false,
"required": true,
"showLabel": true,
"type": "text"
},
{
"label": {
"pt_PT": "Subtitulo",
"en_US": "Subtitle"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "string",
"indexType": "keyword",
"localizable": true,
"name": "Subtitulo",
"readOnly": false,
"repeatable": false,
"required": false,
"showLabel": true,
"type": "text"
},
{
"label": {
"pt_PT": "Data",
"en_US": "Date"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "date",
"fieldNamespace": "ddm",
"indexType": "keyword",
"localizable": true,
"name": "Data",
"readOnly": false,
"repeatable": false,
"required": true,
"showLabel": true,
"type": "ddm-date"
},
{
"label": {
"pt_PT": "Imagens",
"en_US": "Images"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "image",
"fieldNamespace": "ddm",
"indexType": "text",
"localizable": true,
"name": "Imagens",
"readOnly": false,
"repeatable": true,
"required": false,
"showLabel": true,
"type": "ddm-image"
},
{
"label": {
"pt_PT": "Corpo notícia",
"en_US": "News Body"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "html",
"fieldNamespace": "ddm",
"indexType": "text",
"localizable": true,
"name": "HTMLj7zr",
"readOnly": false,
"repeatable": false,
"required": true,
"showLabel": true,
"type": "ddm-text-html"
},
{
"label": {
"pt_PT": "Link YouTube",
"en_US": "Link YouTube"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "string",
"indexType": "keyword",
"localizable": true,
"name": "idVideo",
"readOnly": false,
"repeatable": false,
"required": false,
"showLabel": true,
"type": "text"
}
]
}</code></pre>
<p> </p>
<p>POSTed data:</p>
<pre><code class="language-javascript">{
"siteId": 20124,
"contentStructureId": 69782,
"title": "Noticia Um",
"title_i18n": {
"pt-PT": "Noticia Um",
"en-US": "Noticia Um"
},
"description": "&lt;p&gt;Summary&lt;/p&gt;",
"description_i18n": {
"pt-PT": "&lt;p&gt;Sumário&lt;/p&gt;",
"en-US": "&lt;p&gt;Summary&lt;/p&gt;"
},
"contentFields": [
{
"name": "title",
"value": {
"data": "Story one"
},
"value_i18n": {
"pt-PT": {
"data": "Noticia Um"
},
"en-US": {
"data": "Story one"
}
}
},
{
"name": "subtitle",
"value": {
"data": ""
},
"value_i18n": {
"pt-PT": {
"data": ""
},
"en-US": {
"data": ""
}
}
},
{
"name": "newsDate",
"value": {
"data": "2020-11-14T00:00:00Z"
},
"value_i18n": {
"pt-PT": {
"data": "2020-11-14T00:00:00Z"
},
"en-US": {
"data": "2020-11-14T00:00:00Z"
}
}
},
{
"name": "HTMLj7zr",
"value": {
"data": "&lt;p&gt;Story Body&lt;/p&gt;"
},
"value_i18n": {
"pt-PT": {
"data": "&lt;p&gt;Corpo da notícia&lt;/p&gt;"
},
"en-US": {
"data": "&lt;p&gt;Story Body&lt;/p&gt;"
}
}
},
{
"name": "newsImg",
"value": {
"image": {
"id": 69726,
"description": "foto"
}
},
"value_i18n": {
"pt-PT": {
"image": {
"id": 69726,
"description": "foto"
}
},
"en-US": {
"image": {
"id": 69726,
"description": "foto"
}
}
}
}
]
}</code></pre>
<p> </p></body></html>
Fernando Fernandez
2020-11-16T10:23:16Z
RE: Adding structured-content through headless API (part2)
Javier De Arcos
https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=120451829
2020-11-16T09:03:50Z
2020-11-16T09:03:50Z
<p>The error description means that the content field "title"
is not getting all the locales it needs to update. It migth have more
languages and you have to add the remaining ones in the data_i18n
property, or it might need a different language than the one defined
in the Accept-Language header (or the default language configured in
the Portal if you are not setting the header).</p>
Javier De Arcos
2020-11-16T09:03:50Z
Adding structured-content through headless API (part2)
Fernando Fernandez
https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=120450986
2020-11-15T22:50:35Z
2020-11-15T22:50:35Z
<html><head></head><body><p>Hi guys,</p>
<p>Some days ago I posted here about a project we're working to migrate
sharepoint content to Liferay DXP SP2. The answers I got allowed me to
create a webcontent with a simple structure, multi-language, with an
image reference and categories.</p>
<p>Now I'm working with the structure the client really needs and I'm
having some strange problems with language fields. On my dev machine I
was getting error 400
"Validation error: Invalid available locales set for field name title"
and I had to reduce the structure to a en-US only structure on a clean
site to make uploads work. </p>
<p>Now I'm trying to make the processo work on the client's dev machine
and I'm not able to work around the same error.</p>
<p>My structure is like this:</p>
<pre><code class="language-javascript">{
"availableLanguageIds": [
"pt_PT",
"en_US"
],
"defaultLanguageId": "en_US",
"fields": [
{
"label": {
"pt_PT": "Título",
"en_US": "Title"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "string",
"indexType": "keyword",
"localizable": true,
"name": "title",
"readOnly": false,
"repeatable": false,
"required": true,
"showLabel": true,
"type": "text"
},
{
"label": {
"pt_PT": "Subtítulo",
"en_US": "Subtitle"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "string",
"indexType": "keyword",
"localizable": true,
"name": "subtitle",
"readOnly": false,
"repeatable": false,
"required": false,
"showLabel": true,
"type": "text"
},
{
"label": {
"pt_PT": "Data",
"en_US": "Date"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "date",
"fieldNamespace": "ddm",
"indexType": "keyword",
"localizable": true,
"name": "newsDate",
"readOnly": false,
"repeatable": false,
"required": true,
"showLabel": true,
"type": "ddm-date"
},
{
"label": {
"pt_PT": "Imagens",
"en_US": "Images"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "image",
"fieldNamespace": "ddm",
"indexType": "text",
"localizable": true,
"name": "newsImg",
"readOnly": false,
"repeatable": true,
"required": false,
"showLabel": true,
"type": "ddm-image"
},
{
"label": {
"pt_PT": "Corpo da notícia",
"en_US": "News Body"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "html",
"fieldNamespace": "ddm",
"indexType": "text",
"localizable": true,
"name": "HTMLj7zr",
"readOnly": false,
"repeatable": false,
"required": true,
"showLabel": true,
"type": "ddm-text-html"
},
{
"label": {
"pt_PT": "Link YouTube",
"en_US": "Link YouTube"
},
"predefinedValue": {
"pt_PT": "",
"en_US": ""
},
"style": {
"pt_PT": "",
"en_US": ""
},
"tip": {
"pt_PT": "",
"en_US": ""
},
"dataType": "string",
"indexType": "keyword",
"localizable": true,
"name": "idVideo",
"readOnly": false,
"repeatable": false,
"required": false,
"showLabel": true,
"type": "text"
}
]
}</code></pre>
<p> </p>
<p>As I wrote, I had to "downgrade" the structure to
single-language to get around the error on local dev environment. The
simpler structure looks like:</p>
<pre><code class="language-javascript">{
"availableLanguageIds": [
"en_US"
],
"defaultLanguageId": "en_US",
"fields": [
{
"label": {
"en_US": "Title"
},
"predefinedValue": {
"en_US": ""
},
"style": {
"en_US": ""
},
"tip": {
"en_US": ""
},
"dataType": "string",
"indexType": "keyword",
"localizable": true,
"name": "title",
"readOnly": false,
"repeatable": false,
"required": true,
"showLabel": true,
"type": "text"
},
{
"label": {
"en_US": "Subtitle"
},
"predefinedValue": {
"en_US": ""
},
"style": {
"en_US": ""
},
"tip": {
"en_US": ""
},
"dataType": "string",
"indexType": "keyword",
"localizable": true,
"name": "subtitle",
"readOnly": false,
"repeatable": false,
"required": false,
"showLabel": true,
"type": "text"
},
{
"label": {
"en_US": "Date"
},
"predefinedValue": {
"en_US": ""
},
"style": {
"en_US": ""
},
"tip": {
"en_US": ""
},
"dataType": "date",
"fieldNamespace": "ddm",
"indexType": "keyword",
"localizable": true,
"name": "newsDate",
"readOnly": false,
"repeatable": false,
"required": true,
"showLabel": true,
"type": "ddm-date"
},
{
"label": {
"en_US": "Images"
},
"predefinedValue": {
"en_US": ""
},
"style": {
"en_US": ""
},
"tip": {
"en_US": ""
},
"dataType": "image",
"fieldNamespace": "ddm",
"indexType": "text",
"localizable": true,
"name": "newsImg",
"readOnly": false,
"repeatable": true,
"required": false,
"showLabel": true,
"type": "ddm-image"
},
{
"label": {
"en_US": "News Body"
},
"predefinedValue": {
"en_US": ""
},
"style": {
"en_US": ""
},
"tip": {
"en_US": ""
},
"dataType": "html",
"fieldNamespace": "ddm",
"indexType": "text",
"localizable": true,
"name": "HTMLj7zr",
"readOnly": false,
"repeatable": false,
"required": true,
"showLabel": true,
"type": "ddm-text-html"
},
{
"label": {
"en_US": "Link YouTube"
},
"predefinedValue": {
"en_US": ""
},
"style": {
"en_US": ""
},
"tip": {
"en_US": ""
},
"dataType": "string",
"indexType": "keyword",
"localizable": true,
"name": "idVideo",
"readOnly": false,
"repeatable": false,
"required": false,
"showLabel": true,
"type": "text"
}
]
}</code></pre>
<p> </p>
<p>I'm using this endpoint:</p>
<pre><code>http://10.99.99.53:8080/o/headless-delivery/v1.0/sites/20124/structured-contents/</code></pre>
<p>And I'm sending this body:</p>
<pre><code class="language-javascript">{
"siteId": 20124,
"contentStructureId": 69782,
"title": "Noticia Dois",
"description": "&lt;p&gt;Summary&lt;/p&gt;",
"contentFields": [
{
"name": "title",
"value": {
"data": "Story one"
}
},
{
"name": "subtitle",
"value": {
"data": ""
}
},
{
"name": "newsDate",
"value": {
"data": "2020-11-14T00:00:00Z"
}
},
{
"name": "HTMLj7zr",
"value": {
"data": "&lt;p&gt;Story Body&lt;/p&gt;"
}
},
{
"name": "newsImg",
"value": {
"image": {
"id": 69726,
"description": "foto"
}
}
}
]
}</code></pre>
<p>Still I get:</p>
<pre><code class="language-javascript">{
"status": "BAD_REQUEST",
"title": "Validation error: Invalid available locales set for field name title"
}</code></pre>
<p