Fire webhook on enrollment

I would like to setup a cloudcode webbook to be triggered on user enrollment, but not quite sure how to set this up in the data model as the fields I need marked as ‘required’ namely ‘sessions’ or ‘enrollment’ are not explicit datamodel fields

Hi @martin

That is an interesting use-case / feature request but not currently possible unfortunately, please add that to our public roadmap [ability to trigger a webhook on successful enrollment]

In the meantime you will need to implement some kind of workaround. Without knowing exactly what your desired end result is I am going to have to make some assumptions and or just share what you can do in the interim.

Firstly, if your users are authenticating via SSO then you already have programmatic control over the enrollment process. Your idp_app_user_task in CloudCode is the thing that is allowing your users to be enrolled and can be extended with whatever custom code you want.

Device Identifier
What is important to note is that you may want to distinguish between a single user enrolling across multiple devices, and for that purpose we have exposed the unique deviceIdentifier in both the app runtime, as, and in the CloudCode idp_app_user_task as context.deviceIdentifier. The Device Identifier is also exposed in the Sessions API

So, depending on exactly what you want to happen you could do something like the following.

  1. In your Main View init() function create a value in the LocalDB to represent the first time you enroll. If the value already exists, don’t create it again. If it does not exist also create a corresponding object in the “real” DB and write both the Device ID and the User ID to that object for reference.
  2. Have this new DB object fire the webhook and trigger your CC task
  3. [OPTIONAL] Using the device and user IDs you can query the sessions API from CC and see if there are any “active” sessions for that user and device ID.
  4. [OPTIONAL] Keep track of all the sessions that you have “processed” through this CC task in the DB in a separate table
  5. [OPTIONAL] If you find an active session for the user and device that has not been “processed”, then process it in CC - executing whatever it is you want to happen in CC

I hope this helps