API Client#

Summary

The ApiClient is responsible for most API calls. Exceptions to this are any API calls interacting with AccessTokens, and calls made during the initial Setup.

class ApiClient(config: ConfigManager)[source]#

Provides methods for interacting with the Jamf API, specifically fetching patch data, device information, and OS versions.

The ApiClient manages authentication and session handling, ensuring efficient and secure communication with the Jamf API.

Initializes the ApiClient with the provided ConfigManager.

This sets up the API client with necessary credentials and session parameters for interacting with the Jamf API.

See also

jamf_client

Parameters:

config (ConfigManager) – Instance of ConfigManager for loading and storing credentials.

Raises:

ValueError – If the JamfClient configuration is invalid.

convert_timezone(utc_time_str: AnyStr) AnyStr | None[source]#

Converts a UTC time string to a formatted string without timezone information.

Parameters:

utc_time_str (AnyStr) – UTC time string in ISO 8601 format (e.g., “2023-08-09T12:34:56+0000”).

Returns:

Formatted date string (e.g., “Aug 09 2023”) or None if the input format is invalid.

Return type:

Optional[AnyStr]

Example:

formatted_date = api_client.convert_timezone("2023-08-09T12:34:56+0000")
print(formatted_date)   # Outputs: "Aug 09 2023"

Note

This function is primarily used ‘privately’ by methods and classes and is not designed to be called explicitly.

async fetch_json(url: AnyStr, session: ClientSession) Dict | None[source]#

Asynchronously fetches JSON data from a specified URL using a session.

Parameters:
  • url (AnyStr) – URL to fetch the JSON data from.

  • session (aiohttp.ClientSession) – An aiohttp.ClientSession instance used to make the request.

Returns:

JSON data as a dictionary or None if an error occurs.

Return type:

Optional[Dict]

Example:

async with aiohttp.ClientSession() as session:
    json_data = await api_client.fetch_json("https://api.example.com/data", session)
    if json_data:
        print(json_data)
async fetch_batch(urls: List) List[Dict | None][source]#

Fetches JSON data in batches to respect the concurrency limit. Data is fetched from each URL in the provided list, ensuring that no more than max_concurrency requests are sent concurrently.

Parameters:

urls (List[AnyStr]) – List of URLs to fetch data from.

Returns:

A list of JSON dictionaries or None for URLs that fail to retrieve data.

Return type:

List[Optional[Dict]]

async get_policies() List | None[source]#

Retrieves a list of patch software title IDs from the Jamf API. This function requires a valid authentication token, which is managed automatically.

Returns:

A list of software title IDs or None if an error occurs.

Return type:

Optional[List]

async get_summaries(policy_ids: List) List[PatchTitle] | None[source]#

Retrieves patch summaries for the specified policy IDs from the Jamf API. This function fetches data asynchronously and compiles the results into a list of PatchTitle objects.

Parameters:

policy_ids (List) – List of policy IDs to retrieve summaries for.

Returns:

List of PatchTitle objects containing patch summaries or None if an error occurs.

Return type:

Optional[List[PatchTitle]]

async get_device_ids() List[int] | None[source]#

Asynchronously fetches the list of mobile device IDs from the Jamf Pro API. This method is only called if the iOS option is passed to the CLI.

Returns:

A list of mobile device IDs or None on error.

Return type:

Optional[List[int]]

async get_device_os_versions(device_ids: List[int]) List[Dict] | None[source]#

Asynchronously fetches the OS version and serial number for each device ID provided. This method is only called if the iOS option is passed to the CLI.

Parameters:

device_ids (List[int]) – A list of mobile device IDs to retrieve information for.

Returns:

A list of dictionaries containing the serial numbers and OS versions, or None on error.

Return type:

Optional[List[Dict[AnyStr, AnyStr]]]

get_sofa_feed() List[Dict] | None[source]#

Fetches iOS Data feeds from SOFA and extracts latest OS version information. To limit the amount of possible SSL verification checks, this method utilizes a subprocess call instead. This method is only called if the iOS option is passed to the CLI.

Returns:

A list of dictionaries containing base OS versions, latest iOS versions and release dates, or None on error.

Return type:

Optional[List[Dict[AnyStr, AnyStr]]]