Endpoint Methods

Understanding the available HTTP methods for FortiOS API endpoints.

Available HTTP Methods

HFortix provides direct access to FortiOS REST API through standard HTTP methods. Each endpoint may support one or more of the following methods depending on the FortiOS API capabilities:

Standard CRUD Methods

  • .get() - HTTP GET - Retrieve resources (list all, or get one by its key field, e.g. name=)

  • .post() - HTTP POST - Create new resources

  • .put() - HTTP PUT - Update existing resources

  • .delete() - HTTP DELETE - Delete resources

  • .set() - Idempotent create-or-update: checks if the object exists, then calls .post() or .put() accordingly (available on table endpoints)

Method Usage

from hfortix_fortios import FortiOS

fgt = FortiOS(host='192.168.1.99', token='your-token')

# GET - Retrieve all resources
addresses = fgt.api.cmdb.firewall.address.get()

# GET - Retrieve specific resource by its key field (name for firewall.address)
address = fgt.api.cmdb.firewall.address.get(name='webserver')

# POST - Create new resource
result = fgt.api.cmdb.firewall.address.post(
    payload_dict={
        'name': 'webserver',
        'subnet': '192.168.1.100 255.255.255.255',
        'comment': 'Production web server'
    }
)

# PUT - Update existing resource
result = fgt.api.cmdb.firewall.address.put(
    name='webserver',
    payload_dict={
        'comment': 'Updated comment'
    }
)

# DELETE - Remove resource
result = fgt.api.cmdb.firewall.address.delete(name='webserver')

# SET - Create-or-update (table endpoints)
result = fgt.api.cmdb.firewall.address.set(
    name='webserver',
    subnet='192.168.1.100 255.255.255.255',
    comment='Created or updated as needed'
)

Method Availability

Not all endpoints support all methods. The available methods depend on the FortiOS API design:

Endpoint Type

GET

POST

PUT

DELETE

SET

CMDB Table (e.g., firewall.address)

CMDB Complex (e.g., system.global, via system.global_)

Monitor (e.g., system.status)

Log (e.g., disk.event)

Common Parameters

GET Method

# List all with filtering
addresses = fgt.api.cmdb.firewall.address.get(
    filter=['type==ipmask'],
    count=10,
    start=0
)

# Get specific object by its key field
address = fgt.api.cmdb.firewall.address.get(name='webserver')

# With VDOM
address = fgt.api.cmdb.firewall.address.get(
    name='webserver',
    vdom='root'
)

POST Method

# Create with payload_dict
result = fgt.api.cmdb.firewall.policy.post(
    payload_dict={
        'name': 'Allow-Web',
        'srcintf': [{'name': 'port1'}],
        'dstintf': [{'name': 'port2'}],
        'srcaddr': [{'name': 'all'}],
        'dstaddr': [{'name': 'webserver'}],
        'service': [{'name': 'HTTP'}, {'name': 'HTTPS'}],
        'action': 'accept'
    }
)

# Create with keyword arguments (Pydantic models where available)
result = fgt.api.cmdb.firewall.address.post(
    name='testserver',
    subnet='10.0.1.5 255.255.255.255',
    comment='Test server'
)

PUT Method

# Update by key field with payload_dict
result = fgt.api.cmdb.firewall.address.put(
    name='webserver',
    payload_dict={
        'comment': 'Updated web server',
        'color': 3
    }
)

# Update with keyword arguments
result = fgt.api.cmdb.firewall.address.put(
    name='webserver',
    comment='Updated comment',
    color=3
)

DELETE Method

# Delete by key field
result = fgt.api.cmdb.firewall.address.delete(name='webserver')

# Delete with VDOM
result = fgt.api.cmdb.firewall.address.delete(
    name='webserver',
    vdom='root'
)

SET Method

.set() is a convenience method on table endpoints: it checks whether the object already exists and then calls .post() (create) or .put() (update).

# Create-or-update a table entry
result = fgt.api.cmdb.firewall.address.set(
    name='webserver',
    subnet='192.168.1.100 255.255.255.255',
    comment='Idempotent create-or-update'
)

Complex (singleton) endpoints such as system.global do not have .set() — update them with .put(). Note that global is a Python keyword, so the attribute is global_:

result = fgt.api.cmdb.system.global_.put(
    hostname='firewall-01',
    timezone='America/New_York',
)

Response Objects

All methods return FortiObject or FortiObjectList instances:

# Single object response (POST, PUT, DELETE)
result = fgt.api.cmdb.firewall.address.post(...)
print(result.http_status_code)  # 200
print(result.fgt_revision)      # Configuration revision
print(result.raw)               # Full API envelope

# List response (GET without a key)
addresses = fgt.api.cmdb.firewall.address.get()
for addr in addresses:
    print(addr.name)
    print(addr.subnet)

# Single object response (GET with a key)
address = fgt.api.cmdb.firewall.address.get(name='webserver')
print(address.name)
print(address.subnet)

Using the request() Method

For maximum flexibility, use the low-level request() method:

# Direct request - copy JSON from FortiGate GUI
response = fgt.request(
    method='POST',
    path='/api/v2/cmdb/firewall/address',
    data={
        'name': 'webserver',
        'subnet': '192.168.1.100 255.255.255.255',
        'comment': 'Production web server'
    }
)

Monitor API Methods

Monitor endpoints typically only support GET and POST:

# GET - Retrieve monitoring data
status = fgt.api.monitor.system.status.get()
interfaces = fgt.api.monitor.system.interface.get()

# POST - Trigger actions
result = fgt.api.monitor.system.config.backup.post()

Error Handling

from hfortix_core.exceptions import APIError, ResourceNotFoundError

try:
    address = fgt.api.cmdb.firewall.address.get(name='nonexistent')
except ResourceNotFoundError:
    print("Address not found")
except APIError as e:
    print(f"Error: {e.http_status} - {e.message}")

See Also