Skip to main content
Solved

Control Room API in PowerShell


Forum|alt.badge.img+17

I am curious if anyone has connected to the Control Room APIs through PowerShell for A360. I am attempting to assist someone that wants to kick off a taskbot through powershell via the API, but am running into a wall. I can connect easily enough and obtain the token, something like so:

 

$sUrl = "https://CR_URL/v1/authentication"

 

$body = @{

  'username' = "Username"

  'password' = "Password"

}

 

$bodyJson = $body | ConvertTo-Json

 

$Response1 = Invoke-RestMethod -Method Post -Uri $sURL -Body $bodyJson

$Response1.token

 

However, to launch a bot I need to connect to the workspaces and find the bot file ID. To do so I need to add the token from the above step and connect to "https://CR_URL/v2/repository/workspaces/{workspaceType}/files/list". I cannot seem to get the syntax correct for adding the token to the header. I have tried a couple of variations of this:

 

$newURL = "https://CR_URL/v2/repository/workspaces/private/files/list"

$authVal = $Response1.token

$newBody = @{

#Body for file filter

}

$newBodyJson = $newBody | ConvertTo-Json

$Response2 = Invoke-RestMethod -Method Post -Uri $newURL -Body $newBodyJson -Headers @{"AUTHORIZATION"=$authVal}

 

I know this is just a syntax error as I can get it to work outside of PS. Was just curious if anyone has an example of making the connection and listing the CR files in PowerShell that I can look at.

Best answer by JLogan3o13

Dandy Huang wrote:

Do you have successful codes with deploying bot? I tested above codes for deploying but got failed. thanks in advance

 

Yes, after two years I am not surprised things have changed on the API spec. The following is working for me. Note some caveats:

  • Obviously, modify the scripts to use your Control Room URL, Username, PW, and API Key.
  • You can skip running the second piece of code if you have the Bot ID already
  • On the third call, per the swagger docs, you have to set up a callback server, and implement a key for it.

 

#Authenticate To CR

$authHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$authHeaders.Add("accept", "application/json")
$authHeaders.Add("Content-Type", "application/json")

$authBody = @"
{
  `"username`": `"myUserName`",
  `"password`": `"myPassword`",
  `"apiKey`": `"myAPIKey`",
  `"multipleLogin`": false
}
"@

$authResponse = Invoke-RestMethod 'https://<myCR>.my.automationanywhere.digital/v2/authentication' -Method 'POST' -Headers $authHeaders -Body $authBody
#Capture Bot ID

$repoHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$repoHeaders.Add("Content-Type", "application/json")
$repoHeaders.Add("Accept", "application/json")
$repoHeaders.Add("X-Authorization", $authResponse.token)

$repoBody = @"
{
  `"filter`": {
    `"operator`": `"or`",
    `"operands`": [
      {
        `"operator`": `"substring`",
        `"field`": `"name`",
        `"value`": `"Test_API`"
      }
    ]
},
  `"sort`": [
    {
      `"field`": `"directory`",
      `"direction`": `"asc`"
    }
  ],
  `"page`": {
    `"offset`": 0,
    `"length`": 100
  }
}
"@

$repoResponse = Invoke-RestMethod 'https://myCR.my.automationanywhere.digital/v2/repository/file/list' -Method 'POST' -Headers $repoHeaders -Body $repoBody
$botID = $repoResponse.list[0].id
#Deploy Bot

$deployHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$deployHeaders.Add("Content-Type", "application/json")
$deployHeaders.Add("Accept", "application/json")
$deployHeaders.Add("X-Authorization", $authResponse.token)

$deployBody = @"
{
  `"botId`": $($botID),
  `"automationName`": `"Test_API_Deployment`",
  `"botLabel`": `"string`",
  `"runElevated`": false,
  `"hideBotAgentUi`": false,
  `"callbackInfo`": {
    `"url`": `"https://callbackserver.com/storeBotExecutionStatus`",
    `"headers`": {
      `"X-Authorization`": `"eyJhbGciOiJSUzUxMiJ9.eyJzdWIiOiI0Ii`"
    }
  },
  `"automationPriority`": `"PRIORITY_MEDIUM`",
  `"attendedRequest`": {
    `"deploymentDeviceId`": 0,
    `"queueDeployment`": true,
    `"launchInChildWindow`": true
  }
}
"@

