Skip to content

Request client

nexthink_api.Clients.NxtApiClient

Initializes a new instance of the NxtApiClient class.

Parameters

instance : str
    The name of the Nexthink instance.
region : NxtRegionName
    The region of the Nexthink instance.
client_id : str
    The client ID for authentication.
client_secret : str
    The client secret for authentication.
proxies : Optional[dict]
    A dictionary of proxies to use for the requests. Defaults to None.
Note.
  • if proxy are not provided, it will try to detect proxies from environment variables
  • if no proxy are detected, it will disable the proxy
  • false value disable the proxy

settings = NxtSettings(instance=instance, region=region, proxies=proxies) instance-attribute

endpoint: NxtEndpoint instance-attribute

token: Union[NxtTokenResponse, None] = None instance-attribute

headers = {} instance-attribute

init_token(client_id: str, client_secret: str) -> None

Initialize the token using the provided client ID and client secret.

Parameters
client_id : str
    The client ID.
client_secret : str
    The client secret.
Returns
None

update_header(endpoint: NxtEndpoint = None) -> None

Update header for subsequent requests based on the given endpoint.

Parameters
endpoint : NxtEndpoint, optional
    The endpoint type for which to update the header. Defaults to None.
Returns
None

create_autorisation(client_id: str, client_secret: str) -> None

Create authorization using client ID and client secret.

Parameters
client_id : str
    The client ID.
client_secret :str
    The client secret.
Returns
None

get_bearer_token() -> bool

Retrieve a bearer token from the server.

Returns
bool
    True if the token was successfully retrieved, False otherwise.
Raises
NxtTokenException
    If an error occurs during the token retrieval.

run_enrichment(endpoint: NxtEndpoint, data: NxtEnrichmentRequest) -> EnrichmentResponseType

Run an enrichment request on the specified endpoint using the provided data.

Parameter
endpoint : NxtEndpoint
    The endpoint to run the enrichment request on.
data : NxtEnrichmentRequest
    The data containing the enrichment request.
Raises
ValueError
    If the specified HTTP method is not supported.
Returns
EnrichmentResponseType
    The EnrichmentResponseType object containing the response from the API call.

run_nql(endpoint: NxtEndpoint, data: NxtNqlApiExecuteRequest, method: Optional[str] = None) -> NqlResponseType

Run an NQL query on the specified endpoint using the provided data.

Parameters
endpoint : NxtEndpoint
    The endpoint to run the NQL query on.
data NxtNqlApiExecuteRequest
    The data containing the NQL query.
method : Optional[str], optional
    The HTTP method to use for the request. Defaults to 'POST'.
Raises
ValueError
    If the specified HTTP method is not supported.
Returns
NqlResponseType
    The nql response object containing the response from the API call.

wait_status(value: NxtNqlApiExportResponse, timeout: int = 300) -> Union[NxtNqlApiStatusResponse, NxtErrorResponse]

Wait for the status of an NQL API export request to complete.

Parameters
value : NxtNqlApiExportResponse
    The export request to check the status of.
timeout : int, optional
    The maximum time to wait for the status to complete. Defaults to 300.
Returns
Union[NxtNqlApiStatusResponse, NxtErrorResponse]
    The final status response of the export request.

get_status_export(value: NxtNqlApiExportResponse) -> NqlResponseType

Retrieve the status of an export based on the provided NxtNqlApiExportResponse value.

Constructs the export status URL and makes a GET request to fetch the status. Converts the response to a NxtNqlStatus object and returns it.

Parameters
value : NxtNqlApiExportResponse
    The export response object containing export ID.
Returns
NqlResponseType
    The status of the export operation.

download_export(value: NxtNqlApiStatusResponse, timeout: int = 300) -> requests.models.Response

Download an export file based on the NxtNqlApiStatusResponse value and a timeout period.

Parameters
value : NxtNqlApiStatusResponse
    The status response object containing the export details.
timeout : int, optional
    The timeout period for the download request in seconds. Defaults to 300.
Returns
requests.models.Response
    The response object from the download request.

download_export_as_df(value: NxtNqlApiStatusResponse, timeout: int = 300) -> pd.DataFrame

Download an export file as a pandas DataFrame based on the NxtNqlApiStatusResponse value and a timeout period.

Parameters
value : NxtNqlApiStatusResponse
    The status response object containing the export details.
timeout : int, optional
    The timeout period for the download request in seconds. Defaults to 300.
Returns
pd.DataFrame
    The downloaded dataframe.

check_method(endpoint: NxtEndpoint, method: str) -> bool

Check if a given method is supported for a specific endpoint.

Parameters
endpoint : NxtEndpoint
    The endpoint to check the method for.
method : str
    The method to check.
Returns
bool
    True if the method is supported, False otherwise.

get(endpoint: NxtEndpoint, params=None) -> ResponseApiType

Send a GET request to the specified endpoint with optional query parameters.

Parameters
endpoint : NxtEndpoint
    The endpoint to send the request to.
params : Optional[Dict[str, Any]]
    Query parameters to include in the request. Defaults to None.
Returns
ResponseAPIType
    The response object containing the status of the request.
Raises
requests.exceptions.RequestException
    If there was an error sending the request.

post(endpoint: NxtEndpoint, data: Union[NxtTokenRequest, NxtEnrichmentRequest, NxtNqlApiExecuteRequest]) -> ResponseApiType

Send a POST request to the specified endpoint with the provided data.

Parameters
endpoint : (NxtEndpoint
    The endpoint to send the request to.
data : Union[NxtTokenRequest, NxtEnrichmentRequest, NxtNqlApiExecuteRequest])
    The data to be sent in the request.
Returns
 ResponseAPIType
    The response object containing the status of the POST request.