From 33c3109445dc942a81e31926c0fbb6b0ce1344b6 Mon Sep 17 00:00:00 2001 From: saminamhk Date: Wed, 13 Mar 2024 16:59:26 +0100 Subject: [PATCH] Updating the code because the initial one had error thrown because of the guidelines element --- .../importing_create_type.js | 131 +++++++++--------- 1 file changed, 67 insertions(+), 64 deletions(-) diff --git a/js/import-content-items/importing_create_type.js b/js/import-content-items/importing_create_type.js index bb684f31..cce09450 100644 --- a/js/import-content-items/importing_create_type.js +++ b/js/import-content-items/importing_create_type.js @@ -1,70 +1,73 @@ // Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript // Using ES6 syntax -import { ManagementClient, ElementModels } from '@kontent-ai/management-sdk'; +import { ManagementClient } from '@kontent-ai/management-sdk'; const client = new ManagementClient({ - environmentId: '', - apiKey: '' + environmentId: '', + apiKey: '' }); -const response = await client.addContentType() - .withData( - { - codename: "cafe", - name: "Cafe", - external_id: "cafe", - elements: [ - { - name: "Price per unit", - type: "number", - codename: "price_per_unit" - }, - { - guidelines: "

Keep Guidelines where the creative process happens.

\n

These are sample guidelines that you can place for the whole content item. It’s a place where you can include your content brief, voice and tone recommendations or the URL to a wireframe, so the author will have all the relevant instructions at hand before writing a single line.

\n

Besides overview guidelines, you can include instructions for each particular content element, as you will see below.

", - type: ElementModels.ElementType.guidelines, - codename: "n2f836bce_e062_b2cd_5265_f5c3be3aa6f5" - }, - { - name: "Street", - type: ElementModels.ElementType.text, - codename: "street" - }, - { - name: "City", - type: ElementModels.ElementType.text, - codename: "city" - }, - { - name: "Country", - type: ElementModels.ElementType.text, - codename: "country" - }, - { - name: "State", - type: ElementModels.ElementType.text, - codename: "state" - }, - { - name: "ZIP Code", - type: ElementModels.ElementType.text, - codename: "zip_code" - }, - { - name: "Phone", - type: ElementModels.ElementType.text, - codename: "phone" - }, - { - name: "Email", - type: ElementModels.ElementType.text, - codename: "email" - }, - { - name: "Photo", - type: ElementModels.ElementType.asset, - codename: "photo" - } - ] - } - ) - .toPromise(); +const response = await client + .addContentType() + .withData((builder) => { + return { + codename: 'cafe', + name: 'Cafe', + external_id: 'cafe', + elements: [ + builder.numberElement({ + name: 'Price per unit', + type: 'number', + codename: 'price_per_unit' + }), + builder.guidelinesElement({ + guidelines: + '

Keep Guidelines where the creative process happens.

\n

These are sample guidelines that you can place for the whole content item. It’s a place where you can include your content brief, voice and tone recommendations or the URL to a wireframe, so the author will have all the relevant instructions at hand before writing a single line.

\n

Besides overview guidelines, you can include instructions for each particular content element, as you will see below.

', + type: 'guidelines', + codename: 'n2f836bce_e062_b2cd_5265_f5c3be3aa6f5' + }), + builder.textElement({ + name: 'Street', + type: 'text', + codename: 'street' + }), + + builder.textElement({ + name: 'City', + type: 'text', + codename: 'city' + }), + builder.textElement({ + name: 'Country', + type: 'text', + codename: 'country' + }), + builder.textElement({ + name: 'State', + type: 'text', + codename: 'state' + }), + builder.textElement({ + name: 'ZIP Code', + type: 'text', + codename: 'zip_code' + }), + builder.textElement({ + name: 'Phone', + type: 'text', + codename: 'phone' + }), + builder.textElement({ + name: 'Email', + type: 'text', + codename: 'email' + }), + builder.assetElement({ + name: 'Photo', + type: 'asset', + codename: 'photo' + }) + ] + }; + }) + .toPromise(); \ No newline at end of file