Courseiva
PCNSEChapter 14 of 19Objective 6.3

Automation and API Usage for Operations

Without understanding automation and API usage, a network engineer would spend hours every day doing repetitive tasks like updating firewall rules one by one, checking logs manually, and pushing the same configuration change to dozens of devices. That is slow, error-prone, and exhausting. Automation and the PAN-OS XML API solve this by letting a single command trigger changes across your entire Palo Alto Networks firewall environment, freeing you to focus on bigger problems.

12 min read
Advanced
Updated Jul 23, 2026
Reviewed by Johnson Ajibi· Senior Network & Security Engineer · MSc IT Security

A simple way to picture Automation and API Usage for Operations

The Hotel Manager and the Property Management System Analogy

A hotel manager named Sophia runs a 500-room resort. Every morning, she does the same rounds: checks which rooms are occupied, which need cleaning, which guests have checked out, and which maintenance requests are pending. Doing this by walking floor to floor, talking to housekeeping, and flipping through paper logs takes her three hours. One day, she gets a Property Management System (PMS) — a central digital dashboard. Now, instead of walking, she sends a single text message to the PMS: "Show me all rooms that need cleaning before noon." The PMS instantly replies with a list. She then sends another message: "Change the status of rooms 201, 305, and 412 to 'Cleaning in Progress'." The PMS updates instantly, and housekeeping staff see the change on their handheld devices. Sophia can now manage the entire hotel from her tablet while sitting at the front desk. She even schedules recurring messages: every morning at 8 AM, the PMS automatically emails the cleaning schedule to every housekeeper. This is exactly how automation and APIs work in IT. Sophia is the network engineer. The PMS is the PAN-OS XML API. Her text messages are API calls. The instant replies are API responses. The recurring emails are automated scripts. Instead of manually logging into each part of the network, the engineer sends one command, and the security system does the rest.

The hotel manager stopped being a floor-walker and became a dashboard commander. That is the power of automation and APIs.

How It Actually Works

Let us start with what an API is. API stands for Application Programming Interface. Think of it as a menu in a restaurant. You (the customer) have a menu that lists what you can order. You do not need to know how the kitchen cooks the food — you just tell the waiter your order, and the kitchen handles the rest. In IT, an API is that menu. It defines exactly what commands you can send to a piece of software and what responses you will get back.

Now, PAN-OS is the operating system that runs on Palo Alto Networks firewalls. It has its own API called the PAN-OS XML API. XML stands for eXtensible Markup Language. It is a way of writing data that both humans and computers can read. It looks like structured text with tags, similar to HTML but customisable. For example, a simple XML message might look like: <request><show><system><info/></show></request>. This is a request asking the firewall to show its system information.

So what does the PAN-OS XML API actually do? It lets you send commands to your firewall in a standardised way, and the firewall responds with structured data. You can do almost anything you can do through the web interface (GUI) — add a security rule, modify a policy, check logs, reboot the device, change an address object, and much more — but you do it by sending an XML message over HTTP or HTTPS.

Why does this matter? Before APIs, if you had 50 firewalls and needed to add a new rule blocking a malicious website on all of them, you would:

Log in to firewall #1 via a web browser

Navigate through menus to find the security policy section

Click 'Add' and fill in the rule details

Click 'Commit' to save the change

Repeat this exact process 49 more times

That takes hours and is incredibly boring. One typo and you might block legitimate traffic or leave a security hole. With the API, you write one script (a set of instructions that can be executed automatically) that sends the same XML message to all 50 firewalls. The whole job takes a few seconds.

Automation takes this a step further. Automation means having a computer perform a task repeatedly without human intervention. In the context of PAN-OS, you might write a script that runs every hour to check if any firewall rules are out of date, then automatically updates them. Or a script that checks for new threats and adds blocking rules instantly.

How does authentication work? To use the PAN-OS XML API, you need to prove you are allowed to make changes. You do this by providing an API key. An API key is a secret token — a long string of letters and numbers — that identifies you to the firewall. You generate this key once by sending your username and password to a special API endpoint (a specific URL on the firewall). The firewall returns an API key, and you use that key in all future requests instead of sending your password every time.

A typical API request looks like this: you send an HTTPS request (secure web request) to a URL like: https://YOUR-FIREWALL-IP/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry/rulebase/security/rules&element=<rule><name>Block-Bad-IP</name><action>deny</action></rule>&key=YOUR-API-KEY. That is one long URL with parameters. The firewall reads it and adds a new security rule called "Block-Bad-IP" that denies traffic.

