This module is used to interact with the Xurrent API. It provides a set of classes to interact with the API.
fromxurrent.coreimportXurrentApiHelperapitoken="********"baseUrl="https://api.xurrent.qa/v1"account="account-name"x_api_helper=XurrentApiHelper(baseUrl, apitoken, account)
# change log level (default: INFO)x_api_helper.set_log_level("DEBUG")
# Plain API Calluri="/requests?subject=Example Subject"x_api_helper.api_call(uri, 'GET')
# Convert node IDx_api_helper.decode_api_id('ZmFiaWFuc3RlaW5lci4yNDEyMTAxMDE0MTJANG1lLWRlbW8uY29tL1JlcS83MDU3NTU') # fabiansteiner.241210101412@4me-demo.com/Req/705755# this can be used to derive the ID from the nodeIDYou can let the helper automatically request and refresh bearer tokens by providing the OAuth
client_id and client_secret that were issued to your application. The original API key flow
continues to work unchanged, but only one authentication method may be used per helper instance.
fromxurrent.coreimportXurrentApiHelperbaseUrl="https://api.xurrent.qa/v1"account="account-name"client_id="your-client-id"client_secret="your-client-secret"x_api_helper=XurrentApiHelper(
baseUrl,
api_account=account,
client_id=client_id,
client_secret=client_secret,
)
response=x_api_helper.api_call("/requests", "GET")# Example usage of ConfigurationItem classfromxurrent.configuration_itemsimportConfigurationItem# Get a Configuration Item by IDci=ConfigurationItem.get_by_id(x_api_helper, <id>)
print(ci)
# List all Configuration Itemsall_cis=ConfigurationItem.get_configuration_items(x_api_helper)
print(all_cis)
# List active Configuration Itemsactive_cis=ConfigurationItem.get_configuration_items(x_api_helper, predefinedFilter="active")
print(active_cis)
# Update a Configuration Itemupdated_ci=ci.update({"name": "Updated Name", "status": "being_repaired"})
print(updated_ci)
# Create a new Configuration Item# creating without specifying the label, takes the last ci of the product and increments the label# example: "wdc-02" -> "wdc-03"data= {"name": "New CI", "type": "software", "status": "in_production", "product_id": "<product_id>"}
new_ci=ConfigurationItem.create(x_api_helper, data)
print(new_ci)
# Archive a Configuration Item (must be in an allowed state)try:
archived_ci=ci.archive()
print(archived_ci)
exceptValueErrorase:
print(f"Error: {e}")
# Trash a Configuration Item (must be in an allowed state)try:
trashed_ci=ci.trash()
print(trashed_ci)
exceptValueErrorase:
print(f"Error: {e}")
# Restore a Configuration Itemrestored_ci=ci.restore()
print(restored_ci)fromxurrent.peopleimportPersonpeople=Person.get_by_id(x_api_helper, <id>)
api_user=Person.get_me(x_api_helper)
# get all people with a specific subjectpeople=Person.get_people(x_api_helper,queryfilter={
"name": "Werner"
})
# enablepeople.enable()
#disablepeople.disable()
#archivepeople.archive()
#trashpeople.trash()
#restorepeople.restore()fromxurrent.requestsimportRequestrequest=Request.get_by_id(x_api_helper, <id>)
# get all requests with a specific subjectrequests=Request.get_request(x_api_helper,queryfilter={
"subject": "Example Subject"
})
# closerequest.close("closed")
# archiverequest.archive()
#trashrequest.trash()
#restorerequest.restore()fromsrc.xurrent.requestsimportRequest# Get Configuration Items for a Requestrequest_id=<request_id># Add a Configuration Item to a Requestci_id=<ci_id>try:
response=Request.add_ci_to_request_by_id(x_api_helper, request_id, ci_id)
print("CI added:", response)
exceptValueErrorase:
print(f"Error: {e}")
cis=Request.get_cis_by_request_id(x_api_helper, request_id)
print(cis)
# Remove a Configuration Item from a Requesttry:
response=Request.remove_ci_from_request_by_id(x_api_helper, request_id, ci_id)
print("CI removed:", response)
exceptValueErrorase:
print(f"Error: {e}")
# Instance-based examplereq=Request.get_by_id(x_api_helper, request_id)
# Add a CI to this requesttry:
response=req.add_ci(ci_id)
print("CI added:", response)
exceptValueErrorase:
print(f"Error: {e}")
# Get CIs for this requestcis_instance=req.get_cis()
print(cis_instance)
# Remove a CI from this requesttry:
response=req.remove_ci(ci_id)
print("CI removed:", response)
exceptValueErrorase:
print(f"Error: {e}")fromxurrent.requestsimportRequestrequest=Request.get_by_id(x_api_helper, <id>)
request_note=request.get_by_id(x_api_helper, <id>)
# get all request notes with a specific subjectrequest_notes=request.get_notes(x_api_helper, predefinedFilter="public")
request.add_note("This is a test note")
request.add_note({
"text": "This is a test note",
"internal": True
})fromxurrent.tasksimportTasktask=Task.get_by_id(x_api_helper, <id>)
# get all tasks with a specific subjecttasks=Task.get_task(x_api_helper,queryfilter={
"subject": "Example Subject"
})
# get workflow of task (use expand: True to get the full workflow object)workflow=task.get_workflow(expand=True)
# or staticallyworkflow=Task.get_workflow_by_template_id(x_api_helper, <id>, expand=True)
# closetask.close()
#canceltask.cancel() # only possible before the task is started#rejecttask.reject()
#approvetask.approve()fromxurrent.teamsimportTeamteam=Team.get_by_id(x_api_helper, <id>)
# get all teams with a specific subjectteams=Team.get_team(x_api_helper,predifinedFilter="enabled")
# enableteam.enable()
#disableteam.disable()
#archiveteam.archive()
#trashteam.trash()
#restoreteam.restore()fromxurrent.workflowsimportWorkflowworkflow=Workflow.get_by_id(x_api_helper, <id>)
#closeworkflow.close() # completion reason: completed, note: closed# close with completion reasonworkflow.close(completion_reason="withdrawn")
#close with completion reason and noteworkflow.close(completion_reason="withdrawn", note="This is a test note")importcsvimportio#Request a bulk export of "people"csvdata=x_api_helper.bulk_export("people")
#Iterate fetched export rows with the csv library, where row 1 defines the column namesforrowincsv.DictReader(io.StringIO(csvdata)):
print(row["Employee Number"])