$deployResponse = Invoke-RestMethod 'https://myCR.my.automationanywhere.digital/v4/automations/deploy' -Method 'POST' -Headers $deployHeaders -Body $deployBody
$deployResponse | ConvertTo-Json

 

View original
Did this topic help answer your question?

6 replies

Forum|alt.badge.img+11

Hello @Jeremiah Logan​ 

 

Thanks for reaching out to Automation Anywhere.

 

You could try passing the token with Headers on the next call with the X-Authorization parameter

 

@header@{

x-authorization="token received form older call"}

 

For further assistance please reach us with a Support case and our Engineers shall assist

 

https://apeople.automationanywhere.com/s/article/How-to-create-a-support-case-in-service-cloud


Forum|alt.badge.img+17
  • Author
  • Navigator | Tier 3
  • 83 replies
  • May 20, 2022

Thanks, I was able to get the list to work by including the X-Authorization param. I'm now trying to get the bot deployment to work. I can connect, and get both the user ID and the Bot ID, but the deployment fails with a 400 Unauthorized. I think it has something to do with the RunAsUserIDs arraylist:

 

$sUrl = "<url>/v1/authentication"

 

$body = @{

  'username' = "username"

  'password' = "password"

}

 

$bodyJson = $body | ConvertTo-Json

$Response = Invoke-RestMethod -Method Post -Uri $sURL -Body $bodyJson

 

$newURL = "<url>/v2/repository/workspaces/private/files/list"

$sessionHeader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"

$sessionHeader.Add('x-Authorization',$Response.token)

$sessionHeader.Add('Accept','application/json')

$type = "application/json"

 

$newBody = @{

 'filter' = @{

  'operator' = "substring"

  'field' = "name"

  'value' = "AA_API_"

 }

}

 

$newBodyJson = $newBody | ConvertTo-Json

$Response2 = Invoke-RestMethod -Method Post -Uri $newURL -Body $newBodyJson -Headers $sessionHeader -ContentType $type

 

$token = $Response.token

$ID = $Response.user.id

$botID = $Response2.list.Id

 

$botURL = "<url>/v3/automations/deploy"

$botBody = @{

  'fileId' = "8200"

  'runAsUserIds' = "[168]"

  'poolIds' = ""

  'overrideDefaultDevice' = "false"

  'callbackInfo' = @{

    'url' = "https://callbackserver.com/storeBotExecutionStatusquot;

    'headers' = @{

      'X-Authorization' = "{{$($token)}}"

    }

  }

  'botInput' = @{

    'sInput1' = @{

      'type' = "STRING"

      'string' = "These values come "

    }

    'sInput2' = @{

      'type' = "STRING"

      'string' = "from the API call"

    }

  }

}

$botBodyJson = $botBody | ConvertTo-Json

 

$Response3 = Invoke-RestMethod -Method Post -Uri $botURL -Body $botBodyJson

$Response3


Forum|alt.badge.img+4
  • Cadet | Tier 2
  • 9 replies
  • September 6, 2022

Hi @Jeremiah Logan​,

 

Trust you are well.

I'm trying to, build a bot to reset its own AD password and at the same time update the password in the CR.

This must be done in powershell, how where you able to connect to the Control room API using powershell?


Forum|alt.badge.img+12
  • Navigator | Tier 3
  • 67 replies
  • September 6, 2022

I was able to connect to the CR, and manage some items, but have not had time to revisit in a while. Here are some of the things I was able to accomplish:

 

Authentication to the CR:

https://gist.github.com/JLogan3o13/296395aeee5e332a6934a84276403597/p>

 

From here I can capture the auth token with $Response.token, or the UUID with $Response.tenantUUID, so I know I am connected successfully. I can also poll the user hive with things like $Response.user.id and $response.user.sysAssignedRoles. I can even list all bots in the CR, or search for one in particular:

 

<Start with the authentication code above>...

 https://gist.github.com/JLogan3o13/4ad71c05374fe029872558ccba2fa845/p>

 

Again, this is about as far as I got before getting pulled into other projects. Hope it helps you.


