Skip to content

How to Update Cisco Meraki MX Layer 3 Firewall Rules via API

June 6, 2026
Meraki MX

Introduction

Managing a handful of branch firewalls via a graphical user interface is standard procedure. However, when an enterprise network scales to dozens, hundreds, or thousands of locations, manual configuration becomes a liability. Clicking through the Meraki Dashboard to update a single Layer 3 outbound firewall rule across 50 sites is not just tedious—it introduces configuration drift, human error, and massive operational overhead.

Network automation fundamentally changes this dynamic. By leveraging the Cisco Meraki REST API, infrastructure engineers can programmatically query, modify, and push firewall policies across an entire global network in seconds.

Whether you are cloning a “Golden Image” site for a new retail branch, dynamically blocking malicious IP addresses detected by your SIEM, or updating printer subnets after a VLAN migration, API-driven firewall management is a mandatory skill for modern NetOps teams.

What is Meraki API Firewall Automation?

Meraki API firewall automation is the process of interacting with the Cisco Meraki cloud backend via HTTP requests to manage the Layer 3 security policies of MX security appliances.

Instead of logging into the web dashboard and navigating to Security & SD-WAN > Firewall, engineers send formatted JSON payloads to specific Meraki API endpoints. For outbound Layer 3 rules, the target endpoint in API version 1 (v1) is /networks/{networkId}/appliance/firewall/l3FirewallRules.

Through standard RESTful operations—specifically GET to retrieve current rules and PUT to overwrite them—you can manage the entire access control list (ACL) of an appliance programmatically.

Read Also: Meraki API Updating VLANs

Why It Matters in Modern Networks

In legacy environments, firewall rules were static. Today, networks are highly dynamic. Applications move between cloud providers, threat intelligence feeds update by the minute, and new branch sites are spun up rapidly using zero-touch provisioning (ZTP).

Relying on manual firewall updates creates a bottleneck between security requirements and business agility. API-driven firewall management matters because it enables Infrastructure as Code (IaC). When firewall rules are defined in code (like Python or Terraform), they can be version-controlled in Git, peer-reviewed, tested in staging environments, and deployed uniformly. This ensures compliance, eliminates shadow IT, and guarantees that site B has the exact same security posture as site A.

Key Concepts Explained

To successfully interact with the Meraki firewall API, you need to understand a few core concepts:

  • RESTful Verbs: We rely heavily on GET (to read data) and PUT (to update data). Meraki uses PUT for firewall rules, which means you must supply the entire list of rules in your request. If you only send one rule in a PUT request, you will accidentally delete all other existing rules.

  • Network ID: Every site in your Meraki dashboard has a unique string identifier (e.g., N_1234567890123456). API calls are directed at this specific ID.

  • JSON Payloads: Meraki API requires data to be formatted in JavaScript Object Notation (JSON). This structure maps perfectly to Python dictionaries.

  • Outbound Layer 3 Rules: In the Meraki MX architecture, standard L3 rules dictate outbound traffic (traffic leaving a VLAN toward the WAN or another VPN subnet).

Step-by-Step Breakdown

Executing a firewall update via the API follows a strict, repeatable workflow:

  1. Authentication: Obtain your Meraki API key and include it in the X-Cisco-Meraki-API-Key HTTP header.

  2. Locate the Network ID: Identify the specific site where the MX appliance resides.

  3. Fetch Existing Rules (GET): Pull down the current firewall policy to ensure you do not overwrite existing configurations blindly.

  4. Modify the Payload: Programmatically alter the specific rule you need to change (e.g., updating a source CIDR block).

  5. Push the Update (PUT): Send the complete, updated list of rules back to the Meraki cloud.

  6. Verify: Check the HTTP status code (looking for a 200 OK) and optionally verify in the Meraki Dashboard.

Configuration / Code Examples

While tools like Postman are excellent for quick testing, Python is the industry standard for production automation. Below is a robust Python script using the requests library to safely update a Layer 3 firewall rule.

Python Script: Updating a Layer 3 Firewall Rule

import requests
import json

# Define variables (Replace with your actual data)
API_KEY = "your_meraki_api_key_here"
NETWORK_ID = "L_1234567890123456"
BASE_URL = f"https://api.meraki.com/api/v1/networks/{NETWORK_ID}/appliance/firewall/l3FirewallRules"

# Setup HTTP Headers
headers = {
    "X-Cisco-Meraki-API-Key": API_KEY,
    "Content-Type": "application/json",
    "Accept": "application/json"
}

