QPR ProcessAnalyzer API: Difference between revisions

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search
 
(65 intermediate revisions by the same user not shown)
Line 1: Line 1:
QPR ProcessAnalyzer API's can be used to automate operations in process mining or create integration with other applications. QPR ProcessAnalyzer has two API:
QPR ProcessAnalyzer API can be used to build integrations with other applications and automate operations in the process mining system.
* '''Web API''': REST-based API used by the web UI.
* '''WCF API''': Older API used by the Excel Client and ScriptLauncher.


Prefer the Web API, because WCF API is a legacy API that will be removed in future.
QPR ProcessAnalyzer API is a JSON based API following the REST design principles. All methods (except the [[Web_API:_Token|token]] and [[Web_API:_Serverinfo|serverinfo]]) require a prior login to establish a session. The session is initialized with the [[Web_API:_Token|token]] call with username and password, and the access token is returned as a response for a successful login. The methods requiring prior authenticated session, need to have a HTTP request header ''Authorization'' with value ''Bearer <access token>'' to identify the session.


== Web API ==
Url for calling the API has the following form (replace the server hostname with a correct one):
The Web API uses JSON and it's based on the REST design principles. All operations require a login which is done with the ''Token'' operation with username and password. All operations (except the Token) need to have a HTTP request header ''Authorization'' with value ''Bearer <access token>'' in place to identify the session.
 
Url for calling the API has the following form (replace the DNS name with a correct one):
<pre>
<pre>
https://customer.onqpr.com/qprpa/api/<operationName>
https://customer.onqpr.com/qprpa/api/<methodName>
</pre>
</pre>


Following operations is available:
Following methods are available:
* [[Web_API:_Token|token]]: Login user using username and password, and get a session token as a response.
{| class="wikitable"
* [[Web_API:_Signout|signout]]: Logs out a session.
!'''Method'''
* [[Web_API:_Analysis|analysis]]: Run query in the server and returns results as a response.
! '''Description'''
* [[Web_API:_Cancel|cancel]]: Cancels currently running operation.
|-
* [[Web_API:_Filters|Filters]]: Get all filters in system or filters in a model.
||[[Web_API:_Token|token]]
* [[Web_API:_Serverinfo|serverinfo]]: Gets the default UI language in whether SSO has been configured.
||Login user using username and password and get a session token as a response.
* [[Web_API:_Importfile|importfile]]: Import data into models and datatables from .csv, .xes and .pacm files.
|-
* [[Web_API:_Usersettings|usersettings]]: Save user specific settings to the server.
||[[Web_API:_Signout|api/signout]]
||Logs out a user session.
|-
||[[Web_API:_Expression|api/expression]]
||Runs an expression.
|-
||[[Web_API:_Expression/query|api/expression/query]]
||Runs query written using the expression language and returns result data as response.
|-
||[[Web_API:_Filters|api/filters]]
||Get filters for all models or filters for a single model.
|-
||[[Web_API:_Serverinfo|api/serverinfo]]
||Returns common system information needed by UI, such as the default UI language and in whether SSO has been configured.
|-
||[[Web_API:_Importfile|api/importfile]]
||Import data into datatable from .csv, .xes or .pacm file.
|-
||[[Web_API:_Usersettings|api/usersettings]]
||Save user specific settings to the server.
|-
||[[Web_API:_Operations/terminate|api/operations/terminate]]
||Stops the defined tasks (by the task id) to save computing resources.
|-
||[[Web_API:_Cancel|api/analysis/cancel]]
||Stops currently running tasks (by the task identifier) to save computing resources.
|-
||[[Web_API:_saml2/acs|api/saml2/acs]]
||Identity provider (IdP) will send the SAML 2.0 assertion to this endpoint, which responses with 302 to redirect to QPR ProcessAnalyzer UI.
|-
||[[Web_API:_saml2|api/saml2]]
||Returns the SAML 2.0 service provider (SP) metadata, if SAML 2.0 authentication has been configured.
|}
 
In addition, there are methods for
* [[Web API for Workspace Elements|moving and deleting workspace elements]]
* [[Web_API_for_Projects|projects]]
* [[Web_API_for_Dashboards|dashboards]]
* [[Web_API_for_Models|models]]
* [[Web_API_for_Datatables|datatables]]
* [[Web_API_for_Scripts|scripts]]
* [[Web_API_for_User_Management|users, groups and roles]]


