Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Richard_Carson
Contributor

CP python SDK - api_query function

As i understand it in the python sdk, api_query should return all objects and handle all the require API paging. This seems to work for show-host\show objects

"to": 45766,
"total": 45766
},
"status_code": 200

however for show-access-rules

client.api_query(command="show-access-rulebase",payload={"name" : "MyPolicy Security"})

This does not seem to work - it only returns objects up to the default page limit for that api call

"to": 50, client.api_query(command="show-access-rulebase",payload={"name" : sl})
"total": 52,

Do i misunderstand something here?

Also - include-container-key doesnt seem to have any affect - whether True or False it always returns a dict, never a list. Not a problem for me but the documentation is misleading?

 

"""
The APIs that return a list of objects are limited by the number of objects that they return.
To get the full list of objects, there's a need to make repeated API calls each time using a different offset
until all the objects are returned.
This API makes such repeated API calls and return the full list objects.
note: this function calls gen_api_query and iterates over the generator until it gets all the objects,
then returns.

:param command: name of API command. This command should be an API that returns an array of
objects (for example: show-hosts, show networks, ...)
:param details_level: query APIs always take a details-level argument.
possible values are "standard", "full", "uid"
:param container_key: name of the key that holds the objects in the JSON response (usually "objects").
:param include_container_key: If set to False the 'data' field of the APIResponse object
will be a list of the wanted objects.
Otherwise, the date field of the APIResponse will be a dictionary in the following
format: { container_key: [ List of the wanted objects], "total": size of the list}
:param payload: a JSON object (or a string representing a JSON object) with the command arguments
:return: if include-container-key is False:
an APIResponse object whose .data member contains a list of the objects requested: [ , , , ...]
if include-container-key is True:
an APIResponse object whose .data member contains a dict: { container_key: [...], "total": n }
"""

0 Kudos
2 Replies
PhoneBoy
Admin
Admin

That appears to be what the source code says.
Possible this is a bug.
@Amiad_Stern 

0 Kudos
Richard_Carson
Contributor

I figured it out - you need to use the correct 'container key'. By default it will pass a json container of "objects" but in the case of show-access-rulebase the container is 'rulebase' - once I set the correct container it works as I would expect. thxs @Amiad_Stern
0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events