In this solution, we discuss two distinct approaches in detail to achieve continuous email monitoring and unattended bot deployment in A360. The first approach demonstrates how to trigger an unattended RPA bot using VBA code in Outlook, utilizing the A360 bot deploy API when an email is received in a shared Outlook mailbox. The second approach showcases the triggering process of an Unattended RPA bot using Power Automate cloud flows with the A360 bot deploy API.
A. Outlook and A360 Integration
In this method, VBA code is set up in the users Outlook Windows application to monitor the shared mailbox folders and trigger an unattended bot, utilizing the A360 bot deploy API.
1) Prerequisites:
a) Outlook windows Application
• The users outlook windows application session should be active and running for the VBA code to execute and respond to events such as receiving new emails in the shared mailbox.
• The user should have access to shared mailbox.
b) A360 Bot Deploy API
The Bot Deploy API deploys bots on an unattended bot runner VDI. Before deploying the bot, the user needs to be authorized through the Authentication API[13], and the authentication token must be included in the request header.
• The bot must be in a public workspace.
• The user must have the "View and Run my bots" feature permission.
• The user must have "Run and schedule" permissions for the folders containing the bots.
• The user must have access to Bot Runner licensed users.
• The user must have access to either a default device or a device pool.
c) VBA Code functionality in Outlook:
VBA code is setup in outlook for monitoring emails in a shared mailbox and trigger an A360 Bot Deploy API.
a) Steps for setting up the VBA code
• Open Outlook and press Alt + F11 or click Developer tab then click Visual Basic to open the VBA editor[8].
• In the Project Explorer window, locate and expand the project (Project 1).
• Double-click “ThisOutlookSession” to open the code module for Outlook.
• In the code window, write the VBA code.
b) VBA Code and explanation
• Declare Private variables to access them with in the module.
// objInboxItems monitors shared mailboxes’ inbox folder for any new emails. The WithEvents enables the object to respond to events (ItemAdd), which is triggered when a new item is added to the collection (Outlook.Items).
Private WithEvents objInboxItems As Outlook.Items
// Declare objProcessedFolder variable to hold a reference to an Outlook folder
Private objProcessedFolder As Outlook.Folder
• The "Application_Startup" Private Subroutine is triggered upon starting the Outlook session in Windows. It initializes the necessary objects and sets up the event handler to monitor the Inbox of the shared mailbox.
Private Sub Application_Startup()
//Reference Outlook MAPI name space
Dim objNamespace As Outlook.NameSpace
//Reference to access shared mailbox and its contents
Dim objSharedMailbox As Outlook.Recipient
//Reference Inbox folder
Dim objInboxFolder As Outlook.Folder
Set objNamespace = Application.GetNamespace("MAPI")
// Replace *Shared mailbox Address* placeholder with your shared mailbox box address
Set objSharedMailbox = objNamespace.CreateRecipient("*Shared mailbox Address*") ' Replace with the email address of the shared mailbox
//Reference and get the Inbox folder of the shared mailbox
Set objInboxFolder = objNamespace.GetSharedDefaultFolder(objSharedMailbox, olFolderInbox)
Set objInboxItems = objInboxFolder.Items
End Sub
• The Private Sub objInboxItems_ItemAdd event handler is triggered whenever a new item (email) is added to the Inbox folder of the shared mailbox.
Private Sub ObjInboxItems_ItemAdd(ByVal Item As Object)
//Check if the received item is a MailItem
If TypeOf Item Is Outlook.MailItem Then
//Call TriggerAutomation360Bot function to trigger a bot
Call TriggerAutomation360Bot
End If
End Sub
• The ‘TriggerAutomation360Bot’ function is ‘called’ within the objInboxItems_ItemAdd subroutine to trigger an unattended bot in the bot runner VDI using the A360 Bot Deploy API.
Private Function TriggerAutomation360Bot()
//Call Authenticate function
Dim Token As String
Token = Authenticate
//Call Bot Deploy API function and pass Token. This function triggers the API and deploys the specified bot on specified unattended bot user
DeployBot (Token)
//Expire authentication
ExpireAuthentication (Token)
End Function
• The ‘Authenticate’ Function is called with in the ‘TriggerAutomation360Bot’ to authorize the A360 control room user and retrieve the token.
Private Function Authenticate() As String
Dim objHTTP As Object
Dim Json As String
//Construct Json string to pass user name and APIkey/Password. Replace *UserName* and *ApiKey* placeholders with actual username and API key values
Json = "{ ""username"": """*UserName* """, ""apiKey"": """*ApiKey*"""}"
Dim result As String
//Replace *A360AuthenticationURL* placeholder with actual URL. Ex: A360 control room URL/ v1/authentication
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "*A360AutenticationURL*"
//Trigger Authenticate API by passing the header
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "Content-type", "application/json"
objHTTP.Send (Json)
result = objHTTP.responseText
//Call “GetSubString” function to retrieve token from JSON response
Token = GetSubString(result, """token"":""", """")
//Return token as output
Authenticate = Token
End Function
• The ‘GetSubString’ function is called with in the ‘Authenticate’ function to retrieve token value from Authenticate API Json response.
Private Function GetSubString(vJsonOutput As String, FirstDelimiter As String, SecondDelimiter As String) As String
//Store the position of the 1st and 2nd delimiter in the String
Dim vFirstDelimiterPosition As Integer, vSecndDelimiterPosition As Integer
//Store the length of the delimiter
Dim vLenDelimiter As Integer
//Validating the input parameters
If Len(vJsonOutput) = 0 And Len(FirstDelimiter) = 0 And Len(SecondDelimiter) = 0 Then
//Return output
GetSubString = ""
Exit Function
End If
vLenDelimiter = Len(FirstDelimiter)
//Find the 1st delimiter
vFirstDelimiterPosition = InStr(vJsonOutput, FirstDelimiter)
//Find the 2nd delimiter position
vSecndDelimiterPosition = InStr(vFirstDelimiterPosition + vLenDelimiter, vJsonOutput, SecondDelimiter)
If vFirstDelimiterPosition > 0 And vSecndDelimiterPosition > 0 Then
//Extract substring and return output
GetSubString = Mid(vJsonOutput, vFirstDelimiterPosition + vLenDelimiter, _
vSecndDelimiterPosition - vFirstDelimiterPosition - vLenDelimiter)
Else
//Return output
GetSubString = ""
End If
End Function
• The ‘DeployBot’ function is called with in the ‘TriggerAutomation360Bot’ function to trigger a RPA bot using A360 Bot Deploy API.
Private Function DeployBot(Token As String)
//Declare variables
Dim objHTTP As Object
Dim result As String
Dim Json As String
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
//Replace the *DeployBotURL* place holder with the actual URL. Ex: A360 control room URL/v3/automations/deploy.
Url = "*DeployBotURL*"
//Replace the *FileID* place holder with the main task ID (click open task to view the task id in the URL)
//Replace the *UnattendedUserID* place holder with the actual unattended bot user ID (click open user to view the user ID in the URL)
Json = "{ ""fileId"": ""*FileID*"", ""runAsUserIds"": [""*UnattandedUserID*""]}"
//Trigger Bot Deploy API by passing the headers, Content Type and Token
objHTTP.Open "POST", URL, False
With objHTTP
.setRequestHeader "Content-type", "application/json"
.setRequestHeader "X-Authorization", Token
End With
objHTTP.Send (Json)
result = objHTTP.responseText
End Function
• The ‘ExpireAuthentication’ function is called with in the ‘TriggerAutomation360Bot’ function to trigger the A360 Authentication API to expire the user token.
Private Function ExpireAuthentication(Token As String)
//Declare variables
Dim objHTTP As Object
Dim result As String
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
// Replace *A360AutheticationLogoutURL* place holder with the actual logout URL. Ex: A360 control room URL/v1/authentication/logout.
URL = "*A360AutheticationLogoutURL*"
objHTTP.Open "POST", URL, False
With objHTTP
.setRequestHeader "X-Authorization", Token
End With
objHTTP.Send
'result = objHTTP.responseText
End Function
• The Bot Deploy API produces five outputs, which can be analyzed and acted upon as necessary.
200: Success-Returns a Deployment ID that can be used to check the deployment status using the callback URL.
400: Bad Request-This response contains a JSON object with an error code and error message.
401: Authentication required-This response contains a JSON object with an error code and error message.
404: Not Found-This response contains a JSON object with the error message.
500: Server error-This response contains a JSON object with an error code and error message.
B) Power Automate and A360 Integration
In this method, a power automate flow is setup for the O365 user to monitor the shared mailbox folders and trigger an unattended bot, utilizing the A360 bot deploy API.
1) Prerequisites
a) Power Automate Cloud flows
• The user should have access to Power Automate cloud flows and Premium connectors[14].
• The user should have a Premium license to use the HTTP connector in power automate[15].
The Bot Deploy API deploys bots on an unattended bot runner VDI. Before deploying the bot, the user needs to be authorized through the Authentication API, and the authentication token must be included in the request header.
• The bot must be in a public workspace.
• The user must have the "View and Run my bots" feature permission.
• The user must have "Run and schedule" permissions for the folders containing the bots.
• The user must have access to Bot Runner licensed users.
• The user must have access to either a default device or a device pool.
2) Power Automate Cloud flows functionality
a) Setup up an “Automated clod flow”
• Create a new flow and select “Automated Cloud flow” under “My flows” tab[16].
• Define name for the flow and select “When a new email arrives in a shared mailbox” trigger.
• Click create to create and start developing the cloud flow.
b) Power Automate Cloud flow development steps
• Select Shared mailbox and Folder.
• Add Step, choose HTTP operation and select HTTP action to call A360 Authentication API.
• Select POST method in the HTTP action.
• Enter A360 Authentication URL, the Authentication URL is a combination of control room URL and “/v1/authentication”. Ex: “https://organizarionname.my.automationanywhere.digital/v1/authentication”.
• Enter Header, content type-application/JSON.
• Enter JSON body, replace “*UserEmail*” and “*APIKey*” place holders with actual user email and API key.
• Save the flow, click “Test” button, and send a test email to shared mailbox to test the flow. The flow will be activated upon receiving the email in the designated folder within the shared mailbox. It will then execute an HTTP action, calling the Authentication API and generating a JSON response. Copy this JSON output to a notepad for further reference.
• Edit the flow and add “Data Operation” step. Select Parse JSON action in Data operation.
• Select “Body” (output) from previous HTTP action as “Content” for parse JSON action. This step will retrieve A360 control room user authorization token from Authentication API JSON response.
• Click “Generate from Sample” button.
• Paste the previously saved Authentication API JSON output from HTTP step on to the “Insert a sample JSON payload” window and click done. This will generate JSON schema to parse the JSON and get hold of “Token”[17].
• Add another step and select HTTP operation and HTTP action to call Bot Deploy API.
• Select POST method in HTTP action.
• Enter A360 Bot Deploy URL, the Bot Deploy URL is a combination of control room URL and “/ v3/automations/deploy”. Ex: “https://organizarionname.my.automationanywhere.digital/v3/automations/deploy”.
• Enter Headers, Content-type and X-Authorization. The user authorization token retrieved from the previous step, Parse JSON is passed as an input for X-Authorization header.
• Enter JSON Body, replace *MainTaskID* and *UnattendedBotUserID* place holders with the actual Mian task ID and Unattended bot user ID.
• Click open task/bot to view the task id in the URL.
• Click open the unattended bot user to view the user ID in the URL.
• The Bot Deploy API produces five outputs, which can be analyzed and acted upon as necessary.
• Add step and select HTTP operation and HTTP action to call A360 Authentication API to expire the token.
• Select POST method in HTTP action.
• Enter A360 Authentication Logout URL. Ex: “https://organizarionname.my.automationanywhere.digital/v1/authentication/logout”.
• Enter Header (X-Authorization), token retrieved from previous Parse JSON operation.
• Save the flow and click test/run to test the functionality of the flow.