Forum|alt.badge.img
  • Cadet | Tier 2
  • 1 reply
  • February 4, 2025
J.Logan wrote:

I was able to connect to the CR, and manage some items, but have not had time to revisit in a while. Here are some of the things I was able to accomplish:

 

Authentication to the CR:

https://gist.github.com/JLogan3o13/296395aeee5e332a6934a84276403597/p>

 

From here I can capture the auth token with $Response.token, or the UUID with $Response.tenantUUID, so I know I am connected successfully. I can also poll the user hive with things like $Response.user.id and $response.user.sysAssignedRoles. I can even list all bots in the CR, or search for one in particular:

 

<Start with the authentication code above>...

 https://gist.github.com/JLogan3o13/4ad71c05374fe029872558ccba2fa845/p>

 

Again, this is about as far as I got before getting pulled into other projects. Hope it helps you.

The script is quite useful! by the way, do you have successful codes with deploying bot? I tested above codes for deploying but got failed. thanks in advance


Forum|alt.badge.img+17
  • Author
  • Navigator | Tier 3
  • 83 replies
  • Answer
  • February 7, 2025
Dandy Huang wrote:

Do you have successful codes with deploying bot? I tested above codes for deploying but got failed. thanks in advance

 

Yes, after two years I am not surprised things have changed on the API spec. The following is working for me. Note some caveats:

  • Obviously, modify the scripts to use your Control Room URL, Username, PW, and API Key.
  • You can skip running the second piece of code if you have the Bot ID already
  • On the third call, per the swagger docs, you have to set up a callback server, and implement a key for it.

 

#Authenticate To CR

$authHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$authHeaders.Add("accept", "application/json")
$authHeaders.Add("Content-Type", "application/json")

$authBody = @"
{
  `"username`": `"myUserName`",
  `"password`": `"myPassword`",
  `"apiKey`": `"myAPIKey`",
  `"multipleLogin`": false
}
"@

$authResponse = Invoke-RestMethod 'https://<myCR>.my.automationanywhere.digital/v2/authentication' -Method 'POST' -Headers $authHeaders -Body $authBody
#Capture Bot ID

$repoHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$repoHeaders.Add("Content-Type", "application/json")
$repoHeaders.Add("Accept", "application/json")
$repoHeaders.Add("X-Authorization", $authResponse.token)

$repoBody = @"
{
  `"filter`": {
    `"operator`": `"or`",
    `"operands`": [
      {
        `"operator`": `"substring`",
        `"field`": `"name`",
        `"value`": `"Test_API`"
      }
    ]
},
  `"sort`": [
    {
      `"field`": `"directory`",
      `"direction`": `"asc`"
    }
  ],
  `"page`": {
    `"offset`": 0,
    `"length`": 100
  }
}
"@

$repoResponse = Invoke-RestMethod 'https://myCR.my.automationanywhere.digital/v2/repository/file/list' -Method 'POST' -Headers $repoHeaders -Body $repoBody
$botID = $repoResponse.list[0].id
#Deploy Bot

$deployHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$deployHeaders.Add("Content-Type", "application/json")
$deployHeaders.Add("Accept", "application/json")
$deployHeaders.Add("X-Authorization", $authResponse.token)

$deployBody = @"
{
  `"botId`": $($botID),
  `"automationName`": `"Test_API_Deployment`",
  `"botLabel`": `"string`",
  `"runElevated`": false,
  `"hideBotAgentUi`": false,
  `"callbackInfo`": {
    `"url`": `"https://callbackserver.com/storeBotExecutionStatus`",
    `"headers`": {
      `"X-Authorization`": `"eyJhbGciOiJSUzUxMiJ9.eyJzdWIiOiI0Ii`"
    }
  },
  `"automationPriority`": `"PRIORITY_MEDIUM`",
  `"attendedRequest`": {
    `"deploymentDeviceId`": 0,
    `"queueDeployment`": true,
    `"launchInChildWindow`": true
  }
}
"@

$deployResponse = Invoke-RestMethod 'https://myCR.my.automationanywhere.digital/v4/automations/deploy' -Method 'POST' -Headers $deployHeaders -Body $deployBody
$deployResponse | ConvertTo-Json

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings