Skip to content

Commit

Permalink
Update import_rich_upsert_variant.js
Browse files Browse the repository at this point in the history
  • Loading branch information
saminamhk committed Mar 14, 2024
1 parent c203cb2 commit cc21064
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions js/import-rich-text/import_rich_upsert_variant.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,46 @@
import { ManagementClient } from '@kontent-ai/management-sdk';

const client = new ManagementClient({
environmentId: '<YOUR_ENVIRONMENT_ID>',
apiKey: '<YOUR_API_KEY>'
environmentId: '<YOUR_ENVIRONMENT_ID>',
apiKey: '<YOUR_API_KEY>'
});

const response = await client.upsertLanguageVariant()
.byItemExternalId('simple-example')
.byLanguageId('00000000-0000-0000-0000-000000000000')
.withElements([
{
element: {
external_id: "rich-text"
},
value: "<h1>Lorem Ipsum</h1>\n<p>Lorem ipsum dolor sit amet, consectetur <a href=\"https://wikipedia.org\">adipiscing elit</a>, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n<object type=\"application/kenticocloud\" data-type=\"component\" data-id=\"a2ee7bac-15ff-4dce-a244-012b9f98dd7b\"></object>\n<p>Ut enim ad minim veniam, <a data-item-external-id=\"second-page\">quis nostrud</a> exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>\n<ul>\n <li>Lorem ipsum dolor sit amet</li>\n <li>Consectetur adipiscing elit</li>\n <li>Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</li>\n</ul><figure data-asset-external-id=\"rich-text-asset\"></figure>",
components: [
{
id: "a2ee7bac-15ff-4dce-a244-012b9f98dd7b",
type: {
external_id: "button"
},
elements: [
{
element: {
external_id:"button-text"
},
value: "Buy me"
},
{
element: {
external_id: "button-link"
},
value: "https://kontent.ai"
},
]
}
]
}
])
.toPromise();
const response = await client
.upsertLanguageVariant()
.byItemExternalId('simple-example')
.byLanguageId('00000000-0000-0000-0000-000000000000')
.withData((builder) => {
return {
elements: [
builder.richTextElement({
element: {
external_id: 'rich-text'
},
value: '<h1>Lorem Ipsum</h1>\n<p>Lorem ipsum dolor sit amet, consectetur <a href="https://wikipedia.org">adipiscing elit</a>, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n<object type="application/kenticocloud" data-type="component" data-id="a2ee7bac-15ff-4dce-a244-012b9f98dd7b"></object>\n<p>Ut enim ad minim veniam, <a data-item-external-id="second-page">quis nostrud</a> exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>\n<ul>\n <li>Lorem ipsum dolor sit amet</li>\n <li>Consectetur adipiscing elit</li>\n <li>Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</li>\n</ul><figure data-asset-external-id="rich-text-asset"></figure>',
components: [
{
id: 'a2ee7bac-15ff-4dce-a244-012b9f98dd7b',
type: {
external_id: 'button'
},
elements: [
{
element: {
external_id: 'button-text'
},
value: 'Buy me'
},
{
element: {
external_id: 'button-link'
},
value: 'https://kontent.ai'
}
]
}
]
})
]
};
})
.toPromise();

0 comments on commit cc21064

Please sign in to comment.