REST API调用机器人(Automation Anywhere)

远程调用机器人是蛮有意思的事情。
Automation Anywhere很早就开始提供远程调用的功能,以便第三方定制。可以是ChatBot或者Portal完成调用工作。通过这项工作可以让机器人不必跟用户一对一绑定。是可以让个体户瞬间变成集团协同作战的方式之一。
以下是比较偷懒的方法,干脆用vbs脚本。需要的话提供数据给机器人。这样我们可以节省email检查岗机器人的工时了。当然,企业级生产环境不建议使用vbs直接调用。林子大了。。。删库跑路还是要杜绝滴。
大致逻辑是验证身份->发出调用指令->查收结果。
这种方式只限于Unattended bot的调用。

'AUTHENTICATION API - START
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile("C:\auth-input.txt")

restRequest = objStream.ReadText()

objStream.Close
Set objStream = Nothing

contentType = "application/json"

Set oWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")

oWinHttp.Open "POST", "http://xxx/v1/authentication", False

oWinHttp.setRequestHeader "Content-Type", contentType

oWinHttp.Send restRequest

response = oWinHttp.StatusText

MsgBox response

Dim AuthToken

'Set oJson = new aspJSON

AuthToken = oWinHttp.ResponseText

'oJson.loadJSON(AuthToken)

'MsgBox oJson.data("token")

MsgBox AuthToken

'AUTHENTICATION API - ENDS

'---------------------------------------------------

'RESPONSE HEADER PARSING - START
Dim sToken
Dim posUser

sToken = Right(AuthToken, Len(AuthToken) - 10)

MsgBox(sToken)

'sToken = Left(sToken, Len(sToken) - 4)

posUser = InStr(sToken, "user")

MsgBox posUser

sToken = Left(sToken, posUser - 4)

MsgBox(sToken)

'RESPONSE HEADER PARSING - END

'DEPLOYMENT API - START

Set objStream_dep = CreateObject("ADODB.Stream")
objStream_dep.CharSet = "utf-8"
objStream_dep.Open
objStream_dep.LoadFromFile("D:\\cred-input.txt")

restRequest = objStream_dep.ReadText()

objStream_dep.Close
Set objStream = Nothing

contentType = "application/json"

Set oWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")

oWinHttp.Open "POST", "http://xxxx/v1/credentialvault/external/credentials/loginsetting", False

oWinHttp.setRequestHeader "Content-Type", contentType

oWinHttp.setRequestHeader "X-Authorization", sToken

oWinHttp.Send restRequest

response = oWinHttp.StatusText

MsgBox response

Dim DeployResponse

DeployResponse = oWinHttp.ResponseText

'MsgBox DeployResponse

'DEPLOYMENT API - ENDS

最近UiPath和AA(Automation Anywhere)几乎同时发布了中文版文档。
细节可参照:https://docs.automationanywhere.com/bundle/enterprise-v11.3/page/topics/control-room/control-room-api/api-authentication.html

你可能感兴趣的:(REST API调用机器人(Automation Anywhere))