I was annoyed to refill a form everytime to test a process so I've built something quick in Excel VBA
Calling PostOfferta() you can login and instantiate a process adapting the code to you process definition.
Hope this helps :
Ciao Alberto
Public Const BonitaSession = "X-Bonita-API-Token"
Public Const urlServerPath = "http://localhost:8080/bonita"
Public Type JsonData
KeyName As String
KeyValue As String
End Type
Sub PostOfferta()
Dim xmlhttp As New MSXML2.xmlhttp, myurl As String
JS = GetLoginSession()
DoEvents
ProcessId = GetProcessId("Richiesta utilizzo macchine") 'GetProcessId("Gestione Offerte di Vendita")
myurl = urlServerPath + "/API/bpm/process/" + ProcessId + "/instantiation"
xmlhttp.Open "POST", myurl, False
xmlhttp.setRequestHeader "Content-type", "application/json"
xmlhttp.setRequestHeader BonitaSession, JS
URL = "www.google.it" 'https://radar-test.celadagroup.com/wp-admin/admin-ajax.php?lang=it&action=b4y_crm_ws_get_pdf_quotation_v002"ationId=2a0f45bb-dda3-49e6-ac67-08d7f110e6d0&rnd=nTc8UHUWr6YnyQdaRobmzU34wZongTuD
json = "{ 'quotationEntityInput' : { 'QuotationId' : 'QUO-0001-2020', 'CustomerId' : '1003713', 'CustomerName' : 'LUXOTTICA S.R.L.', 'HasSpecialItem' : true, 'GrossAmount' : 1000000, 'NetAmount' : 975000, 'Discount' : 25000, 'SalesmanId' : '201244', 'SalesmanName' : 'MURADOR DAVIDE', 'Version' : '2000647' , 'URLQuotation' : '" + URL + "' }}"
json = Replace(json, "'", Chr(34))
xmlhttp.send (json)
DoEvents
result = xmlhttp.responseText
MsgBox (result)
End Sub
Public Sub httpclient()
Dim xmlhttp As New MSXML2.xmlhttp, myurl As String
myurl = urlServerPath + "/loginservice"
xmlhttp.Open "POST", myurl, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send "username=alberto.bernasconi@celadagroup.com&redirect=false&password=bpm"
strCookie = xmlhttp.getAllResponseHeaders()
jsessionidCookie = GetJsessionIdCookie(strCookie)
' MsgBox (xmlhttp.responseText)
myHeader = xmlhttp.getResponseHeader("X-Bonita-API-Token")
MsgBox (jsessionidCookie)
End Sub
Public Function GetLoginSession()
Dim xmlhttp As New MSXML2.xmlhttp, myurl As String
myurl = urlServerPath + "/loginservice"
xmlhttp.Open "POST", myurl, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send "username=alberto.bernasconi&redirect=false&password=bpm"
strCookie = xmlhttp.getAllResponseHeaders()
SessionId = Split(strCookie, Chr(13))(2)
jsessionidCookie = Split(Mid(SessionId, InStr(SessionId, BonitaSession) + Len(BonitaSession) + 1), ";")(0)
GetLoginSession = jsessionidCookie
' Set xmlhttp = Null
End Function
Function GetProcessId(ProcessName)
Dim xmlhttp As New MSXML2.xmlhttp, myurl As String
myurl = urlServerPath + "/API/bpm/process?f=name=" + ProcessName
xmlhttp.Open "GET", myurl, False
xmlhttp.setRequestHeader "Content-type", "application/json"
xmlhttp.send
result = xmlhttp.responseText
GetProcessId = getKeyValue(result, "id")
End Function
Function getKeyValue(result, Search)
If Left(result, 2) = "{[" Then result = Left(Mid(result, 3), Len(result) - 4)
varLines = Split(result, ",")
ReDim ResultJson(0) As JsonData
For i = 0 To UBound(varLines)
If (varLines(i) <> "") Then
ReDim Preserve ResultJson(i)
ResultJson(i).KeyName = Split(Replace(varLines(i), Chr(34), ""), ":")(0)
ResultJson(i).KeyValue = Split(Replace(varLines(i), Chr(34), ""), ":")(1)
End If
Next
For i = 0 To UBound(ResultJson)
If ResultJson(i).KeyName = Search Then
getKeyValue = ResultJson(i).KeyValue
Exit Function
End If
Next i
End Function