Custom webhook templates are network specific?

Solved
ksumann
Getting noticed

Custom webhook templates are network specific?

Hi everyone,

 

i wanted to create a custom template for a webhook. In the Dashboard its in ORGANISATION -> API and Webhooks.

After creating it, i noticed i couldn't use it in a network template because another network was selected while creating it.

 

I thought it would be available organisation wide, creating the template again for every network is pointless.

 

Greetings

1 Accepted Solution
MartinLL
Getting noticed

You need to use the API for it to be org wide.

 

Main: configure-meraki-custom-templates.py

 

 

#Import modules
import requests
import json
import os
import config
#API documentation for calls used in this script. 
#!! This API Call is in early access. Make sure to enable EA API access under organization -> Early Access.
#https://developer.cisco.com/meraki/api-latest/create-organization-webhooks-payload-template/
#set global vars
organizationId = config.orgid
apikey = os.environ.get("MERAKI_DASHBOARD_API_KEY")
headers = {
    "X-Cisco-Meraki-API-Key": apikey,
    "Content-Type":"application/json",
    "Accept":"application/json"
}
#open webhook template settings file and convert it to a python dictionary
with open ("templatesettings.json") as f:
    jsonfile = json.load(f)
#serialize python dict to json string for use in POST request
payload = json.dumps(jsonfile)

#generate post request to payloadTemplate URI and formats string with organizationId in configuration file.
try:
    url = "https://api.meraki.com/api/v1/organizations/{}/webhooks/payloadTemplates".format(organizationId)
    response = requests.request('POST', url , headers = headers, data = payload)
    print(response.status_code)
    print(response.text)
except requests.exceptions.HTTPError as err:
    raise SystemExit(err)

 

 

 config file: config.py

 

 

orgid = "<<insert org id>>"
#example orgid = "123456789"

 

 

Settings: templatesettings.json

 

 

{
    "name": "ServiceNow",
    "headers": [{
            "name": "Authorization",
            "template": "Basic {{ sharedSecret | base64_encode }}"
        },
        {
            "name": "Content-Type",
            "template": "application/json"
        },
        {
            "name": "Accept",
            "template": "*/*"
        },
        {
            "name": "Accept-Encoding",
            "template": "gzip, compress, br"
        }
    ],
    "body": "{\r\n\"version\": \"0.1\",\r\n\"sharedSecret\": \"{{sharedSecret}}\",\r\n\"sentAt\": \"{{sentAt}}\",\r\n\"organizationId\": \"{{organizationId}}\",\r\n\"organizationName\": \"{{organizationName}}\",\r\n\"organizationUrl\": \"{{organizationUrl}}\",\r\n\"networkId\": \"{{networkId}}\",\r\n\"networkName\": \"{{networkName}}\",\r\n\"networkUrl\": \"{{networkUrl}}\",\r\n\"networkTags\": {{ networkTags | jsonify }},\r\n\"deviceSerial\": \"{{deviceSerial}}\",\r\n\"deviceMac\": \"{{deviceMac}}\",\r\n\"deviceName\": \"{{deviceName}}\",\r\n\"deviceUrl\": \"{{deviceUrl}}\",\r\n\"deviceTags\": {{ deviceTags | jsonify }},\r\n\"deviceModel\": \"{{deviceModel}}\",\r\n\"alertId\": \"{{alertId}}\",\r\n\"alertType\": \"{{alertType}}\",\r\n\"alertTypeId\": \"{{alertTypeId}}\",\r\n\"alertLevel\": \"{{alertLevel}}\",\r\n\"occurredAt\": \"{{occurredAt}}\",\r\n\"alertData\": {{ alertData | jsonify }}\r\n}\r\n",
    "sharing": {
        "byNetwork": {
            "adminsCanModify": true,
            "ids": [
                null
            ],
            "withAll": true
        }
    }
}

 

 

Take a note of this part in the templatesettings.json part. No idea why its not in the GUI yet, but set this to true and you can use it org wide.

 

