hfortix_fortios.ContentResponse

class hfortix_fortios.ContentResponse(data, raw_envelope=None, response_time=None, endpoint_path=None, request_info=None)[source]

Response wrapper for endpoints that return binary/text content.

Some FortiOS endpoints return raw content (config files, certificates, crash logs, etc.) instead of structured JSON. This class provides a consistent interface for accessing both the content and standard API response metadata.

Properties:

content: Raw bytes content from the response content_type: MIME type of the content (e.g., “text/plain”) text: Content decoded as UTF-8 string

# Standard API response fields (same as FortiObject): http_status_code: HTTP status code (200, 404, etc.) http_status: API status (‘success’ or ‘error’) http_method: HTTP method used http_response_time: Response time in milliseconds vdom: Virtual domain name serial: Device serial number version: FortiOS version build: FortiOS build number raw: Full API response envelope

# Endpoint-specific fields from query params: # These are dynamically available based on the endpoint schema

Parameters:
  • data (dict[str, Any])

  • raw_envelope (dict[str, Any] | None)

  • response_time (float | None)

  • endpoint_path (str | None)

  • request_info (dict | None)

to_text(encoding)[source]

Decode content with specified encoding

to_dict()[source]

Parse FortiOS config format to dictionary (if parseable)

to_json()[source]

Get parsed content as JSON string

save(path)[source]

Save content to file

Examples

>>> # Download config revision
>>> result = fgt.api.monitor.system.config_revision.file.get(config_id=45)
>>>
>>> # Access raw content
>>> result.content
b'#config-version=FGVM64-7.6.5...'
>>>
>>> # Get as text
>>> result.text
'#config-version=FGVM64-7.6.5...'
>>>
>>> # Access standard response fields
>>> result.http_status_code
200
>>> result.content_type
'text/plain'
>>>
>>> # Access endpoint-specific fields
>>> result.config_id
45
>>>
>>> # Parse FortiOS config to dict (if supported)
>>> config = result.to_dict()
>>> config['global']['system global']['admin-host']
'fgt.example.com'
>>>
>>> # Save to file
>>> result.save('/tmp/config_backup.conf')
__init__(data, raw_envelope=None, response_time=None, endpoint_path=None, request_info=None)[source]

Initialize ContentResponse.

Parameters:
  • data (dict[str, Any]) – Response data containing ‘content’ and ‘content_type’

  • raw_envelope (dict[str, Any] | None) – Full API response envelope

  • response_time (float | None) – Response time in seconds

  • endpoint_path (str | None) – Endpoint path for metadata lookup

  • request_info (dict | None) – HTTP request information (method, url, params, data)

Methods

__init__(data[, raw_envelope, ...])

Initialize ContentResponse.

save(path[, mode])

Save content to file.

to_dict()

Parse content to dictionary (for parseable content types).

to_json([indent])

Get parsed content as JSON string.

to_text([encoding])

Decode content to string with specified encoding.

Attributes

build

FortiOS firmware build number.

content

Raw bytes content from the response.

content_type

MIME type of the content.

fmg_api_request

Alias for http_api_request when using FortiManager proxy.

http_api_request

HTTP API request information for this response.

http_method

HTTP method used (GET, POST, PUT, DELETE).

http_response_time

Response time in milliseconds for this API request.

http_stats

HTTP request/response statistics summary.

http_status

API response status ('success' or 'error').

http_status_code

HTTP status code (200, 404, 500, etc.).

raw

Full API response envelope.

revision

Configuration revision number.

serial

Device serial number.

text

Content decoded as UTF-8 string.

vdom

Virtual domain name.

version

FortiOS version string (e.g., 'v7.6.5').