In addition, there are Web API operations [[Web_API_for_Datatables|datatables]] and [[Web_API_for_User_Management|user management]].
== Examples ==
=== Trigger script run ===
Following function written in Python starts a script in QPR ProcessAnalyzer by calling the REST API. The function does following: (1) login to QPR ProcessAnalyzer, (2) start the script, and (3) log out. The call just starts the script without waiting for it to complete (asynchronous behavior).


== WCF API ==
<syntaxhighlight lang="python" line>
All WCF API operations only accept HTTP POST method (HTTP GET is not allowed). WCF API can be used with ''wsHttp'' (SOAP) and ''webHttp'' endpoints.
def startQprProcessAnalyzerScript(serverUrl: str, username: str, password: str, scriptId: int):
  loginData = {
    "grant_type": "password",
    "username": username,
    "password": password
  }
  loginResponse = requests.post(
    url = serverUrl + "/token",
    data = loginData
  )
  loginResponse.raise_for_status()
  sessionToken = loginResponse.json().get("access_token")
 
  startScriptResponse = requests.post(
    url = serverUrl + "/api/scripts/run/" + str(scriptId),
    headers = {
      "Authorization": "Bearer " + sessionToken,
      "Content-type": "application/json"
    }
  )
  startScriptResponse.raise_for_status()


The following methods are available in the WCF API:
  logOutResponse = requests.post(
* [[QPR ProcessAnalyzer API: Authenticate|Authenticate]]: Tries to authenticate given user with given password and authentication parameters.
    url = serverUrl + "/api/signout",
* [[QPR ProcessAnalyzer API: DeleteModel|DeleteModel]]: Deletes a model.
    headers = {
* [[QPR ProcessAnalyzer API: GetAnalysis|GetAnalysis]]: Calculates and returns QPR ProcessAnalyzer analysis.
      "Authorization": "Bearer " + sessionToken,
* [[QPR ProcessAnalyzer API: GetAnalysisImageAsByteArray|GetAnalysisImageAsByteArray]]: Get [[Flowchart_Analysis|Flowchart Analysis]] as image.
      "Content-type": "application/json"
* [[QPR ProcessAnalyzer API: GetModel|GetModel]]: Can be used to query QPR ProcessAnalyzer model data.
    }
* [[QPR ProcessAnalyzer API: GetModels|GetModels]]: Can be used to query QPR ProcessAnalyzer model related information.
  )
* [[QPR ProcessAnalyzer API: GetModelAsStream|GetModelAsStream]]: Exports a model or a filtered data as a .pacm file.
  logOutResponse.raise_for_status()
* [[QPR ProcessAnalyzer API: GetStream|GetStream]] can be used to query contents of a stream bound to the given session identified by given stream id.
</syntaxhighlight>
* [[QPR ProcessAnalyzer API: LogOff|LogOff]]: Logs off the user session.
* [[QPR ProcessAnalyzer API: RunScript|RunScript]] can be used to execute given PA script using given parameters.
* [[QPR ProcessAnalyzer API: SetModel|SetModel]]: Can be used to set model related information.


== WCF API Usage Examples ==
The function can be called as follows:
=== JavaScript Examples ===
<syntaxhighlight lang="python" line>
<pre>
startQprProcessAnalyzerScript(
//login               
   serverUrl = "https://server.onqpr.com/qprpa",
$.ajax({
   username = "qpr",
   "method": "POST",
   password = "demo",
  "url": "http://localhost/qprpa/Mainservice.svc/webHttp/Authenticate",
   scriptId = 1
   "dataType": "json", "contentType": "application/json; charset=utf-8",
)
   "data": JSON.stringify({
</syntaxhighlight>
    'logOnName': '<username>',
The script id can be found in the scripts list in the Workspace.
    'password': '<password>',
    'parameters': ''
   })
});                     
</pre>


<pre>
=== Synchronize users and groups ===
//create user
Following script written in Python updates QPR ProcessAnalyzer users and groups based on the provided dataset. This script can be extended to fetch the user data from an external source (e.g., Azure AD) to implement a complete user management integration between the systems.
$.ajax({
  "method": "POST",
  "url": "http://localhost/qprpa/Mainservice.svc/webHttp/SetUser",
  "dataType": "json", "contentType": "application/json; charset=utf-8",
  "data": JSON.stringify({
    "sessionId": sessionId,
    "user": {"Name": "user", "FullName": "first last" },
    "parameters": [{"Key": "Password", "Value": "demo"}]
  })
});
</pre>