What can you do with the API? The PAN-OS XML API supports several operation types:

'config': for configuration changes — add, edit, delete, rename, or move objects like rules, zones, or interfaces.

'op': for operational commands — like showing system information, checking logs, rebooting, or running a traceroute.

'log': specifically for retrieving log data, such as traffic logs or threat logs.

'export': to export configuration files or reports.

'import': to import configuration files, like a full device state or a custom signature.

'user-id': to update user-to-IP mapping information, which is used for User-ID policies.

'report': to generate and retrieve custom reports.

Each of these operations uses a specific 'type' parameter in the API URL.

What tools do you use to send API calls? You can use almost any programming language. Python is the most popular because it has libraries (pre-written code) that make sending HTTP requests easy. For example, the 'requests' library in Python lets you send an API call in three lines of code. You can also use command-line tools like 'curl' (a tool for transferring data with URLs) or Postman (a graphical application for testing APIs). Some engineers use automation platforms like Ansible (which has a module specifically for Palo Alto Networks firewalls) or Terraform (for infrastructure as code).

What is a commit? In PAN-OS, when you make a configuration change via the API, the change is not active until you perform a 'commit'. A commit tells the firewall to apply all pending changes and make them part of the active running configuration. Without a commit, your changes are saved only as candidates. The API allows you to trigger a commit by sending an operational command: type=op with a command like <commit></commit>.

How do you handle errors? The API returns XML responses that include status codes. A successful request returns a status of 'success'. An error returns a status of 'error' with a message explaining what went wrong, such as "invalid key" or "object already exists". Your automation scripts should check these responses to know if the request succeeded.

In summary, the PAN-OS XML API gives you a programmable way to control your firewalls. Automation uses that API to execute repetitive tasks automatically. This replaces tedious manual work with efficient, scripted operations.

Flowchart showing how an engineer uses automation tools to send API requests to a firewall, which processes them based on request type and returns a response.

Walk-Through

1

Generate the API Key

First, you need to authenticate to the firewall to get an API key. You send an HTTPS request to the firewall's API endpoint with your username and password (e.g., using a URL like https://firewall-ip/api/?type=keygen&user=admin&password=secret). The firewall returns an XML response containing your API key. This key is a long alphanumeric string that you will use in all subsequent requests. You should store this key securely, never hardcode it in scripts.

2

Construct the API Request

