vladimirs-git / fortigate-api

Python package for configuring Fortigate (Fortios) devices using REST API
Apache License 2.0
61 stars 18 forks source link

Unable to use Query Params with Fortigate.get() #14

Closed AaronFoley closed 1 year ago

AaronFoley commented 1 year ago

Hi,

I am trying to access a REST endpoint that needs to be supplied a query parameter, but due the the URL formatting I am not able to do this.

Example:

from fortigate_api import Fortigate

fgt = Fortigate(host='127.0.0.1', username='user', password='password')
fgt.get('api/v2/monitor/router/lookup?destination=0.0.0.0')

Will return an error "{'error_message': 'Failed to resolve FQDN'}" because the URL is formatted to be: api/v2/monitor/router/lookup?destination=0.0.0.0/

The _valid_url function does this: https://github.com/vladimirs-git/fortigate-api/blob/b19f7bd94f152b422323b096b7115ed7ba3192ad/fortigate_api/fortigate.py#L430

Will probably either need to remove the trailing / from the url, or may extend the get function to also accept parameters. Happy to raise a PR for this, just not sure which solution you would have preferred.

A hacky workaround I've found is to add an additional query parameter to the URL so that the / ends up as part of that:

fgt.get('api/v2/monitor/router/lookup?destination=0.0.0.0&ignore')

Thanks, Aaron

vladimirs-git commented 1 year ago

Confirm, in case if the "destination" parameter is the last parameter in the URL "api/v2/monitor/router/lookup" Fortigate will return the following error: {'error_message': 'Failed to resolve FQDN'} instead of interested data. As a temporary solution, do not put the "destination" parameter as the last parameter in the URL

vladimirs-git commented 1 year ago

fixed in v1.2.4