Cards in Microsoft Teams Notifications with action templates

In the previous post, I have explained how to configure SQLWATCH To send simple, plain text notifications to Microsoft Teams.

Today, we are going to look at how to send formatted cards:

SQLWATCH sqlwatch msteams card 09 04 2020 16 36
Microsoft Teams Cards

Action templates

Formatted cards require slightly more complex JSON structure and for that reason, we are going to create a new message template. SQLWATCH has always been designed with flexibility in mind. Adding a new message template is a very simple task:


declare @template varchar(max) = '{
    "@context": "",
    "@type": "MessageCard",
      "sections": [
            "facts": [
                    "name": "Check Staus:",
                    "value": "{CHECK_STATUS}"
                    "name": "Check Name:",
                    "value": "{CHECK_NAME}"
                    "name": "Host Name:",
                    "value": "{SQL_INSTANCE}"
            "text": "{CHECK_DESCRIPTION}"
    "summary": "Check Summary",
INSERT INTO [dbo].[sqlwatch_config_check_action_template]
           ('Microsoft Teams Card'
           ,'TEXT' )


The next step is to re-assign existing action to use the new template. In our case this is action_id=1 (as in the previous post) and action_template_id=1:

update [dbo].[sqlwatch_config_check_action]
set action_template_id = 1
where action_id = 1

The last step is to update the existing action_exec in [dbo].[sqlwatch_config_action] and only pass {BODY} as the entire payload formatting is now done in the template:

$webhookurl = "" 

Invoke-RestMethod `
    -Uri $webhookurl `
    -Method Post `
    -Body '{BODY}' `
    -ContentType 'application/json'

If you are using the original action from the previous post, you can simply update the action:

  UPDATE [dbo].[sqlwatch_config_action]
  SET action_exec = REPLACE(action_exec,'{"text":"{BODY}", "title":"{SUBJECT}"}','{BODY}')
  WHERE action_id = 1


That’s it. You are now going to receive formatted notifications and you are free to modify the card template to fit your purpose. If you are new to SQLWATCH please check our documentation and the getting started guide.

This post was originally published on 10th June 2020.


  1. SQLWATCH 7c0247ecd15445d1f9f130cdbabd7814?s=54&d=mm&r=g
    Upul 2nd March 2021 at 03:58 - Reply

    Hi, How do you pass values to the variables in the JSON template? for example, CHECK_NAME

Leave A Comment

Recent Posts