TDX Integration¶
This class contains all the methods that work with the following TDX API endpoints:
- Authentication
- Locations
- Rooms
- People
- Groups
- Accounts
- Custom attributes
Class & Methods¶
This class is inherited by the ticket & asset integrations
-
class
tdxlib.tdx_integration.TDXIntegration(filename: str = None, config: dict = None)¶ -
auth() → bool¶ Internal method to authenticate to the TDX api using the selected method Stores a token in the token property, used for future calls. Returns true for success, false for failure.
-
clean_cache()¶ Internal method to refresh the cache in a tdxlib object.
-
create_account(name: str, manager: str, additional_info: dict = None, custom_attributes: dict = None) → dict¶ Creates an account in TeamDynamix.
Parameters: - name – Name of account to create.
- manager – email address of the TDX Person who will be the manager of the group
- additional_info – dict of other attributes to set on account. Retrieved from: https://api.teamdynamix.com/TDWebApi/Home/type/TeamDynamix.Api.Accounts.Account
- custom_attributes – dict of names of custom attributes and corresponding names of the choices to set on each attribute. These names must match the names in TDX, not IDs.
Returns: a dict with information about the created account
Return type: dict
-
create_room(location, name: str, external_id: str = None, description: str = None, floor: str = None, capacity: int = None, attributes: dict = None) → dict¶ Creates a room in a location in TDX.
Parameters: - location – Dict of location information (or ID), possibly from get_location_by_name()
- name – Name of new room
- external_id – External ID of new room as a string (optional)
- description – Description of new room as a string (optional)
- floor – Floor for new room as a string (optional)
- capacity – Capacity of the room, as an integer (optional)
- attributes – Dict of Custom Attributes (optional)
Returns: Dict with newly created room information
-
edit_account(name: str, changed_attributes: dict) → dict¶ Edits an account in TeamDynamix
Parameters: - name – Name of account to edit.
- changed_attributes – dict of names of attributes and corresponding data to set on each attribute.
Returns: a dict with information about the edited account
Return type: dict
-
get_account_by_id(account_id: int) → dict¶ Gets an account by the account ID.
Parameters: account_id – ID number of account to get information about Returns: dict of account data Return type: dict
-
get_account_by_name(key: str, additional_params: dict = None) → dict¶ Gets an account with by searching on its name.
Parameters: - key – a partial or full name of an account to search for
- additional_params – other search items, as a python dict, as described in TDX Api Docs
Returns: dict of account data (not complete, but including the ID)
Return type: dict
-
get_all_accounts() → list¶ Gets a list of all accounts in TDX
Returns: list of dicts containing account data Return type: list
-
get_all_custom_attributes(object_type: int, associated_type: int = 0, app_id: int = 0) → list¶ Gets all custom attributes for the component type in TDX. See https://solutions.teamdynamix.com/TDClient/KB/ArticleDet?ID=22203 for possible values.
Parameters: - object_type – the object type to get attributes for (tickets = 9, assets = 27, CI’s = 63)
- associated_type – the associated type of object to get attributes for, default: 0
- app_id – the application number to get attributes from, default: 0
Returns: list of dicts containing custom attributes, including choices and choice ID’s
Return type: list
-
get_all_groups() → list¶ Gets a list of all groups in TDX
Returns: list of dicts containing group data Return type: list
-
get_all_locations() → list¶ Gets all locations in TDX.
Returns: a list of dicts containing location information Return type: list
-
get_custom_attribute_by_name_id(key: str, object_type: int) → dict¶ Gets a custom attribute for the component type. See https://solutions.teamdynamix.com/TDClient/KB/ArticleDet?ID=22203 for possible values for component_type.
NOTE: The best way to assign CA’s is to test for an existing value (for choice-based CA’s) using get_custom_attribute_value_by_name, and then if it returns false, directly assign the desired value to the CA. Because of this, date-type and other format-specific attributes need to be in a TDX-acceptable format, this means that a field designated to hold person objects needs to be set to a UID.
Parameters: - key – a partial or full name of the custom attribute to search for
- object_type – the object type ID to get attributes for
Returns: the attribute as a dict, with all choice items included
Return type: dict
-
get_custom_attribute_choice_by_name_id(attribute, key)¶ Gets the choice item from a custom attribute, maybe from get_custom_attribute_by_name()
NOTE: The best way to assign CA’s is to test for an existing value (for choice-based CA’s), and then if this method returns false, directly assign the desired value to the CA. Because of this, date-type and other format specific attributes need to be in a TDX-acceptable format, this means that a field designated to hold person objects needs to be set to a UID.
Parameters: - key – a partial or full name of the choice to look for
- attribute – a dict of custom attribute data (as retrieved from get_attribute_by_name())
Returns: the the choice object from this attribute whose name matches ‘key’, or False if none matches.
Return type: dict
-
get_group_by_id(group_id: int) → dict¶ Gets a group by the group ID.
Parameters: group_id – ID number of group to get information about Returns: dict of group data, including members Return type: dict
-
get_group_by_name(key: str, additional_params=None) → dict¶ Gets a group by searching on its name.
Parameters: - key – a partial or full name of Group to search for
- additional_params – other search items, as a dict, as described in TDX Api Docs
Returns: a dict of group data (not complete, but including the ID)
Return type: dict
-
get_group_members_by_id(group_id: int) → list¶ Gets a list of group members by the group ID.
Parameters: group_id – ID number of group to get members of Returns: list of person data for people in the group Return type: list
-
get_group_members_by_name(key: str) → list¶ Gets all the members of a group as person objects by searching on the group’s name.
Parameters: key – a partial or full name of a group Returns: list of group members Return type: list
-
get_location_by_id(location_id: int) → dict¶ Gets a location by the location ID.
Parameters: location_id – ID number of location to get information about Returns: dict of location data Return type: dict
-
get_location_by_name(key: str, additional_params: dict = None) → dict¶ Gets a location by searching its name.
Parameters: - key – a partial or full name of the location to search for
- additional_params – other search items, as a dict, as described in TDX Api Docs
Returns: a dict of location data
Return type: dict
-
get_person_by_name_email(key: str) → dict¶ Gets the top match of people with based on a simple text search, such as: - Name - Email - Username - Organizational ID
Parameters: key – string with search text of person to search with Returns: dict of person data Return type: dict
-
get_person_by_uid(uid: str) → dict¶ Gets a person by their UID.
Parameters: uid – UID string corresponding to a person Returns: dict of person data Return type: dict
-
static
get_room_by_name(location: dict, room: str) → dict¶ Gets a room by searching its name in location information, maybe from get_location_by_name().
Parameters: - location – dict of location info
- room – partial or full name of a room to search for
Returns: a dict with all the information regarding the room. Use this to retrieve the ID attribute.
Return type: dict
-
get_tdx_item_by_id(obj_type: str, key)¶ A generic function to get something from the TDX API using its ID/UID.
Since the TDX API endpoints are almost all in the form /<object type>/id, this method gives an easy way to template all the different get_<object>_by_id methods.
Parameters: - obj_type – the type of object to get.
- key – the ID number of an object to get, as a string
Returns: list of person data
-
make_delete(request_url: str)¶ Makes an HTTP DELETE request to the TDX Api.
Parameters: request_url – the path (everything after /TDWebAPI/api/) to call Returns: None
-
make_file_post(request_url: str, file: BinaryIO, filename: str = None)¶ Makes an HTTP POST request to the TDX Api with a Multipart-Encoded File
Parameters: - request_url – the path (everything after /TDWebApi/api/) to call
- file – BinaryIO object opened in read mode to upload as attachment.
(read documentation at requests.readthedocs.io/en/master/user/quickstart/#post-a-multipart-encoded-file) :param filename: (optional), allows to explicitly specify filename header. If None, requests will determine from passed-in file object. This is useful for if you want to upload a file in memory without a filename, which is required for uploading to TeamDynamix.
Returns: the API’s response as a python dict
-
make_get(request_url: str, retries: int = 3)¶ Makes an HTTP GET request to the TDX Api.
Parameters: - request_url – the path (everything after /TDWebAPI/api/) to call
- retries – the number of times to retry a failed request (defaults to 3)
Returns: the API’s response as a python dict or list
-
make_patch(request_url: str, body: dict)¶ Makes an HTTP PATCH request to the TDX API.
The TeamDynamix API supports limited PATCH functionality. Since TDX data is highly structured, items are referenced explicitly by their TDX ID, and not by their order in the object. Likewise, since the fields in a TDX object are all predefined, a PATCH call cannot add or remove any fields in the object.
Parameters: - request_url – the path (everything after /TDWebAPI/api/) to call
- body – a list of PATCH operations as dictionaries, each including the keys “op”, “path”, and “value”
Returns: the API’s response, as a python dict or list
-
make_post(request_url: str, body: dict)¶ Makes an HTTP POST request to the TDX Api
Parameters: - request_url – the path (everything after /TDWebAPI/api/) to call
- body – dumped JSON data to send with the POST
Returns: the API’s response as a python dict or list
-
make_put(request_url: str, body: dict)¶ Makes an HTTP PUT request to the TDX API.
Parameters: - request_url – the path (everything after /TDWebAPI/api/) to call
- body – dumped JSON data to send with the PUT
Returns: the API’s response as a python dict or list
-
search_people(key: str, max_results: int = 20) → list¶ Gets a list of people, based on a simple text search, which may match Name, Email, Username or ID
Parameters: - key – string with search text of person to search with
- max_results – maximum number of matches to return (Default: 20)
Returns: list of dicts of person data
Return type: list
-