<pre>
This script performs following steps:
//add user to group, value 8:12:0 is user:group:member type
# Read the provided dataset and store it to in-memory structures.
$.ajax({
# Read all users from QPR ProcessAnalyzer (including which groups the users belong to). (POST /api/expression/query)
  "method": "POST",
# Read all groups from QPR ProcessAnalyzer. (POST /api/expression/query)
  "url": "http://localhost/qprpa/Mainservice.svc/webHttp/ModifyUserRelations",
# Determine the gap between the current state in the user management and the provided dataset.
  "dataType": "json", "contentType": "application/json; charset=utf-8",
# Create new users appearing in the dataset to QPR ProcessAnalyzer. (POST /api/users)
  "data": JSON.stringify({
# Inactivate non-existing users in the dataset from QPR ProcessAnalyzer. (PUT /api/users)
    "sessionId": sessionId,
# Activate existing inactive users in QPR ProcessAnalyzer that exist in the dataset. (PUT /api/users)
    "parameters": [{"Key": "AddGroups", "Value": "8:12:0"}]
# Add users to groups and remove from groups based on the determined gap in the state. (PUT/DELETE /api/users/memberships)
  })
});
</pre>


Users are queried as follows:
<pre>
<pre>
//log off
{
$.ajax({
  "Dimensions": null,
  "method": "POST",
  "Values": [
  "url": "http://localhost/qprpa/Mainservice.svc/webHttp/LogOff",
      {
  "dataType": "json", "contentType": "application/json; charset=utf-8",
        "Name": "Id",
  "data": JSON.stringify({  
        "Expression": "Id"
    "sessionId": sessionId
      },
  })
      {
});
        "Name": "Name",
        "Expression": "Name"
      },
      {
        "Name": "IsActive",
        "Expression": "IsActive"
      },
      {
        "Name": "Groups",
        "Expression": "ToJson(OrderByValue(Groups.Id))"
      }
  ],
  "Root": "Users",
  "ContextType": "generic"
}
</pre>
</pre>


=== PowerShell Examples ===
Groups are queried as follows:
==== [[Move Data from QPR ProcessAnalyzer to Database using PowerShell]] ====
==== List Users ====
<pre>
<pre>
$paService=New-WebServiceProxy –Uri "http://localhost/qprpa/MainService.svc"
{
$connection=$paService.Authenticate("username", "password", @())
  "Dimensions": null,
$token=$connection.GetValue(0).Value
  "Values": [
 
      {
$param=@()
        "Name": "Id",
$users=$paService.GetUsers($token, $null, $param)
        "Expression": "Id"
$users
      },
$paService | get-member | ? {$_.definition -match "GetAnalysis"}
      {
        "Name": "Name",
        "Expression": "Name"
      }
  ],
  "Root": "UserGroups",
  "ContextType": "generic"
}
</pre>
</pre>


==== Update Model Configuration ====
Request /api/users/memberships body:
<pre>
<pre>
$paService=New-WebServiceProxy –Uri "http://localhost/qprpa/MainService.svc"
{
$connection=$paService.Authenticate("username", "password", @())
  "GroupId": 1,
$token=$connection.GetValue(0).Value
  "MemberId": 2,
$param=@()
  "RoleName": "Member"
$modelId=@(2)
}
$model=$paService.GetModels($token,$modelId, $param)
 
$model[0]
$model[0].ConfigurationJson = "{}"
 
$paService.SetModel($token,$model[0], $param)
</pre>
</pre>


==== Get Flowchart Image ====
<syntaxhighlight lang="python" line>
<pre>
...
$paService=New-WebServiceProxy –Uri "http://localhost/qprpa/MainService.svc" -Namespace "WebServiceProxy" -Class "PaService"
</syntaxhighlight>
$connection=$paService.Authenticate("username", "password", @())
$token=$connection.GetValue(0).Value
 
$ids = new-object WebServiceProxy.ModelViewId
$ids.ViewId = 13
$ids.ViewIdSpecified = 1
 
$analysisType = 0
$processAnalysisType = 4
$minTransitionPercentage = 0.0
 
$png=  $paService.GetAnalysisImageAsByteArray($token, $ids,  $analysisType,1,  $processAnalysisType,1 , $minTransitionPercentage,1)
[IO.File]::WriteAllBytes('c:\tmp\image.png', $png)
</pre>


__NOTOC__
__NOTOC__


[[Category: QPR ProcessAnalyzer]]
[[Category: QPR ProcessAnalyzer]]

Latest revision as of 19:04, 13 October 2024

QPR ProcessAnalyzer API can be used to build integrations with other applications and automate operations in the process mining system.

