Message Boards
Adding multi-language structured webcontents through headless API
Adding multi-language structured webcontents through headless API
Expert Posts: 396 Join Date: 8/22/07 Recent PostsHi guys,
On 7.2 I'm trying to add structured content with headless api. I created a structure "Client" with two text fields (Name and Surname).
I'm already able to insert new webcontents with:
POST http://localhost:8080/o/headless-delivery/v1.0/sites/20124/structured-contents/
Where the request body is:
{
"title": "Mary Shelley",
"contentStructureId": 38610,
"contentFields": [
{
"name": "Name",
"value": {
"data": "Mary"
}
},
{
"name": "Surname",
"value": {
"data": "Shelley"
}
}
]
}
Now I need to add multi-lingual content but I'm at a loss on how to do it, even if it seems to be supported by the API.
I've tried some variants like:
{
"title": "Joanne d'Arc",
"contentStructureId": 38610,
"contentFields": [
{
"name": "Name",
"value": {
"data": "Joanne"
},
"name": "Name_pt_PT",
"value": {
"data": "Joana"
}
},
{
"name": "Surname",
"value": {
"data": "d'Arc"
},
"name": "Surname_pt_PT",
"value": {
"data": "de Arc"
}
}
]
}
but the result is "Unable to get content field value for \"Name_pt_PT\" for content structure 38610".
Anybody out there has a cheat sheet for this? I couldn't find many examples...
TIA
Fernando
RE: Adding multi-language structured webcontents through headless API (Answer)
New Member Posts: 5 Join Date: 6/15/18 Recent PostsHello Fernando,
To add multilingual fields it is necessary to use the i18n properties. For example, if you have a localized title you should use title with the default language (or the one using in the accept-language header) and the rest you add it in the title_i18n like
{
...
"title": "The notebook"
"title_i18n": {
"es_ES": "El diario",
"fr_FR": "Le notebook"
},
...
}
If the multilingual content is inside a contentField you should use the data_i18n or similiar properties to add the localized values.
Hope this helps you and kudos to Javier de Arcos for the response.
Luismi
RE: RE: Adding multi-language structured webcontents through headless API
Expert Posts: 396 Join Date: 8/22/07 Recent PostsHi Luis Miguel,
WIth your help and a suggestion I also got from Javier Arcos on slack I managed to POST a multi-language web content. I'm currently trying to add an image and some categories but I'm getting nowhere.
I have a structure in place and I follow the JSON I get from a content inputed by hand, but it seems the images and categories are just being ignored, althoug the web content is being stored.
I'm POSTing to http://localhost:8080/o/headless-delivery/v1.0/sites/20124/structured-contents/ with a request body like:
{
"contentStructureId": 38734,
"dateCreated": "2020-11-01T06:00:00Z",
"dateModified": "2020-11-01T06:00:00Z",
"datePublished": "2020-11-01T06:00:00Z",
"siteId": 20124,
"title": "Investimento de 900 mil euros",
"title_i18n": {
"pt-PT": "Investimento de 900 mil euros",
"en-US": "Investimento de 900 mil euros"
},
"description": "Enim sapiente integer exercitation beatae ab platea eos.",
"description_i18n": {
"pt-PT": "Enim sapiente integer exercitation beatae ab platea eos.",
"en-US": "Enim sapiente integer exercitation beatae ab platea eos."
},
"contentFields": [
{
"dataType": "string",
"inputControl": "textarea",
"label": "PageContent",
"label_i18n": {
"en-US": "PageContent"
},
"name": "PageContent",
"nestedContentFields": [],
"repeatable": false,
"value": {
"data": "Com o intuito de promover a manutenção, cerca de 900 mil euros."
},
"value_i18n": {
"pt-PT": {
"data": "Com o intuito de promover a manutenção, cerca de 900 mil euros."
},
"en-US": {
"data": "Com o intuito de promover a manutenção, cerca de 900 mil euros."
}
}
},
{
"dataType": "image",
"label": "PageImage",
"label_i18n": {
"en-US": "PageImage"
},
"name": "PageImage",
"nestedContentFields": [],
"repeatable": false,
"value": {},
"value_i18n": {
"pt-PT": {
"image": {
"contentType": "Document",
"contentUrl": "/documents/20124/38878/cm187383b.jpg/a94237dd-7e2b-a555-bae2-a76a386ab289?t=1605130977583",
"description": "",
"encodingFormat": "image/jpeg",
"fileExtension": "jpg",
"id": 39158,
"sizeInBytes": 8411159,
"title": "cm187383b.jpg"
}
},
"en-US": {
"image": {
"contentType": "Document",
"contentUrl": "/documents/20124/38878/cm187383b.jpg/a94237dd-7e2b-a555-bae2-a76a386ab289?t=1605130977583",
"description": "",
"encodingFormat": "image/jpeg",
"fileExtension": "jpg",
"id": 39158,
"sizeInBytes": 8411159,
"title": "cm187383b.jpg"
}
}
}
}
],
"taxonomyCategories": [
{
"taxonomyCategoryId": 38762,
"taxonomyCategoryName": "Urbanismo",
"taxonomyCategoryName_i18n": {
"pt-PT": "Urbanismo",
"en-US": "Urbanismo"
}
}
]
}
The response I get from the server doesn't include neither the images nor the categories:
{
"actions": {
"subscribe": {
"method": "PUT",
"href": "http://localhost:8080/o/headless-delivery/v1.0/structured-content/{structuredContentId}/subscribe"
},
"unsubscribe": {
"method": "PUT",
"href": "http://localhost:8080/o/headless-delivery/v1.0/structured-content/{structuredContentId}/unsubscribe"
},
"get": {
"method": "GET",
"href": "http://localhost:8080/o/headless-delivery/v1.0/structured-contents/{structuredContentId}"
},
"replace": {
"method": "PUT",
"href": "http://localhost:8080/o/headless-delivery/v1.0/structured-contents/{structuredContentId}"
},
"update": {
"method": "PATCH",
"href": "http://localhost:8080/o/headless-delivery/v1.0/structured-contents/{structuredContentId}"
},
"get-template": {
"method": "GET",
"href": "http://localhost:8080/o/headless-delivery/v1.0/structured-contents/{structuredContentId}/rendered-content/{templateId}"
},
"delete": {
"method": "DELETE",
"href": "http://localhost:8080/o/headless-delivery/v1.0/structured-contents/{structuredContentId}"
}
},
"availableLanguages": [
"en-US",
"pt-PT"
],
"contentFields": [
{
"dataType": "string",
"inputControl": "textarea",
"label": "PageContent",
"name": "PageContent",
"nestedContentFields": [],
"repeatable": false,
"value": {
"data": "Com o intuito de promover a manutenção, cerca de 900 mil euros."
}
},
{
"dataType": "image",
"label": "PageImage",
"name": "PageImage",
"nestedContentFields": [],
"repeatable": false,
"value": {}
}
],
"contentStructureId": 38734,
"creator": {
"additionalName": "",
"contentType": "UserAccount",
"familyName": "Test",
"givenName": "Test",
"id": 20130,
"name": "Test Test",
"profileURL": "/web/test"
},
"customFields": [],
"dateCreated": "2020-11-12T00:14:49Z",
"dateModified": "2020-11-12T00:14:49Z",
"datePublished": "2020-11-01T06:00:00Z",
"description": "Enim sapiente integer exercitation beatae ab platea eos.",
"friendlyUrlPath": "investimento-de-900-mil-euros",
"id": 39285,
"key": "39283",
"keywords": [],
"numberOfComments": 0,
"relatedContents": [],
"renderedContents": [
{
"renderedContentURL": "http://localhost:8080/o/headless-delivery/v1.0/structured-contents/39285/rendered-content/39249",
"templateName": "NewsStory basic template"
}
],
"siteId": 20124,
"subscribed": false,
"taxonomyCategories": [],
"title": "Investimento de 900 mil euros",
"uuid": "e85f7271-c645-690c-35a7-00de30dff8af"
}
Any ideas?
I'm using DXP 7.2 SP2.
TIA
Fernando
RE: RE: Adding multi-language structured webcontents through headless API
New Member Posts: 9 Join Date: 7/16/20 Recent PostsTo provide the Taxonomy Categories you should add them as an array of their ids. If you take a look to the StructuredContent schema you will find it in the property taxonomyCategoryIds
StructuredContent:
description:
Represents content that has fields and is rendered by a template backed by a `ContentStructure`. This is
modeled internally as a `JournalArticle`.
properties:
...
taxonomyCategoryIds:
description:
A write-only field to add a category to this structured content.
items:
format: int64
type: integer
type: array
writeOnly: true
...
So you have to add them in your request like
"taxonomyCategoryIds":[38762]
In the case of the images, I guess the problem is you are not providing any value to the default language in the "value" property, like you are doing with the text area field. You should provide the english value in the "value" property and any other value in the "value_i18n" property. Try this and let me know
RE: Adding multi-language structured webcontents through headless API
Expert Posts: 396 Join Date: 8/22/07 Recent PostsThanks Javier, that did it! :-)
I think I'm still sending too much data but this POST works:
{
"contentStructureId": 38734,
"siteId": 20124,
"title": "Investimento de 900 mil euros",
"title_i18n": {
"pt-PT": "Investimento de 900 mil euros",
"en-US": "Investimento de 900 mil euros"
},
"description": "Enim sapiente integer exercitation beatae ab platea eos.",
"description_i18n": {
"pt-PT": "Enim sapiente integer exercitation beatae ab platea eos.",
"en-US": "Enim sapiente integer exercitation beatae ab platea eos."
},
"contentFields": [
{
"dataType": "string",
"inputControl": "textarea",
"label": "PageContent",
"label_i18n": {
"en-US": "PageContent"
},
"name": "PageContent",
"nestedContentFields": [],
"repeatable": false,
"value": {
"data": "Com o intuito de promover a manutenção, cerca de 900 mil euros."
},
"value_i18n": {
"pt-PT": {
"data": "Com o intuito de promover a manutenção, cerca de 900 mil euros."
},
"en-US": {
"data": "Com o intuito de promover a manutenção, cerca de 900 mil euros."
}
}
},
{
"dataType": "image",
"label": "PageImage",
"label_i18n": {
"en-US": "PageImage"
},
"name": "PageImage",
"nestedContentFields": [],
"repeatable": false,
"value": {
"image": {
"contentType": "Document",
"contentUrl": "/documents/20124/38878/cm187383b.jpg/a94237dd-7e2b-a555-bae2-a76a386ab289?t=1605130977583",
"description": "",
"encodingFormat": "image/jpeg",
"fileExtension": "jpg",
"id": 39158,
"sizeInBytes": 8411159,
"title": "cm187383b.jpg"
}
},
"value_i18n": {
"pt-PT": {
"image": {
"contentType": "Document",
"contentUrl": "/documents/20124/38878/cm187383b.jpg/a94237dd-7e2b-a555-bae2-a76a386ab289?t=1605130977583",
"description": "",
"encodingFormat": "image/jpeg",
"fileExtension": "jpg",
"id": 39158,
"sizeInBytes": 8411159,
"title": "cm187383b.jpg"
}
},
"en-US": {
"image": {
"contentType": "Document",
"contentUrl": "/documents/20124/38878/cm187383b.jpg/a94237dd-7e2b-a555-bae2-a76a386ab289?t=1605130977583",
"description": "",
"encodingFormat": "image/jpeg",
"fileExtension": "jpg",
"id": 39158,
"sizeInBytes": 8411159,
"title": "cm187383b.jpg"
}
}
}
}
],
"taxonomyCategoryIds":[38762]
}