Try our conversational search powered by Generative AI!

Service API not resulting in content events



As with Content Events (Commerce 10) and Service API (3) | Optimizely Dev we are using the Service API to update the catalog in Optimizely. This works fine, but we have hooked into IContentEvents, more specifically we are using PublishedContent, DeletedContent and MovedContent, but none of these events are fired, when the catalog is updated via Service API. We are running Commerce 13.31 and Service APi 5.5.1 and from the post, I mention above, it should work when using Service API 5.2 and later?

Mar 03, 2022 6:34

How do you setup Service API (on the same site or on a separate site), and how do you listen to events?

Mar 03, 2022 14:03

We are running the Service API on the same site and we listen to the events like this. It works fine when we do "manually" updates in the catalog.

[ServiceConfiguration(typeof(ContentEventIndexMediator), Lifecycle = ServiceInstanceScope.Singleton)]
public class ContentEventIndexMediator
        private readonly IContentEvents _contentEvents;
        private readonly ISettingsService _settingsService;

        public ContentEventIndexMediator(
            IContentEvents contentEvents,
            ISettingsService settingsService)
            _contentEvents = contentEvents;
            _settingsService = settingsService;

        public void AddContentEvents()
            bool indexingIsEnabled = _settingsService.GetSettingAsBool("indexing:enable-content-events");
            if (indexingIsEnabled)
                _contentEvents.PublishedContent += UpdateIndex;
                _contentEvents.DeletedContent += DeleteFromIndex;
                _contentEvents.MovedContent += MovedContent;

            _contentSecurityRepository.ContentSecuritySaved += UpdateIndex;
Edited, Mar 04, 2022 6:08

Yes it should fire content events. I'm not sure why it does not in your case. please reach out to developer support service for further assistance. 

Mar 04, 2022 14:11

Optimizely Support wrote the following, hence the conclusion is, that we should use the same approach as in Content Events (Commerce 10) and Service API (3) | Optimizely Dev, meaning we should use EventContext.EntryUpdated.

When using bulk import with XML file, it would be the same when you import catalog in Commerce Manager
Service API just is a wrapper in this case, and as it's the legacy system Commerce Manager, we don't change it to use IContentRepository
About the changes in Service API 5.2, it's actually for Get, Post, Put, Delete API not for the import

Mar 18, 2022 8:19

Yeah if you were using the catalog import API then it's (Still) only low level events. Only when you use the CRUD APIs, content events can be used.

Mar 18, 2022 9:05
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.