Calling Specific Endpoint
In this section, we describe how to use the FncApiClient
to call specific endpoints. The steps involved in calling specific endpoints are:
1. Imports
The main classes required while calling specific endpoint are shown below.
from fnc.fnc_client import FncClient from fnc.api import EndpointKey, FncApiClient from fnc.errors import FncClientError
2. Get the Client
The FncApiClient
is created using the FncClient
class’s method and providing the required arguments. For a detailed description, see Getting the client.
3. Call Endpoint
The FncApiClient’s call_endpoint
method is used to call specific endpoints. The method requires two arguments: the endpoint to be called and a dictionary with its required arguments.
client.call_endpoint( endpoint: EndpointKey, args: dict )
The full list of supported endpoints and its description is provided in FncClient Library Supported Endpoints. |
4. Handle Errors
Any exception occurring while calling the endpoint will be raised as a FncClientError
exception. The specific problem can be identified by using the FncClientError
fields.
The code below shows a full example of using the client while calling a specific endpoint to resolve a detection.
from fnc.fnc_client import FncClient from fnc.api import EndpointKey, FncApiClient from fnc.errors import FncClientError client_name = '' api_token = '' domain = '' log_level = None client: FncApiClient = None try: client = FncClient.get_api_client( name=client_name, domain=domain, api_token=api_token ) client.get_logger().set_level(level=log_level) detection_id = '' resolution = '' comment = '' response = client.call_endpoint( EndpointKey.RESOLVE_DETECTION, { 'detection_id': detection_id, 'resolution': resolution, 'resolution_comment': comment } ) client.get_logger().info(response) except FncClientError as e: client.get_logger().error(e)