Vous pouvez utiliser l’API Submit de deux manières: obtenir des versions publiées des éléments de contenu ou prévisualiser leurs versions non publiées. Dans tous les cas, vous utilisez les mêmes méthodes de demande de données, mais avec une URL de base différente.

Rappeler publié Éléments de contenu de votre projet avec le production URL:
https://deliver.kontent.ai/<YOUR_PROJECT_ID>/items

Aperçu inédit Éléments de contenu de votre projet avec le Aperçu URL:
https://preview-deliver.kontent.ai/<YOUR_PROJECT_ID>/items

Si vous souhaitez afficher un aperçu du contenu non publié dans votre projet, vous devez autoriser votre demande.

// Tip: Find more about JS/TS SDKs at https://docs.kontent.ai/javascript const KontentDelivery = require('@kentico/kontent-delivery');   const deliveryClient = new KontentDelivery.DeliveryClient({ projectId: '<YOUR_PROJECT_ID>', previewApiKey: '<YOUR_PREVIEW_API_KEY>', globalQueryConfig: { usePreviewMode: true, // Queries the Delivery Preview API. }, typeResolvers: [ // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models new KontentDelivery.TypeResolver('article', (rawData) => new Article) ] });   deliveryClient.item('my_article') .toObservable() .subscribe(response => console.log(response));

// Tip: Find more about JS/TS SDKs at https://docs.kontent.ai/javascript import { ContentItem, DeliveryClient, Elements, TypeResolver } from '@kentico/kontent-delivery';   // Create strongly typed models according to https://docs.kontent.ai/tutorials/develop-apps/get-content/using-strongly-typed-models export class Article extends ContentItem { public title: Elements.TextElement; public summary: Elements.TextElement; public post_date: Elements.DateTimeElement; public teaser_image: Elements.AssetsElement; public related_articles: Article[]; }   const deliveryClient = new DeliveryClient({ projectId: '<YOUR_PROJECT_ID>', previewApiKey: '<YOUR_PREVIEW_API_KEY>', globalQueryConfig: { usePreviewMode: true, // Queries the Delivery Preview API. }, typeResolvers: [ new TypeResolver('article', (rawData) => new Article) ] });   deliveryClient.item<Article>('on_roasts') .toObservable() .subscribe(response => console.log(response));

// Tip: Find more about .NET SDKs at https://docs.kontent.ai/net using Kentico.Kontent.Delivery;   // Initializes a delivery client for previewing content IDeliveryClient client = DeliveryClientBuilder .WithOptions(builder => builder .WithProjectId("<YOUR_PROJECT_ID>") .UsePreviewApi("<YOUR_PREVIEW_API_KEY>") .Build()) .Build();   // Generate strongly typed models via https://github.com/Kentico/kontent-generators-net IDeliveryItemResponse<Article> response = await client.GetItemAsync<Article>("my_article"); Article item = response.Item;

// Tip: Find more about PHP SDKs at https://docs.kontent.ai/php // Defined by Composer to include required libraries require __DIR__ . '/vendor/autoload.php';   use KenticoKontentDeliveryDeliveryClient;   $client = new DeliveryClient('<YOUR_PROJECT_ID>', '<YOUR_PREVIEW_API_KEY>');   $item = $client->getItem('my_article');

// Tip: Find more about Java SDK at https://docs.kontent.ai/java import kentico.kontent.delivery.*;   // Initializes a Delivery client for preview DeliveryClient client = new DeliveryClient( DeliveryOptions.builder() .projectId("<YOUR_PROJECT_ID>") .previewApiKey("<YOUR_PREVIEW_API_KEY>") .usePreviewApi(true) .build() );   // Registers the model class for articles // Tip: Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models client.registerType(Article.class);   // Gets an article CompletionStage<Article> article = client.getItem("my_article", Article.class); // To use the code for Android projects, see http://docs.kontent.ai/android

# Tip: Find more about Ruby SDKs at https://docs.kontent.ai/ruby require 'delivery-sdk-ruby'   delivery_client = Kentico::Kontent::Delivery::DeliveryClient.new project_id: '<YOUR_PROJECT_ID>', preview_key: '<YOUR_PREVIEW_API_KEY>' delivery_client.item('my_article').execute do |response| puts response.to_s end

// Tip: Find more about Swift SDK at https://docs.kontent.ai/ios import KenticoKontentDelivery   let client = DeliveryClient.init(projectId: "<YOUR_PROJECT_ID>", apiKey: "<YOUR_PREVIEW_API_KEY>")   // More about strongly-typed models https://github.com/Kentico/kontent-delivery-sdk-swift#using-strongly-typed-models client.getItem(modelType: Article.self, itemName: "my_article") { (isSuccess, itemResponse, error) in if isSuccess { if let article = itemResponse.item { // Use your item here } } else { if let error = error { print(error) } } }

curl --request GET --url https://preview-deliver.kontent.ai/<YOUR_PROJECT_ID>/items/my_article --header 'authorization: Bearer <YOUR_PREVIEW_API_KEY>'

Pour l’API Delivery Preview, vous pouvez utiliser deux clés API simultanées, principale et secondaire. Pour plus d’informations sur l’utilisation des touches et la prévisualisation du contenu dans son ensemble, voir Configurer l’aperçu des éléments.



Source link

Recent Posts