You can configure the DeliveryClient
to retrieve either secured or unpublished content at one time.
For security reasons, the PreviewApiKey
and SecureAccessApiKey
key should be stored outside of the project file structure. It's recommended to use Secret Manager or Azure Key Vault to store sensitive data. Avoid using appsettings.json
for API keys.
To retrieve secured content, you need to create an instance of the IDeliveryClient
with a Secure API key. Each Kontent.ai environment has its own Secure API key.
IDeliveryClient client = DeliveryClientBuilder
.WithOptions(builder => builder
.WithEnvironmentId("<YOUR_ENVIRONMENT_ID>")
.UseProductionApi("<YOUR_SECURE_API_KEY>")
.Build())
.Build();
or set it to the IConfiguration
object using the Configuration["DeliveryOptions:SecureAccessApiKey"]
and Configuration["DeliveryOptions:UseSecureAccess"]
Configuration structure:
"DeliveryOptions": {
"UseSecureAccess": true,
"SecureAccessApiKey": "<YOUR_SECURE_API_KEY>"
}
Similarly, to retrieve unpublished content, you need to create an instance of the IDeliveryClient
with both Environment ID and Preview API key. Each Kontent.ai environment has its own Preview API key.
IDeliveryClient client = DeliveryClientBuilder
.WithOptions(builder => builder
.WithEnvironmentId("<YOUR_ENVIRONMENT_ID>")
.UsePreviewApi("<YOUR_PREVIEW_API_KEY>")
.Build())
.Build();
or set it to the IConfiguration
object using the Configuration["DeliveryOptions:PreviewApiKey"]
and Configuration["DeliveryOptions:UsePreviewApi"]
Configuration structure:
"DeliveryOptions": {
"UsePreviewApi": true,
"PreviewApiKey": "<YOUR_SECURE_API_KEY>"
}
Learn more about configuring content preview for your app and Kontent.ai environment.