Now you decide what you want to do — for example, add a new security rule. You construct an XML-formatted request within a URL. The URL includes parameters: type (e.g., 'config' for configuration changes), action (e.g., 'set' to add a new object), xpath (the exact location in the firewall's configuration tree where the new rule should go), and element (the XML describing the rule itself). You also append your API key to the URL.

3

Send the Request and Receive the Response

You send the HTTPS request to the firewall. The firewall processes it and sends back an XML response. You need to check the response for a status attribute. If it says 'success', your request was accepted. If 'error', read the message to understand why (e.g., invalid key, missing parameter, object already exists). The response may also contain additional data depending on the request type.

4

Commit the Changes

The changes you made are now in the candidate configuration — they are not yet active. To make them part of the running configuration and actually enforce the new rule, you must send a commit command. This is an operational command (type=op) that contains a <commit></commit> element. The firewall will validate and apply all pending candidate changes. The commit may take a few seconds or minutes depending on the size of the changes.

5

Verify the Change

After the commit, you should verify that the change was applied successfully. You can send another API request — for example, use type=op with a command like <show><config><running></running></config></show> to retrieve the current running configuration and check for your new rule. Alternatively, you can use the 'log' API to check if the new rule is logging traffic as expected. This verification step is critical to ensure no errors occurred during the commit.

6

Automate Repetitive Tasks

For operations that recur regularly — like daily log retrieval, weekly rule cleanup, or immediate threat blocking — you can wrap the above steps in a script (e.g., Python) or an automation platform (e.g., Ansible). Schedule the script to run at specific times using a task scheduler (cron on Linux, Task Scheduler on Windows). The script handles all the requests, error checking, and commits automatically, giving you a report or alert if something goes wrong.

What This Looks Like on the Job

Consider this: Sarah is a network security engineer at a mid-sized company called TechFlow Ltd that has 30 Palo Alto Networks firewalls deployed in offices around the world. One Monday morning, the company's security team identifies a new malicious IP address that is actively trying to attack their web servers. They need to block this IP on all firewalls immediately — ideally within minutes.

Without automation, Sarah would have to:

Log in to the first firewall's web interface

Navigate to Policies > Security > Add a new rule

Set the source to 'any', destination to 'any', application to 'any', service to 'any', action to 'deny'

Enter the malicious IP as the source address

Name the rule "Emergency-Block-2025-03-24"

Click OK, then Commit

Repeat 29 more times

This would take at least an hour, and Sarah might make a typo in one of the 30 firewalls, leaving one unprotected.

Instead, Sarah uses automation. She has a Python script saved on her laptop called 'block_ip.py'. She opens a terminal, types: python block_ip.py --ip 5.5.5.5 --reason "Emergent threat"

The script does the following: 1. It reads a list of all 30 firewall IP addresses and their API keys from a secure configuration file. 2. For each firewall, it constructs an XML API request to add a new security rule with the malicious IP. 3. It sends the request via HTTPS to each firewall's API endpoint. 4. It checks the response from each firewall to confirm the rule was added successfully. 5. If any firewall returns an error, it logs that for Sarah to review. 6. Once all rules are added, the script sends a commit command to all 30 firewalls simultaneously.

Total time: about 30 seconds for the script to run, plus a minute for the commits to complete. Sarah then runs another script to verify the new rules are active by querying each firewall's rulebase and printing a status report.

Later that week, Sarah needs to generate a report of all traffic blocked by the new rule over the last 48 hours. She uses another script that calls the 'log' API to retrieve the traffic logs, filters them for the rule name "Emergency-Block-2025-03-24", and compiles them into a CSV file (Comma-Separated Values — a simple table format for data).

At the end of the quarter, the compliance team needs an audit of all firewall rule changes made in the last three months. Sarah uses an API script to export the full configuration of each firewall, which she stores in a version control system (like Git) to track every change. This way, if a problem arises, she can instantly see who changed what and revert to a previous configuration using the API.

Sarah also uses scheduled automation. She has a cron job (a time-based job scheduler on Linux) that runs every night at 2 AM:

It queries all firewalls for the latest threat log entries.

It checks for high-severity threats that are not yet blocked.

It automatically adds dynamic block rules for those IP addresses using the API.

It sends a summary email to the security team each morning.

This means Sarah does not have to sit up all night watching logs. The automation handles the routine tasks, and she only gets involved for exceptions.

The key takeaway from Sarah's experience is that automation and API usage turn a reactive, manual, error-prone job into a proactive, efficient, and reliable operation. The engineer becomes a supervisor of automated processes rather than a manual labourer.

How PCNSE Actually Tests This

The PCNSE exam objective 6.3 — 'Use the PAN-OS XML API and automation tools for operational tasks and configuration changes' — is a focused test of your ability to understand and apply the API in practical scenarios. The exam does not ask you to write code, but it does test your conceptual knowledge of how the API works, what methods it supports, and how to use it for common tasks.

What specific concepts appear on the exam? - API authentication methods: You must know that the API uses an API key for authentication, and that the key is generated by sending a valid username and password to the API endpoint /api/?type=keygen. You must also know that you should never hardcode the API key in scripts — it should be stored securely. - API request types: You need to remember the main request type parameters: config, op, log, export, import, user-id, and report. For each, you should know its purpose and a typical example. For instance, 'op' is for operational commands like 'show system info' or 'traceroute'. - XML structure basics: You do not need to be an XML expert, but you should recognise the common XML elements in API requests, like <uid-message>, <commit>, <entry>, <rule>, and <action>. The exam might show a partial XML snippet and ask what it does. - Commit behaviour: You must understand that changes made via the API are candidates until a commit is performed. The exam may present a scenario where a rule is added but not committed, and ask whether it is active. - Automation tools: The exam expects you to know that common automation tools include Ansible, Terraform, Python with the requests library, and curl. You do not need to know how to use them in depth, but you should recognise them as valid options. - Use cases: The exam tests your ability to identify when to use each API type. For example, a question might say: 'An engineer wants to retrieve the last 100 threat log entries. Which API type should they use?' The answer is 'log'. - Error handling: You should know that successful API calls return a status of 'success' and errors return 'error' with a message. The exam might ask what to check in the response to verify success.

What traps does the exam set? - Trap: Confusing 'config' and 'op'. They test that you know 'config' is for configuration changes, while 'op' is for operational commands. A question might describe adding a security rule and ask whether to use 'config' or 'op'. The trap answer is 'op' for those who remember it vaguely. - Trap: Forgetting the commit step. A scenario might describe adding a rule via API and then asking if traffic is now blocked. The correct answer is 'No, because the change has not been committed yet'. - Trap: Assuming the API key is the same for every operation. They might ask: 'Is the API key the same for the 'config' and 'log' API calls?' The answer is yes, it is one key per firewall account. - Trap: Mixing up API endpoint URLs. They might give a URL with a wrong parameter (e.g., type=op for a config change) and ask if it is correct. The answer is no. - Trap: Believing that all automation must be done with Python. The exam wants you to know that multiple tools exist — Ansible is especially common for enterprise automation.

Key definitions to memorise for the exam:

API key: A secret token used to authenticate API requests.

Commit: The action of making candidate configuration changes active.

XML: eXtensible Markup Language — the format for API requests and responses.

Operational command (op): A command to run a show, debug, or test action on the firewall.

Configuration command (config): A command to add, edit, delete, or rename configuration objects.

Candidate configuration: Uncommitted changes stored in memory.

Running configuration: The current active configuration on the firewall.

Question patterns to expect:

Multiple-choice: 'Which API type should be used to add a new address object?' The answer is 'config'.

Multiple-choice: 'After adding a security rule via the API, what additional step is required for the rule to take effect?' The answer is 'Perform a commit'.

Scenario-based: 'An engineer needs to update the URL filtering profile on 200 firewalls. Which approach is most efficient?' The answer is 'Write a Python script that uses the PAN-OS XML API to push the change to all firewalls and then commit.'

True/False: 'The PAN-OS XML API requires the engineer to log in to the web interface first.' The answer is false — it uses an API key.

To prepare, practise reading XML API requests and responses. Use the Palo Alto Networks API explorer (a free tool that lets you test API calls against a demo firewall) to familiarise yourself with common commands. Remember that the exam emphasises practical application: you need to know not just what the API can do, but also when and why to use it.

Key Takeaways

The PAN-OS XML API uses an API key for authentication, which you generate once by sending a valid username and password to the /api/?type=keygen endpoint.

Configuration changes made via the API are saved as candidate configuration and do not take effect until you perform a commit.

The API supports seven major request types: config, op, log, export, import, user-id, and report, each for a different category of task.

Automation tools like Ansible and Python scripts can send API calls to multiple firewalls simultaneously, reducing hours of manual work to seconds.

An API key is long-lived and remains valid until the password is changed or the key is explicitly invalidated.

Successful API responses contain a status of 'success'; errors include a descriptive message that helps you diagnose the problem.

The 'op' API type is used for operational commands such as 'show system info' and 'traceroute', not for configuration changes.

You can test API calls manually using curl or Postman without writing any code, making the API accessible even to non-programmers.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Config API (type=config)

Used for adding, editing, deleting, renaming, or moving configuration objects like rules, zones, and address objects.

Changes are made to the candidate configuration and require a commit to become active.

Uses parameters like xpath (location in config tree) and element (XML describing the object).

Op API (type=op)

Used for executing operational commands like show system info, traceroute, ping, or commit.

Commands are executed immediately and do not require a commit.

Uses a cmd parameter that contains the command in XML format, e.g., <show><system><info/></show>.

API Key Authentication

Uses a long-lived secret token (API key) generated once via the keygen API endpoint.

The key is included in every API request as a parameter or header.

The key remains valid until the firewall password is changed or the key is explicitly invalidated.

Session-Based Authentication (Web GUI)

Uses a temporary session cookie that expires after inactivity or browser closure.

The session is established by logging in via the web interface with username/password.

Sessions are short-lived and must be refreshed periodically.

Manual CLI/GUI Operations

Requires the engineer to log in to each firewall individually via SSH or web browser.

Each step (navigate, change, commit) is performed manually, one firewall at a time.

Prone to human error (typos, missed steps) and time-consuming for multiple devices.

Automated API Operations

Uses a script or tool to send API calls to multiple firewalls simultaneously from one command.

The entire workflow (request, check response, commit) is executed by the script without manual intervention.

Highly repeatable, consistent, and fast — reduces error rates and frees the engineer.

Watch Out for These

Mistake

You need to be a programmer to use the PAN-OS XML API.

Correct

You do not need to be a programmer. You can test API calls manually using tools like curl or Postman without writing any code. Many automation tasks are done with pre-built scripts or Ansible playbooks that require minimal scripting knowledge.

This misconception comes from the word 'API' sounding technical and the association with programming languages. Beginners see XML and think it requires coding expertise, but the API is designed to be accessible to network engineers with basic command-line skills.

Mistake

The API key is valid for a single session and expires after each use.

Correct

The API key is long-lived by default. It does not expire after each use or after a session ends. You generate it once and reuse it until you deliberately invalidate it (e.g., by changing the password).

This confusion arises because web interfaces often use session tokens that expire quickly. Beginners assume the API key works the same way as a browser session cookie. In reality, the API key is more like a permanent password for programmatic access.

Mistake

If you make a configuration change via the API, it is immediately active on the firewall.

Correct

A configuration change via the API only modifies the candidate configuration. It does not become active until you explicitly perform a commit operation via the API. Until then, the change exists but is not enforced.

In the web interface, users often click 'OK' and then 'Commit' in quick succession, so they perceive the change as immediate. When using the API, these steps are separate, so beginners mistakenly believe the API skips the commit phase.

Mistake

The PAN-OS XML API can only be used for configuration changes, not for retrieving information.

Correct

The API supports many operation types, including 'op' for operational commands (show system info, traceroute, etc.) and 'log' for retrieving logs. It is not limited to configuration — you can use it to monitor and troubleshoot as well.

The name 'config' in the API URL leads beginners to think that is the only purpose. They overlook that you can also run operational commands and fetch logs. The exam tests this distinction directly.

Mistake

Automation means you replace human engineers entirely, so the company will fire the network team.

Correct

Automation offloads repetitive, tedious tasks to machines, allowing engineers to focus on more strategic work like security architecture, incident response, and optimisation. The engineer's role evolves from manual execution to designing and supervising automated processes.

Fear of job loss is common in any industry adopting automation. This fear is amplified by media narratives. In reality, automation creates demand for skilled engineers who understand the technology, rather than eliminating jobs.

Mistake

You must use Python for any PAN-OS automation task; no other tools work.

Correct

You can use many tools: curl (command-line), Postman (graphical), Ansible (configuration management), Terraform (infrastructure as code), PowerShell (on Windows), or even a browser's developer console. Python is popular but not required.

Python is heavily marketed in IT as the go-to automation language, so beginners assume it is the only option. The PCNSE exam expects you to know that multiple tools exist, but it does not require Python expertise.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between the PAN-OS XML API and the REST API?

Palo Alto Networks has both an XML API and a newer REST API. The XML API uses XML formatting and requires more manual construction of requests. The REST API uses JSON and is more modern. Both can achieve similar tasks, but the XML API is the legacy interface covered by the PCNSE exam objective 6.3.

Can I use the API to reboot a firewall remotely?

Yes. You send an operational command (type=op) with the command <request><restart><system></system></restart></request>. You must include your API key. The firewall will restart, and you will need to wait for it to come back online before sending further commands.

How do I find the correct xpath for a configuration object?

You can use the API explorer on the Palo Alto Networks documentation site, or you can export the current configuration (type=export) and examine the XML structure. The xpath is the path through the configuration tree, like /config/devices/entry/vsys/entry/rulebase/security/rules.

Is there a risk that an API call could break the firewall configuration?

Yes, if you send an incorrect xpath or malformed XML, you could corrupt the configuration or create conflicting rules. Always test API calls in a lab environment first. Use the commit operation on a test device before applying to production. The API does not have undo functionality — you must fix mistakes manually.

Do I need to know XML to pass PCNSE objective 6.3?

You do not need to be an XML expert, but you should recognise common XML elements like <entry>, <rule>, <action>, <commit>, and <uid-message>. The exam may present a partial XML snippet and ask what it does. Practise reading example API request and response XML from Palo Alto's documentation.

What happens if I lose my API key?

You cannot retrieve a lost API key. You must generate a new one by sending the keygen request again with your username and password. The old key will become invalid. Store your API key securely in a password manager or encrypted file to avoid this.

Terms Worth Knowing

Keep going

You've finished Automation and API Usage for Operations. Continue through the PCNSE study guide to build a complete picture of the exam.

Done with this chapter?