Maximo API Class
Maximo API class allows the user to communicate with Maximo REST API using python
Prerequisites:
Python > 3.7
Maximo access
- class MAXIMO_API.MAXIMO_REST(base_url, username=None, password=None, api_key=None, authentication_type='LDAP BASIC', max_attempts=1, timeout=None, mif=False, verbose=False, verify=True, logger=None)
- Parameters
maximo_url – (
string
) - Maximo URLusername – (
string
- optional) - Default value Nonepassword – (
string
- optional) - Default value Noneapi_key – (
string
- optional) - Default value Noneauthentication_type – (
string
- optional) - The only value supported LDAP BASIC (default value LDAP BASIC)max_attempts – (
int
- optional) - Maximum number of attempts if disconnected (default value 1)timeout – (
int
- optional) - Timeout threshold in seconds (default value None)mif – (
bool
- optional) - True if maximo_mif to be used, False if maximo to be used in the URL (default value False)verbose – (
bool
- optional) - Print internal messages if True (default value False)verify – (
bool
- optional) - By pass SSL verification if True (default value True)
- Returns
None
- add_param_to_url(url, param, value)
- authenticate(verbose=False)
Authenticate with Maximo using the defined authentication type used in the class constructor
- Parameters
verbose – (
bool
- optional) - Print internal messages if True (default value False).- Returns
None
- generate_base64(value)
Generate base64 string
- Parameters
value – (
string
) - String value to be converted to base64.- Returns
(
String
) - base64 string.
- get_mx_srs(select_fields='*', where=None, orderBy=None, gbcols=None, oslc=True, pageSize=100)
Execute query and get Service Requests.
- Parameters
select_fields – (
string
- optional) - Fields included in the query (defaul value *)where – (
string
- optional) - Where condition to be included in the query (defaul value None)orderBy – (
string
- optional) - Field(s) to order data (default value None). + sign indicated ascending and - sign indicates descendinggbcols – (
string
- optional) - Group by columns condition to aggregate data (default value None). See https://www.imwuc.org/HigherLogic/System/DownloadDocumentFile.ashx?DocumentFileKey=f29fb7ba-5917-f2a9-e599-9161e5d14582oslc – (
bool
- optional) - Defines whether to use oslc protocol or not (default value True)pageSize – (
int
- optional) - Page size for response (default value None). When default is used the default Maximo page size will be used (1000).
- Returns
(
tuple
- dict or string, string) - response (json or error string) and response status code.
- get_mx_wos(select_fields='*', where=None, orderBy=None, gbcols=None, oslc=True, pageSize=100)
Execute query and get WOs.
- Parameters
select_fields – (
string
- optional) - Fields included in the query (defaul value *)where – (
string
- optional) - Where condition to be included in the query (defaul value None)orderBy – (
string
- optional) - Field(s) to order data (default value None). + sign indicated ascending and - sign indicates descendinggbcols – (
string
- optional) - Group by columns condition to aggregate data (default value None). See https://www.imwuc.org/HigherLogic/System/DownloadDocumentFile.ashx?DocumentFileKey=f29fb7ba-5917-f2a9-e599-9161e5d14582oslc – (
bool
- optional) - Defines whether to use oslc protocol or not (default value True)pageSize – (
int
- optional) - Page size for response (default value None). When default is used the default Maximo page size will be used (1000).
- Returns
(
tuple
- dict or string, string) - response (json or error string) and response status code.
- mbo_create_new_record(tableName, parameters, verbose=False)
Create a new record in a specific table in Maximo.
- Parameters
tableName – (
string
) - Maximo table nameparameters – (
dict
) - Field names (dict keys) and values (dict values) to be insertedverbose – (
bool
- optional) - Print internal messages if True (default value False).
- Returns
(
tuple
- dict or string, string) - response (json or error string) and response status code.
- mbo_exec_method(tableName, tableID, method, method_parameters=None, verbose=False)
Execute a method on a specific MBO in Maximo.
- Parameters
tableName – (
string
) - Maximo table nametableID – (
int
) - Primary key record IDmethod – (
string
) - Name of the method to be executedmethod_parameters – (
dict
) - Method parametersverbose – (
bool
- optional) - Print internal messages if True (default value False).
- Returns
(
tuple
- dict or string, string) - response (json or error string) and response status code.
- mbo_get_table(tableName, includecols=None, excludecols=None, orderbyasc=None, orderbydesc=None, where=None, maxItems=None, format='json', compact=1, verbose=False, current_attempt=1)
Get data from a specific table in Maximo using REST API. https://maximo.bia.gov/help/index.jsp?topic=/com.ibm.mif.doc/gp_intfrmwk/rest_api/r_rest_post_method.html
- Parameters
tableName – (
string
) - Maximo table nameincludecols – (
string
- optional) - Comma-separated list of MBO attributes. Includes the listed attributes from the resource response (default value None).excludecols – (
string
- optional) - Comma-separated list of MBO attributes. Excludes the listed attributes from the resource response (default value None).orderbyasc – (
string
- optional) - Comma-separated list of MBO attributes. Specifies the attributes that are used for the order by clause in ascending order (default value None).orderbydesc – (
string
- optional) - Comma-separated list of MBO attributes. Specifies the attributes that are used for the order by clause in descending order (default value None).where – (
string
- optional) - Where condition to filter data (default value None).maxItems – (
int
- optional) - Specifies the maximum number of business objects that are serialized in the resource collection (default value None).format – (
string
- optional) - Specifies the representation of the resource response (default value json). Could be either json or xml.compact – (
int
- optional) - If true, JSON data is represented in a compact representation (default value 1).verbose – (
bool
- optional) - Print internal messages if True (default value False).current_attempt – (
int
- don’t use) - This argument is intended for internal method use only.
- Returns
(
tuple
- dict or string, string) - response (json or error string) and response status code.
- mbo_update_record(tableName, tableID, parameters, verbose=False)
Update specific record in a table in Maximo.
- Parameters
tableName – (
string
) - Maximo table nametableID – (
int
) - Primary key record ID to updateparameters – (
dict
) - Field names (dict keys) and values (dict values) to be updatedverbose – (
bool
- optional) - Print internal messages if True (default value False).
- Returns
(
tuple
- dict or string, string) - response (json or error string) and response status code.
- mxapi_get_request(url)
Execute get request.
- Parameters
url – (
string
) - URL to be executed in the get request.- Returns
(
requests.response
)
- mxapi_post_request(url, body=None, headers=None)
Execute get request.
- Parameters
url – (
string
) - URL to be executed in the post request.body – (
dict
- optional) - Body to be included in the POST request (default value None).headers – (
dict
- optional) - Additional headers to be added in the POST request (default value None).
- Returns
(
requests.response
)
- oslc_create_new_record(tableName, parameters, verbose=False)
Create a new record in a specific table in Maximo.
- Parameters
tableName – (
string
) - Maximo table nameparameters – (
dict
) - Field names (dict keys) and values (dict values) to be insertedverbose – (
bool
- optional) - Print internal messages if True (default value False).
- Returns
(
tuple
- dict or string, string) - response (json or error string) and response status code.
- oslc_get_table(tableName, pageSize=None, select=None, where=None, orderBy=None, pageNum=1, stablePaging=False, gbcols=None, verbose=False, current_attempt=1)
Get data from a specific table in Maximo using OSLC Integration.
- Parameters
tableName – (
string
) - Maximo table name to extract datapageSize – (
int
- optional) - Page size for response (default value None). When default is used the default Maximo page size will be used (1000).select – (
string
- optional) - Maximo table fields to be included in the select query (default value None).where – (
string
- optional) - Where condition to filter data (default value None). See https://www.ibm.com/docs/en/mam/7.6.0?topic=orq-query-where-clause-parameterorderBy – (
string
- optional) - Field(s) to order data (default value None). + sign indicated ascending and - sign indicates descendingpageNum – (
int
- optional) - Page number in the response (default value 1). Recommended to leave default.stablePaging – (
bool
- optional) - Use Maximo stable paging option (default value False). Recommended to leave default.gbcols – (
string
- optional) - Group by columns condition to aggregate data (default value None). See https://www.imwuc.org/HigherLogic/System/DownloadDocumentFile.ashx?DocumentFileKey=f29fb7ba-5917-f2a9-e599-9161e5d14582verbose – (
bool
- optional) - Print internal messages if True (default value False).current_attempt – (
int
- don’t use) - This argument is intended for internal method use only.
- Returns
(
tuple
- dict or string, string) - response (json or error string) and response status code.
- oslc_update_record(tableName, restID, parameters, use_oslc=True, verbose=False)
Update specific record in a table in Maximo
- Parameters
tableName – (
string
) - Maximo table namerestID – (
int
) - REST ID for the record to be updatedparameters – (
dict
) - Field names (dict keys) and values (dict values) to be updateduse_oslc – (
bool
- optional) - If True, url will use oslc. If False, url will use rest (default value True)verbose – (
bool
- optional) - Print internal messages if True (default value False)
- Returns
(
tuple
- dict or string, string) - response (json or error string) and response status code
- validate_and_return_response(response, message, raw=False, content=False)
Validate response by comparing it against the acceptable status codes. Returns response and status code.
- Parameters
response – (
requests.response
) - The response from the query.message – (
string
- optional) - Desired custom error message.raw – (
bool
- optional) - Defines whether to return response raw format or json (default value False).content – (
bool
- optional) - Defines whether to return response content or json (default value False).
- Returns
(
tuple
- dict or string, string) - response (json, raw or error string) and response status code.