Try our conversational search powered by Generative AI!

How do you set the default DeliveryApiKey for a Content Recommendation Block?

Vote:
 

Hello, 

I am pretty new to Episerver development, and I am working with Content Recommendations. 

Right now I am trying to make it so every new Content Recommendations block by default will have the same delivery-source (if that makes sense). 
So we have a couple of widgets set up, and I'd like the block by default to be set to "Daily News", for example. 

In the SetDefaultValues() method, I've written: 
this.DeliveryAPIKey = "Daily News"; 
(as I'm not verified yet, I am unable to upload image of my code) :(

I am aware this is not correct, but I do not understand how I set this string to one of our delivery channels.
Is there a good way of doing this?

Thank you in advance :)

#246835
Jan 14, 2021 13:50
Vote:
 

 If you want to set the same value (e.g. Daily News) for each newly created block then set the properties to value under SetDefaultValues() method.

 public override void SetDefaultValues(ContentType contentType)
 {
            base.SetDefaultValues(contentType);
            this.DeliveryAPIKey = "Daily News"; 

 }

If you want to set a property value with the same name of the created block, then you can assign the Block/Page name in the property as below:

public virtual string DeliveryAPIKey => this.Name;

#246840
Jan 14, 2021 15:51
Vote:
 

I thought this was the proper way at first too, but it seems this property is set to some kind of ID.
When I am debugging and I attempt to get the value of this string, it shows the value in this image: https://imgur.com/h90i96v

This seems to be an ID for the delivery feed. 

It does actually work setting the DeliveryAPIKey value to this through the SetDefaultValues() method, and then the block will have the "Daily News" feed just fine. 
However, is this ID something that might change in the future?
I thought then it would be best to be able to retrieve this ID through code, as to not have any funny surprises if that happens. 

I have not found a way to do this yet, though. 

#246899
Jan 15, 2021 10:01
Vote:
 

The approach which you described will work when the page/block will load.

Another way we can update content through the scheduled job.

  • Create a scheduled job and fetch the blocks/pages e.g.NewsBlock.
  • Update the property value
  • Publish the content
 foreach (var block in allBlocks)
 {​​​​​​​
     var myBlock= block.CreateWritableClone<NewsBlock>();              
     myBlock.DelevriyApiKey= GetDeliveryKey(nameof(DeliveryKeyAPI));
      _contentRepository.Save(myBlock, SaveAction.Publish,AccessLevel.NoAccess);
  }​​​​​​​
  • Set the job interval time to update the content e.g. twice a day
#246921
Jan 15, 2021 12:44
Vote:
 

Thanks for sharing this!

#253351
Apr 16, 2021 10:49
Vote:
 

FIXED!

This is how you do it:

1. Find the API-key of the delivery you wish to use as your default. You'll find this in the Content Intelligence interface, under Engage -> Deliveries.

2. Put this key in, for example, your appsettings like so:

Keep in mind that this is NOT a replacement for your ApiToken that is used for the package in general, but as an extra custom value.

3. In your model or controller, retrieve the value like so:

4. Profit. That's it.

Now your block will use whatever delivery method you chose as the default one.

#253547
Apr 19, 2021 10:30
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.