Custom application subscriptions returns NullPointerException

Hi

I have custom application type with custom content.

I implemented ISubscribableContentType

public bool CanSubscribe(Guid contentId, int userId) {
            return true;
        }

        public bool CanDeleteSubscription(Guid contentId, int subscribedUserId, int userId) {
            return true;

        }

        public bool SupportsSubscriptions => true;



But then I call Apis.Get<IApplicationSubscriptions>()
.Create(Guid.Parse("21BB7313-F73A-419B-B860-0CFC6E901885"), Guid.Parse("00f28038-aa20-5c2b-9f80-cb16f194c6f4"))

I recive NullPointerException in result's errors. 
Same with $core_v2_applicationSubscription.Create($applicationId, $applicationTypeId, "%{}"))


App of course exists and correctly retrives from internal calls from my services.
While debugging I found that issue comes from stored procedure te_Content_Content_Get - it checks application from te_Content_Contents and it absent.

Can someone suggest what should I do with that?



Parents
  • Found solution:

    I have to call

    Services.Get<IContentService>().EnsureExists(newApp);

    after app created. Still don't know how it should works automatically, but that call helps to add required row into te_Content_Contents table.
    Also should have that field with "this" value

    newApp.Application = this
  • Usage of non-extensible services should be avoided. How/when are you calling the subscription Create method? It seems to be before the content in question has been created. The ApplicationSubscription API itself handles ensuring the content record is created, assuming the specific content in question exists.

    A good candidate location for an automatic subscription creation would be in a handler for the Apis.Get<IContents>().Events.AfterCreate event, for instance to subscribe the author/creator user to the created application instance.

    Another possibility would be to create an Automation to subscribe certain users automatically.

    If you are still having trouble, could you share the full exception with stack trace?

  • Actually I don't need to subscribe author. 
    But then user try to subscribe application by rest/script API - it throw an error.

    As I understand there are no auto-created raws in that table only like that EnsureExists, but script-api subscribe flow only checks that table but not creates.

Reply Children