Manually update Headless item Field
I have content type article on headless channel. I want to update headless item field called LikeCount. it's possible to create an endpoint to update the headless data ?
I tried to create like this Update Content Item
but, using IHeadlessItemManager (.TryUpdateDraft) to update the field. when debugging is okay, but the field not updated. what the best practice to update field on content type headless ?
Environment
- Xperience by Kentico version: [30.0.1]
- .NET version: [8]
- Execution environment: [SaaS]
Answers
The link you shared it broken. It would be helpful if you provided some examples code.
this is the reference link https://docs.kentico.com/api/content-management/content-items#update-content-item-drafts
var blogQuery =
await _webPageRetriever.HejazRetrieve<BlogModel>(
BlogModel.CONTENT_TYPE_NAME,
parameters =>
{
parameters.Where(where => where.WhereEquals(nameof(BlogModel.UrlPath), request.UrlPath));
});
if (blogQuery == null)
{
return Models.Result<bool>.NotFound(
$"Blog with url path {request.UrlPath} not found");
}
ContentItemData updatedBlogContentItem = new ContentItemData(new Dictionary<string, object>{
{
"LikeCount", blogQuery.LikeCount + 1
},
});
await _headlessItemManager.TryUpdateDraft(
3060,
"en",
updatedBlogContentItem,
cancellationToken);
blogQuery is data from headless Item, _headlessItemManager is depedency from IHeadlessItemManager
The item manager APIs require being constructed via a factory where you supply the current user ID.
In your case you should be injecting IHeadlessItemManagerFactory
and use it to create a new IHeadlessItemManager
.
Note that IHeadlessItemManagerFactory
and IHeadlessItemManager
are in an .Internal
namespace, which means even though they are public
we can make breaking changes to them at any time.
If you would like to see improved support for programmatic management of headless channels, give us some feedback on our roadmap.
To answer this question, you have to login first.