The guide below shows the basic steps to publish content via SnapComms API using the 'Unplanned IT Outage' template found under IT Communications in the SnapComms Content Manager Template Library. More details on each of the APIs used and other available API endpoints are available in the Available SnapComms API article.
STEPS TO PUBLISH AN ALERT THROUGH API
The steps to publishing an alert using the SnapComms API can be grouped into two parts: Preparations in the Content Manager and Transacting Through API. The preparations in the Content Manager only need to be done at least once, in the beginning, then API transactions can be performed following the Rate Limits set.
Preparations in the Content Manager (Pre-requisites)
-
Turn on 'Enable Service Account Creation' from the Content Manager > Management > General Settings.
-
Navigate to Management > Administrators, click on 'Create Service Account' and assign a name for the Service Account.
-
Review the permissions set for the Service Account. Make sure that it has permissions to access the folder where your Organization Templates for API publishing are stored.
-
Take note of the API Key generated for the Service Account. This will be used later to trigger and authenticate to the APIs.
-
Create an Organization Template by clicking on the 'Create Content' button, choose a template from the Template Library or Build Your Own, assign a name for the template, click the down button next to 'Start', and click 'Start as Organization Template'. For this guide, we'll select the Unplanned IT Outage template.
-
Update the message in the template as necessary. In this example, the Organization Template was modified to have only one pre-defined field. The format for pre-defined fields in the template is '[::fieldname]'.The Targets may be predefined in the template or set to either groups or attributes when published through the SnapComms API.
API Transactions to Publish an Alert
-
Generate a Token: POST request to https://api.snapcomms.com/v1/auth/token
Request Header:
{ "x-tenant-id": "replace this value with the Organization ID from the Content Manager > Management > General Settings > Additional Settings", "x-api-key": "replace this with the API Key copied from the Service Account" }
-
Get all available Organization Templates: GET request to https://api.snapcomms.com/v1/content/template
Request Header:
{ "Authorization": "Bearer <token_value_from_previous_step>" }
-
Get specific Organization Template Details: GET request to https://api.snapcomms.com/v1/content/template/{id_value_of_template_from_previous_step}
Sample Request:
GET https://api.snapcomms.com/v1/content/template/{d23075c3-5ee0-47bc-aeeb-24ccf7ad5559}
Request Header:
{ "Authorization": "Bearer <token_value_from_previous_step>" }
-
(Optional) If there are no Targets defined on your template or you wish to send the message to a target set. To get available Groups for targeting: GET request to https://api.snapcomms.com/v1/targeting/group. For the list of available attributes: GET request to https://api.snapcomms.com/v1/targeting/attribute.
Request Header:
{ "Authorization": "Bearer <token_value_from_previous_step>" }
-
Publish a Content from the Organization Template: POST request to https://api.snapcomms.com/v1/content/publishFromTemplate. The "targets" block can be removed if you have the Targets predefined in your template and want to send the message to them. For this example, group-based targeting is used.
Request Header:
{ "Authorization": "Bearer <token_value_from_previous_step>" }
Request Body:
{ "templateId": "<place_org_template_id_from_previous>", "externalId": "<any_unique_external_id>", "durationInMinutes": 60, "startTime": "publish_time_in_UTC", "targets":[ { "type": "group", "id": "<replace_with_one_of_the_group_ids>" } ] "fields":[ { "name": "<name_of_predefined_field_from_org_template>", "value": "<value_of_the_field>" } ] }
Comments
0 commentsArticle is closed for comments.