Skip to content

Commit

Permalink
Updating the code because the initial one had error thrown because of…
Browse files Browse the repository at this point in the history
… the guidelines element
  • Loading branch information
saminamhk committed Mar 13, 2024
1 parent 5baa7e1 commit 33c3109
Showing 1 changed file with 67 additions and 64 deletions.
131 changes: 67 additions & 64 deletions js/import-content-items/importing_create_type.js
Original file line number Diff line number Diff line change
@@ -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: '<YOUR_ENVIRONMENT_ID>',
apiKey: '<YOUR_MANAGEMENT_API_KEY>'
environmentId: '<YOUR_ENVIRONMENT_ID>',
apiKey: '<YOUR_MANAGEMENT_API_KEY>'
});

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: "<h2>Keep Guidelines where the creative process happens.</h2>\n<p>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.</p>\n<p>Besides overview guidelines, you can include instructions for each particular content element, as you will see below.</p>",
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:
'<h2>Keep Guidelines where the creative process happens.</h2>\n<p>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.</p>\n<p>Besides overview guidelines, you can include instructions for each particular content element, as you will see below.</p>',
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();

0 comments on commit 33c3109

Please sign in to comment.