Creating Events (aka Alerts or Notifications)

Recap: What are Events?

Previously we looked at Event Types, these are templates describing the different types of insights/notifications a business might want to see. They describe the structure of what needs to be displayed as part of a given Event Type along with any placeholders (e.g. {{location}} or {{customerFirstName}}.

Events are the actual, literal alerts/notifications that flow into your Control Room.

So using the Event Type we created previously (Customer Flying), actual events would look something like this:

You can see this is based on the same Event Type we created earlier. But they contain actual information inside of the placeholders.

We can create Events in two ways, via UI or API. In some cases, it makes sense to allow users to post Events via a UI, in other (and most cases) it makes sense to stream events via APIs. We’ll walk you through both.

Creating Events - Using the interface

The Hero Regulator expects Pharmacies to register customers who take the Hero Flight potion and take flight successfully. In this case, Pharma’s simply open their Control Room and raise an alert within the system.

The process is quite straightforward:

  1. Open the Control Room you created in the previous step (Heroes Flying Potion - Real-time Monitoring)

  2. In the side panel, click ‘Post an Event’

  3. Select the Event Type we’d like to post to, in this case “Customer Flying”

  4. Fill in the placeholders with the actual location and name

  5. Post the event!

Now you can go into your Control Room and see the events in your event stream.

Here’s a quick visual walk through:

Creating Events - Using the API

The process is essentially the same. Instead of selecting Event Types from a list as we did previously, we need to reference our Event Type’s Unique Identifier.

Getting this is easy:

  1. Head over to ‘Manage Event Types’ in your Control Room

  2. Open the Event Type of interest (e.g. Customer Flying)

  3. Navigate to the ‘Event Type Schema’ tab

  4. Here you’ll find a bunch of useful information for developers, for example, the endpoint you can POST events to, as well as the schema to use when posting events

Here’s a visual walk through of how to get this:

Now we’re ready to make some calls and push events via API:

Creating Event - Flying Person Detected in Central Park

POST api.skyledge.com/event-types/{eventTypeIdentifier}/events

{  
   "dynamicAttributes":{  
      "location":"Central Park"
   },
   "location":{  
      "type":"Point",
      "coordinates":[  
         "-73.9752",
         "40.7687"
      ]
   }
}
curl --location --request POST 'https://api.skyledge.com/event-types/EVENT_TYPE_ID/events' \
--header 'X-Authorization: API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{  
   "dynamicAttributes":{  
      "location":"Central Park"
   },
   "location":{  
      "type":"Point",
      "coordinates":[  
         "-73.9752",
         "40.7687"
      ]
   }
}'

The output within the Sky Ledge control room should look like this:

When creating an event, it’s expected that an empty response is returned. If you consider situations such as streaming real-time data from an ioT device, it’s doesn’t make much sense to wait for the device to respond before setting up the event in our account

Creating Event - Customer Flying in Garment District

POST api.skyledge.com/event-types/{eventTypeIdentifier}/events

{  
   "dynamicAttributes":{
      "customerFirstName":"Harry",
      "location":"Garment District"
   },
   "location":{  
      "type":"Point",
      "coordinates":[  
         "-73.9951",
         "40.7541"
      ]
   }
}
curl --location --request POST 'https://api.skyledge.com/event-types/EVENT_TYPE_ID/events' \
--header 'X-Authorization: API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{  
   "dynamicAttributes":{
      "customerFirstName":"Harry",
      "location":"Garment District"
   },
   "location":{  
      "type":"Point",
      "coordinates":[  
         "-73.9951",
         "40.7541"
      ]
   }
}'

Your output on the platform in the control room, should look like the following:

Creating Event - Potion Ineffective on customer in Hell’s Kitchen

POST api.skyledge.com/event-types/{eventTypeIdentifier}/events

{  
   "dynamicAttributes":{  
      "location":"Garment District"
   },
   "location":{  
      "type":"Point",
      "coordinates":[  
         "-73.9951",
         "40.7541"
      ]
   }
}
curl --location --request POST 'https://api.skyledge.com/event-types/EVENT_TYPE_ID/events' \
--header 'X-Authorization: API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{  
   "dynamicAttributes":{  
      "location":"Garment District"
   },
   "location":{  
      "type":"Point",
      "coordinates":[  
         "-73.9951",
         "40.7541"
      ]
   }
}'

And last but not least, the potion ineffective event will look like this on our platform:

Special Powers - Creating Geofences

Here’s a little secret, developers have a lot more flexibility with the types of events they can generate. Instead of a simple marker, you could create Events that specify a geofence using simple GeoJSON, check this out:

Creating Event - Flying Limit Exceeded

POST api.skyledge.com/event-types/{eventTypeIdentifier}/events

{  
   "dynamicAttributes":{  
      "location":"Times Square"
   },
   "location":{  
      "type":"Polygon",
      "coordinates":[  
         [  
            [-73.9872, 40.7611],
            [-73.9923, 40.7543],
            [-73.9862, 40.7516],
            [-73.9811, 40.7586],
            [-73.9872, 40.7611]
         ]
      ]
   }
}
curl --location --request POST 'https://api.skyledge.com/event-types/EVENT_TYPE_ID/events' \
--header 'X-Authorization: API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{  
   "dynamicAttributes":{  
      "location":"Times Square"
   },
   "location":{  
      "type":"Polygon",
      "coordinates":[  
         [  
            [-73.9872, 40.7611],
            [-73.9923, 40.7543],
            [-73.9862, 40.7516],
            [-73.9811, 40.7586],
            [-73.9872, 40.7611]
         ]
      ]
   }
}'

There you have it! A geofence that helps us detect our flying person entering the prohibited airspace of Times Square!

Last updated