Hello @RichB,
Are you talking about this endpoint : https://developer.cisco.com/meraki/api-v1/#!get-network-appliance-firewall-l-7-firewall-rules ?
If yes, here is a working script using your payload (note the json.dumps() for the payload):
Code
import requests
import json
import yaml
# Open the config.yml file and load its contents into the 'config' variable
with open('config.yml', 'r') as file:
config = yaml.safe_load(file)
# New rules to be created
newRules = {'rules': [{'policy': 'deny', 'type': 'application', 'value': {'id': 'meraki:layer7/application/101', 'name': 'CBS Sports'}}, {'policy': 'deny', 'type': 'application', 'value': {'id': 'meraki:layer7/application/40', 'name': 'ESPN'}}, {'policy': 'deny', 'type': 'application', 'value': {'id': 'meraki:layer7/application/96', 'name': 'foxsports.com'}}]}
# Create the URL for retrieving all VLANs in the network
url = f"https://api.meraki.com/api/v1/networks/{config['networkId']}/appliance/firewall/l7FirewallRules"
# Set the HTTP headers
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"X-Cisco-Meraki-API-Key": config["apiKey"]
}
# Make the API request using the requests library
response = requests.request("PUT", url, headers=headers, data=json.dumps(newRules))
# Print the status code of the response
print("\nRequest status code : "+str(response.status_code), "\n")
# Parse the response as JSON
responseJson = response.json()
print(responseJson)
Ouptut
Request status code : 200
{'rules': [{'policy': 'deny', 'type': 'application', 'value': {'id': 'meraki:layer7/application/101', 'name': 'CBS Sports'}}, {'policy': 'deny', 'type': 'application', 'value': {'id': 'meraki:layer7/application/40', 'name': 'ESPN'}}, {'policy': 'deny', 'type': 'application', 'value': {'id': 'meraki:layer7/application/96', 'name': 'foxsports.com'}}]}
Indeed, it removed the existing rules :
You can find everything on the following repo: https://github.com/xaviervalette/meraki-update-l7-firewall-rules,
Hope it helps! 🙂
Xavier VALETTE