QPR ProcessAnalyzer API is a JSON based API following the REST design principles. All methods (except the token and serverinfo) require a prior login to establish a session. The session is initialized with the token call with username and password, and the access token is returned as a response for a successful login. The methods requiring prior authenticated session, need to have a HTTP request header Authorization with value Bearer <access token> to identify the session.

Url for calling the API has the following form (replace the server hostname with a correct one):

https://customer.onqpr.com/qprpa/api/<methodName>

Following methods are available:

Method Description
token Login user using username and password and get a session token as a response.
api/signout Logs out a user session.
api/expression Runs an expression.
api/expression/query Runs query written using the expression language and returns result data as response.
api/filters Get filters for all models or filters for a single model.
api/serverinfo Returns common system information needed by UI, such as the default UI language and in whether SSO has been configured.
api/importfile Import data into datatable from .csv, .xes or .pacm file.
api/usersettings Save user specific settings to the server.
api/operations/terminate Stops the defined tasks (by the task id) to save computing resources.
api/analysis/cancel Stops currently running tasks (by the task identifier) to save computing resources.
api/saml2/acs Identity provider (IdP) will send the SAML 2.0 assertion to this endpoint, which responses with 302 to redirect to QPR ProcessAnalyzer UI.
api/saml2 Returns the SAML 2.0 service provider (SP) metadata, if SAML 2.0 authentication has been configured.

In addition, there are methods for

Examples

Trigger script run

Following function written in Python starts a script in QPR ProcessAnalyzer by calling the REST API. The function does following: (1) login to QPR ProcessAnalyzer, (2) start the script, and (3) log out. The call just starts the script without waiting for it to complete (asynchronous behavior).

def startQprProcessAnalyzerScript(serverUrl: str, username: str, password: str, scriptId: int):
  loginData = {
    "grant_type": "password",
    "username": username,
    "password": password
  }
  loginResponse = requests.post(
    url = serverUrl + "/token",
    data = loginData
  )
  loginResponse.raise_for_status()
  sessionToken = loginResponse.json().get("access_token")
  
  startScriptResponse = requests.post(
    url = serverUrl + "/api/scripts/run/" + str(scriptId),
    headers = {
      "Authorization": "Bearer " + sessionToken,
      "Content-type": "application/json"
    }
  )
  startScriptResponse.raise_for_status()

  logOutResponse = requests.post(
    url = serverUrl + "/api/signout",
    headers = {
      "Authorization": "Bearer " + sessionToken,
      "Content-type": "application/json"
    }
  )
  logOutResponse.raise_for_status()

The function can be called as follows:

startQprProcessAnalyzerScript(
  serverUrl = "https://server.onqpr.com/qprpa",
  username = "qpr",
  password = "demo",
  scriptId = 1
)

The script id can be found in the scripts list in the Workspace.

Synchronize users and groups

Following script written in Python updates QPR ProcessAnalyzer users and groups based on the provided dataset. This script can be extended to fetch the user data from an external source (e.g., Azure AD) to implement a complete user management integration between the systems.

This script performs following steps:

  1. Read the provided dataset and store it to in-memory structures.
  2. Read all users from QPR ProcessAnalyzer (including which groups the users belong to). (POST /api/expression/query)
  3. Read all groups from QPR ProcessAnalyzer. (POST /api/expression/query)
  4. Determine the gap between the current state in the user management and the provided dataset.
  5. Create new users appearing in the dataset to QPR ProcessAnalyzer. (POST /api/users)
  6. Inactivate non-existing users in the dataset from QPR ProcessAnalyzer. (PUT /api/users)
  7. Activate existing inactive users in QPR ProcessAnalyzer that exist in the dataset. (PUT /api/users)
  8. Add users to groups and remove from groups based on the determined gap in the state. (PUT/DELETE /api/users/memberships)

Users are queried as follows:

{
   "Dimensions": null,
   "Values": [
      {
         "Name": "Id",
         "Expression": "Id"
      },
      {
         "Name": "Name",
         "Expression": "Name"
      },
      {
         "Name": "IsActive",
         "Expression": "IsActive"
      },
      {
         "Name": "Groups",
         "Expression": "ToJson(OrderByValue(Groups.Id))"
      }
   ],
   "Root": "Users",
   "ContextType": "generic"
}

Groups are queried as follows:

{
   "Dimensions": null,
   "Values": [
      {
         "Name": "Id",
         "Expression": "Id"
      },
      {
         "Name": "Name",
         "Expression": "Name"
      }
   ],
   "Root": "UserGroups",
   "ContextType": "generic"
}

Request /api/users/memberships body:

{
  "GroupId": 1,
  "MemberId": 2,
  "RoleName": "Member"
}
...