"sharing": {
        "byNetwork": {
            "adminsCanModify": true,
            "ids": [
                null
            ],
            "withAll": true <---
 
read me:

 

 

# cisco-meraki
Automation scripts for Cisco Meraki cloud networking
Go to https://developer.cisco.com/meraki/api-latest/overview/ for API documentation 
API calls used to find values and attributes needed in the different config files can be found there as well.

Custom Cisco Meraki scripts
All scripts are self contained and can be executed on their own as long as all requirements are installed.

Setup
Enable API access in your Meraki dashboard organization and obtain an API key (instructions).

Keep your API key safe and secure, as it is similar to a password for your dashboard. If publishing your Python code to a wider audience, please research secure handling of API keys.

Install the latest version of Python 3.

Install the requests module. pip3 install requests.

Usage
Export your API key as an environment variable, for example: export MERAKI_DASHBOARD_API_KEY=123456789asdfghjklasdasd
Alternatively, define your API key as a variable in your source code; this method is not recommended due to its inherent insecurity.

Update the config.py file with the organization ID and other settings you wish to include/add in the scripts

 

 

 

And please forgive the bad code... its just something i cobbeld together.

Also, this is for a service now integration. you might need to adjust some of the header settings in the templatesettings.json file.

 

To run this scrappy code you must get a bit familiar with python. But you should just be able to follow the readme and pile all the files somewhere in the same folder and run it.

View solution in original post

10 Replies 10
alemabrahao
Kind of a big deal
Kind of a big deal

"The HTTP Servers are network-scoped, so the payload templates followed the similar structure. That being said, we are looking at options for org-wide management but it may take some time. Until then, I would make use of Action Batches if you have to deploy these at scale. "

 

The original discussion.

 

Re: IN BETA: Webhook **Custom** Payload Templates - The Meraki Community

I am not a Cisco Meraki employee. My suggestions are based on documentation of Meraki best practices and day-to-day experience.

Please, if this post was useful, leave your kudos and mark it as solved.

Thanks, but later in the discussion:

"As an extra bonus, you will now be able to manage Webhook templates at the Organization level and share the templates across your networks. "

 

No, i can not use it across different networks, or even templates

alemabrahao
Kind of a big deal
Kind of a big deal

Have you opened a support case?

I am not a Cisco Meraki employee. My suggestions are based on documentation of Meraki best practices and day-to-day experience.

Please, if this post was useful, leave your kudos and mark it as solved.
sungod
Head in the Cloud

Custom templates are org-wide and can be shared by multiple networks, I use the this way.

 

Not sure why you are seeing a network to select when creating a template, that is not an option I see within the template editor.

 

Can you post a screenshot of your view in the editor? Otherwise as @alemabrahao says, open a case.

 

 

ksumann
Getting noticed

I have not opened a support case, but i will do if there is no other fix.

 

So here you see the network Test selected and a Teams_Test template created.

ksumann_0-1706116935822.png

 

Now, i want to use it in a different network, not there anymore

ksumann_1-1706117101554.png

 

 

and also not selectable in the networks alert section

ksumann_2-1706117239797.png

 

 

The Community post also says "Note, this is currently an API feature only". Doing some quick testing here I see I can create custom templates without associating them to a specific network. So perhaps it's API only like the comments alludes to and like creation can then only be bound to networks via API calls? Would have to test further.

MartinLL
Getting noticed

You need to use the API for it to be org wide.

 

Main: configure-meraki-custom-templates.py

 

 

#Import modules
import requests
import json
import os
import config
#API documentation for calls used in this script. 
#!! This API Call is in early access. Make sure to enable EA API access under organization -> Early Access.
#https://developer.cisco.com/meraki/api-latest/create-organization-webhooks-payload-template/
#set global vars
organizationId = config.orgid
apikey = os.environ.get("MERAKI_DASHBOARD_API_KEY")
headers = {
    "X-Cisco-Meraki-API-Key": apikey,
    "Content-Type":"application/json",
    "Accept":"application/json"
}
#open webhook template settings file and convert it to a python dictionary
with open ("templatesettings.json") as f:
    jsonfile = json.load(f)
#serialize python dict to json string for use in POST request
payload = json.dumps(jsonfile)

#generate post request to payloadTemplate URI and formats string with organizationId in configuration file.
try:
    url = "https://api.meraki.com/api/v1/organizations/{}/webhooks/payloadTemplates".format(organizationId)
    response = requests.request('POST', url , headers = headers, data = payload)
    print(response.status_code)
    print(response.text)
except requests.exceptions.HTTPError as err:
    raise SystemExit(err)

 

 

 config file: config.py

 

 

orgid = "<<insert org id>>"
#example orgid = "123456789"

 

 

Settings: templatesettings.json

 

 

{
    "name": "ServiceNow",
    "headers": [{
            "name": "Authorization",
            "template": "Basic {{ sharedSecret | base64_encode }}"
        },
        {
            "name": "Content-Type",
            "template": "application/json"
        },
        {
            "name": "Accept",
            "template": "*/*"
        },
        {
            "name": "Accept-Encoding",
            "template": "gzip, compress, br"
        }
    ],
    "body": "{\r\n\"version\": \"0.1\",\r\n\"sharedSecret\": \"{{sharedSecret}}\",\r\n\"sentAt\": \"{{sentAt}}\",\r\n\"organizationId\": \"{{organizationId}}\",\r\n\"organizationName\": \"{{organizationName}}\",\r\n\"organizationUrl\": \"{{organizationUrl}}\",\r\n\"networkId\": \"{{networkId}}\",\r\n\"networkName\": \"{{networkName}}\",\r\n\"networkUrl\": \"{{networkUrl}}\",\r\n\"networkTags\": {{ networkTags | jsonify }},\r\n\"deviceSerial\": \"{{deviceSerial}}\",\r\n\"deviceMac\": \"{{deviceMac}}\",\r\n\"deviceName\": \"{{deviceName}}\",\r\n\"deviceUrl\": \"{{deviceUrl}}\",\r\n\"deviceTags\": {{ deviceTags | jsonify }},\r\n\"deviceModel\": \"{{deviceModel}}\",\r\n\"alertId\": \"{{alertId}}\",\r\n\"alertType\": \"{{alertType}}\",\r\n\"alertTypeId\": \"{{alertTypeId}}\",\r\n\"alertLevel\": \"{{alertLevel}}\",\r\n\"occurredAt\": \"{{occurredAt}}\",\r\n\"alertData\": {{ alertData | jsonify }}\r\n}\r\n",
    "sharing": {
        "byNetwork": {
            "adminsCanModify": true,
            "ids": [
                null
            ],
            "withAll": true
        }
    }
}

 

 

Take a note of this part in the templatesettings.json part. No idea why its not in the GUI yet, but set this to true and you can use it org wide.

 

"sharing": {
        "byNetwork": {
            "adminsCanModify": true,
            "ids": [
                null
            ],
            "withAll": true <---
 
read me:

 

 

# cisco-meraki
Automation scripts for Cisco Meraki cloud networking
Go to https://developer.cisco.com/meraki/api-latest/overview/ for API documentation 
API calls used to find values and attributes needed in the different config files can be found there as well.

Custom Cisco Meraki scripts
All scripts are self contained and can be executed on their own as long as all requirements are installed.

Setup
Enable API access in your Meraki dashboard organization and obtain an API key (instructions).

Keep your API key safe and secure, as it is similar to a password for your dashboard. If publishing your Python code to a wider audience, please research secure handling of API keys.

Install the latest version of Python 3.

Install the requests module. pip3 install requests.

Usage
Export your API key as an environment variable, for example: export MERAKI_DASHBOARD_API_KEY=123456789asdfghjklasdasd
Alternatively, define your API key as a variable in your source code; this method is not recommended due to its inherent insecurity.

Update the config.py file with the organization ID and other settings you wish to include/add in the scripts

 

 

 

And please forgive the bad code... its just something i cobbeld together.

Also, this is for a service now integration. you might need to adjust some of the header settings in the templatesettings.json file.

 

To run this scrappy code you must get a bit familiar with python. But you should just be able to follow the readme and pile all the files somewhere in the same folder and run it.

ksumann
Getting noticed

Many thanks for the example code, i will try that out.

 

Maybe there should be a note in the dashboard that its currently only networkwide but you can use API instead.

 

Its absolutly confusing to have the setting in the organization menu, while its network specific.

 

 

Related question: if i create a receiver template, how do i use it in network -> alert? There is no field to select it.

First you need to configure the https server at the bottom of the alerts page, select your template and save the config. Then you go on the default recipients tab at the top and start typing webhook. Select your https receiver.

 

The alert settings apply to your template.

Thanks, this is really weird to use.
Adding it in Default Reciepients and clicking save will remove it from the default reciepients, but also leaves the webhook section empty. Only after reloading the whole page, the change is visible

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.