def update_firewall_rules():
    print(f"[*] Fetching existing firewall rules for network {NETWORK_ID}...")
    
    # STEP 1: GET existing rules to prevent overwriting everything
    try:
        response = requests.get(BASE_URL, headers=headers)
        response.raise_for_status() # Check for HTTP errors
        current_data = response.json()
        rules_list = current_data.get('rules', [])
    except requests.exceptions.RequestException as e:
        print(f"[!] Failed to fetch rules: {e}")
        return

    # STEP 2: Modify the specific rule locally
    rule_found = False
    new_source_cidr = "10.50.10.0/24" # Our new printer subnet
    
    for rule in rules_list:
        # We target a specific rule by its comment/description
        if rule.get('comment') == 'Allow Printers to Internal':
            print(f"[*] Found target rule. Updating source CIDR to {new_source_cidr}")
            rule['srcCidr'] = new_source_cidr
            rule_found = True
            break
            
    if not rule_found:
        print("[!] Target rule not found. Aborting update.")
        return

    # Prepare the final payload containing ALL rules
    payload = {"rules": rules_list}

    # STEP 3: PUT the updated rule list back to the API
    print("[*] Pushing updated rules to Meraki Cloud...")
    try:
        put_response = requests.put(BASE_URL, headers=headers, json=payload)
        put_response.raise_for_status()
        print("[+] Success! Firewall rules updated. Status Code: 200")
    except requests.exceptions.RequestException as e:
        print(f"[!] Failed to update rules: {e}")

if __name__ == "__main__":
    update_firewall_rules()

 

Code Explanation:

  • Lines 16-24: We perform a GET request to pull the current firewall state. This is the most critical step to avoid a network outage caused by an accidental overwrite.

  • Lines 27-37: We iterate through the Python list of dictionaries. We identify our target rule using the comment field (e.g., “Allow Printers to Internal”) and update the srcCidr key to match a newly provisioned subnet.

  • Lines 42-49: We bundle the modified list back into the expected JSON structure {"rules": [...]} and push it via a PUT request.

Real-World Use Cases

  1. Site Cloning & Branch Spin-ups: When cloning a template network to a new branch, the firewall rules copy over perfectly. However, the internal IP subnets usually change. You can use the API to automatically parse the new site’s rules and update the srcCidr fields to match the newly assigned local VLANs.

  2. Dynamic Threat Containment: Integrate your Meraki firewalls with a Security Information and Event Management (SIEM) tool. If the SIEM detects a malicious external IP, it can trigger an API script to instantly add a Deny rule to the top of the MX firewall across all global sites simultaneously.

  3. Scheduled Maintenance Windows: Write a script that opens specific firewall ports for database replication at 2:00 AM, and uses a scheduled Cron job to run another script to remove the rule at 4:00 AM, ensuring temporary access isn’t forgotten and left open indefinitely.

Benefits

  • High-Speed Execution: Changes that take hours across 50 sites via the GUI take seconds via the API.

  • Consistency: Scripts do not make typos. An IP address pushed via API is deployed exactly as defined in your code.

  • Auditability: When firewall changes are executed via Python or CI/CD pipelines, you retain a clear, text-based log of exactly what was changed, when, and by whom.

Common Challenges

The single largest trap engineers fall into with the Meraki Firewall API is the nature of the PUT command. Because there is no PATCH or POST method specifically for appending a single line to an ACL, the PUT command acts as a complete replacement. If you have 50 rules on a firewall, and you send a payload containing only 1 new rule, the Meraki cloud will delete the 50 existing rules and replace them with your 1 rule.

Always GET first, append/modify the payload locally, and PUT the entire list back.

Best Practices

  • Idempotency: Write your scripts so that if they are run multiple times, the result is the same as running them once. Before adding a rule, have your script check if the rule already exists.

  • Use Staging Networks: Never test a new API script on a production network. Create a virtual MX or an empty network in your dashboard specifically for validating your API payloads.

  • Leverage Tags: Use network tags in Meraki to group sites (e.g., tag:retail). Have your Python script pull a list of networks matching that tag, and apply firewall updates to that specific group sequentially.

Security Considerations

Your Meraki API key provides administrative access to your entire enterprise network. It must be treated like a master password.

  • Never Hardcode Keys: Do not place API keys directly in your Python code. Use environment variables (e.g., os.environ.get('MERAKI_API_KEY')).

  • Use Secrets Vaults: For production environments, integrate HashiCorp Vault, AWS Secrets Manager, or Azure Key Vault to pass credentials to your scripts at runtime.

  • Key Rotation: Regularly revoke and regenerate API keys within the Meraki Dashboard to minimize the blast radius of a potential credential leak.

Troubleshooting Tips

  • HTTP 400 Bad Request: Your JSON payload is malformed. Ensure you are passing the correct data types. For example, the rules parameter must be an array of objects (a list of dictionaries in Python), not a single dictionary.

  • HTTP 401 Unauthorized: Your API key is invalid, missing from the headers, or the account attached to the key does not have write privileges for that specific network.

  • HTTP 404 Not Found: The script is pointing to a Network ID that does not exist. Double-check your URL string formatting.

  • HTTP 429 Too Many Requests: You are hitting the Meraki API rate limit (typically 10 calls per second per organization). Add a time.sleep(0.5) function inside your Python loops to pace your requests gracefully.

