Use the Event Bus system to show alerts for when certain events occur in your DirectScale Platform. For example, an alert will send when a new enrollment occurs. There are multiple default events you can activate and custom event alerts you can create.
Sample WebHook Receiver Project
DirectScale has created a sample WebHook Receiver project available on GitHub. You can use this project to set up a service to receive events from the Bus. We’ve intentionally restricted the scope of this solution to basic functionality. The intent is to provide a starting point for you to use.
This sample project does not include:
- Authentication for loading the swagger page
- Logging
- A complete API versioning strategy
- Other elements typically accompanying a mature enterprise solution
Read more: View a sample WebHook Receiver on GitHub
Enabling an Event Alert
- Create a custom HTTP Endpoint that can receive the alert’s JSON data when it occurs. This endpoint is a URL to hit on a different server that will receive the message and then do something with it.
- Contact Customer Care and give them the HTTP Endpoint URL.
- Tell Customer Care which event alerts you’d like to receive. They will configure the system to send the alert information to that URL.
Note: You can add specific indicator configurations for Endpoint URLs for the different Platform environments (Live or Stage), allowing you to discern between the alerts from the different environments.
Default Events
📝 Parameter definitions:
OrderStatus
– “Paid”, “Pending Payment”, etc.OrderTypes
– Standard=1, AutoShip=2. Learn more about Order Types.ClientId
– Your company unique identifier found in your Admin URL ({Client_ID}.directscale.com
)AssociateId
vs.BackOfficeId
– Learn the difference in Understanding Platform IDsDistributorId
– Refers to the Associate’s numerical Associate ID (also known as the DirectScale ID).
CreateAssociateEvent and UpdateAssociateEvent
CreateAssociateEvent
sends when you create an Associate. UpdateAssociateEvent
sends when you update an Associate’s account. Both of these events share the same data model.
Parameters:
AssociateId
(int)Username
(string)FirstName
(string)LastName
(string)CompanyName
(string)EmailAddress
(string)AssociateStatus
(int)AssociateType
(int)WebAliases
(string[])BackOfficeId
(string)ExternalReferenceId
(string)EventDateUtc
(DateTime)
Example:
_businessEventService.PostBusinessEvent(new CreateAssociateEvent
{
AssociateId = associateId,
Username = username,
FirstName = firstName,
LastName = lastName,
CompanyName = companyName,
EmailAddress = emailAddress,
AssociateStatus = status,
AssociateType = type,
WebAliases = webAliases,
BackOfficeId = backOfficeId,
ExternalReferenceId = externalId
});
EnrollmentEvent
Sends any time a new customer or Associate is enrolled.
Parameters:
DistributorId
(string)DistributorType
(string)DistributorStatus
(string)DistributorCountry
(string)SponsorId
(string)EnrollmentDateUtc
(DateTime)EventDateUtc
(DateTime)
Example:
_businessEventService.PostBusinessEvent(new EnrollmentEvent
{
DistributorId = distId.ToString(),
EnrollmentDateUtc = application.SignupDate.ToUniversalTime(),
SponsorId = application.SponsorID.ToString(),
DistributorCountry = application.ApplicantAddress.CountryCode,
DistributorStatus = application.CustomerStatusId.ToString(),
DistributorType = application.AssociateBaseType.ToString()
});
CreateSubscriptionEvent and UpdateSubscriptionEvent
CreateSubscriptionEvent
sends when an Associate creates a new Subscription, while UpdateSubscriptionEvent
sends when a Subscription is updated. Both events share the same data model.
Parameters:
AssociateId
(int)SubscriptionId
(int)SubscriptionName
(string)IsVoid
(bool)EventDateUtc
(DateTime)
Example:
_businessEventService.PostBusinessEvent(new CreateSubscriptionEvent
{
AssociateId = associateId,
BackOfficeId = backOfficeId,
SubscriptionId = subscriptionId,
SubscriptionName = subscriptionName,
ExpirationDateUtc = DateTime.Now,
IsVoid = false
});
OrderEvent
Sends when a customer or Associate creates an order, including AutoShip and incidental orders.
Parameters:
OrderId
(string)OrderDateUtc
(DateTime)DistributorId
(string)OrderType
(string)OrderTotal
(double)OrderCountry
(string)OrderCurrency
(string)OrderStatus
(string)EventDateUtc
(DateTime)
Example:
_businessEventService.PostBusinessEvent(new OrderEvent
{
DistributorId = order.DistributorID.ToString(),
OrderDateUtc = DateTime.UtcNow,
OrderId = orderNumber.ToString(),
ClientId = clientId,
OrderCountry = order.ShipAddress.CountryCode,
OrderCurrency = order.CurrencyCode,
OrderStatus = payResult.Status.ToString(),
OrderTotal = (decimal)payResult.Amount,
OrderType = order.OrderType.ToString()
});
StockLevelEvent
Sends when an inventory item stock status changes (either in-stock to out-of-stock, or out-of-stock to in-stock).
Parameters:
ItemID
(int)WarehouseID
(int)Available
(double)Status
(string)StatusIndex
(int)EventDateUtc
(DateTime)
Examples:
_businessEventService.PostBusinessEvent(new StockLevelEvent
{
ItemID: 7901
WarehouseID: 2
Available: 188
Status: "In Stock"
StatusIndex: 3
});
_businessEventService.PostBusinessEvent(new StockLevelEvent
{
ItemID: 7901
WarehouseID: 2
Available: 3
Status: "Low on Stock"
StatusIndex: 2
});
_businessEventService.PostBusinessEvent(new StockLevelEvent
{
ItemID: 7901
WarehouseID: 2
Available: 0
Status: "Out of Stock"
StatusIndex: 1
});
Creating Custom Events
You can create custom events with the ClientEvent
alert.
-
Initiate the service and send the custom client event:
var service = new BusinessEventService(); service.PostBusinessEvent(new CoolNewCustomCompanyEvent { EventProperty1 = "The first thing", EventProperty2 = 42, EventProperty3 = true, EventProperty4 = { "CoolData": "Hello" } });
-
To create a custom event, replace the
EventProperty{#}
with your data of any type:private class CoolNewCustomCompanyEvent : ClientEvent { public string EventProperty1 { get; set; } public int EventProperty2 { get; set; } public bool EventProperty3 { get; set; } Public Dictionary<string, object> EventProperty4 { get; set; } }
Comments
Please sign in to leave a comment.