The future of firewall automation is moving heavily toward declarative intent. While imperative Python scripts are incredibly powerful, many teams are transitioning to Terraform. Cisco Meraki maintains an official Terraform provider, allowing engineers to define firewall policies in .tf files. The Terraform engine automatically handles the GET and PUT logic behind the scenes, determining exactly what needs to be changed to match the desired state defined in your code.

Additionally, AI-driven intent-based networking will soon allow operators to type plain-text policies (“Block all traffic from branch networks to the main data center SQL servers after hours”) and have the API auto-generate and push the required L3 rules.

Frequently Asked Questions (FAQ)

What API endpoint is used to update Meraki MX Layer 3 firewall rules?

To update outbound Layer 3 firewall rules on a Meraki MX appliance, you must make a PUT request to the /networks/{networkId}/appliance/firewall/l3FirewallRules endpoint.

Why did my Meraki API call delete all my other firewall rules?

Because updating firewall rules requires an HTTP PUT request, it overwrites the existing configuration. If you do not include the existing rules in your JSON payload, the API assumes you want them removed. Always perform a GET request first, modify the list, and PUT the entire list back.

What format does the Meraki API require for firewall rules?

The Meraki API requires a JSON payload formatted as a single object containing a “rules” key, which holds an array of rule objects containing protocol, policy, destPort, destCidr, srcPort, and srcCidr fields.

Can I use Postman to update Meraki firewall rules?

Yes. Postman is an excellent tool for testing Meraki API calls. You can execute a GET request, copy the response body, modify it in your text editor, paste it into the Body tab of a PUT request, and send it to update the firewall.

How do I authenticate my Python script with the Meraki API?

Authentication is handled via HTTP headers. You must include the “X-Cisco-Meraki-API-Key” header in your requests, mapping it to the API key generated in your user profile on the Meraki Dashboard.

Does changing Meraki firewall rules via API cause network downtime?

No. Updating the Layer 3 firewall rules via the API applies the changes silently in the background, exactly as it would if you clicked “Save” in the web dashboard. Existing allowed states are typically maintained.

How do I handle Meraki API rate limits (HTTP 429)?

Meraki enforces a rate limit of approximately 10 requests per second per organization. If you exceed this, you will receive an HTTP 429 response. Implement exponential backoff or simple sleep timers in your Python loops to pace your calls.

Can I use the official Meraki Python SDK for firewall updates?

Absolutely. The official meraki Python library abstracts the raw HTTP requests. You can use dashboard.appliance.updateNetworkApplianceFirewallL3FirewallRules() to achieve the same result with cleaner code.

Featured Snippet Paragraph

To update Cisco Meraki MX Layer 3 firewall rules using the API, you must first send an HTTP GET request to the /networks/{networkId}/appliance/firewall/l3FirewallRules endpoint to retrieve the current access control list. Because the API uses the PUT method for updates, sending a new rule without the existing rules will overwrite and delete your current configuration. Modify the JSON response locally to include your new or altered rules, and then send an HTTP PUT request with the complete rule list back to the same endpoint to apply the changes safely.

Featured Snippet List

Steps to Automate Meraki Firewall Rules:

  1. Generate a Meraki API Key from your dashboard profile.

  2. Identify the target Network ID.

  3. Execute an HTTP GET request to pull the existing firewall rules.

  4. Parse the JSON response and append or modify the specific rule.

  5. Execute an HTTP PUT request containing the entire updated list of rules.

  6. Verify the 200 OK status code response.

Featured Snippet Table

API Method Endpoint Suffix Action Performed
GET /appliance/firewall/l3FirewallRules Retrieves the current list of L3 outbound firewall rules.
PUT /appliance/firewall/l3FirewallRules Replaces the entire list of L3 firewall rules with the provided JSON payload.

 

 

Bhardwaj Vishnu

Bhardwaj Vishnu is an L2 Network Security Engineer with hands-on expertise in enterprise firewall management, network automation, and multi-vendor infrastructure. He holds Fortinet NSE 4 and NSE 5 certifications, a Cisco CCNA, and has completed all three stages of the Cisco Meraki certification track. In his day-to-day role, he architects and maintains security policies on FortiGate firewalls, deploys and manages Cisco Meraki MX, MS, and MR environments, and handles Cisco routing and switching at scale. Every technical guide on NetConfig.io is written from direct production experience — real CLI commands, verified configurations, and the hard-won lessons that vendor documentation never covers.