VMware Cloud Community
viShukla
Contributor
Contributor
Jump to solution

Adding Cloud Account in Aria Automation using API call

Hi, 

I am trying to use API call from PowerShell to create/add cloud account in aria automation but getting some error.

Invoke-RestMethod : {"message":"Failed to execute handlePostAsync","statusCode":400,"errorCod
e":0,"serverErrorId":"3f237537-b7f5-4650-9e21-eb39b0343954","documentKind":"com:vmware:xenon:
common:ServiceErrorResponse"}

The code I am using is :-

Invoke-RestMethod -Uri "$url/iaas/api/cloud-accounts?apiVersion=$api_version" -Method POST -Headers @{
'Content-Type' = 'application/json'
'Authorization' = "Bearer $accessToken"
} -Body @{
cloudAccountType = 'vsphere'
privateKeyId = $vsphere_user
privateKey = $vsphere_password
cloudAccountProperties = @{
hostName = $vsphere_host_name
acceptSelfSignedCertificate = $false
dcId = "onprem"
privateKeyId = $vsphere_user
privateKey = $vsphere_password
}

createDefaultZones = $false
tags = @(@{ key = 'env'; value = 'prod' })
name = 'demo-vsphere-account'
description = 'This is a demo vSphere account without default cloud zones'
}

Reply
0 Kudos
1 Solution

Accepted Solutions
carl1
Expert
Expert
Jump to solution

I am using cloud-accounts-vsphere for the url, but this should be similar

$tbody = @{
  hostName = "${vCenterManagementIp}"
  acceptSelfSignedCertificate = $true
  regions = @(
  	@{
  		name='Datacenter:datacenter-3' 
  		externalRegionId='Datacenter:datacenter-3'
  	}
  )
  apiKey="${apiToken}"
  nsxHostName="${nsxHostName}"
  sddcId="$sddcId"
  password="${vCenterPassword}"
  createDefaultZones=$true
  dcId="${proxy_id}"
  name="vmcexpert${kit}-${student}_VMConAWS"
  username="${vCenterUsername}"
  
}

$tpayload = $tbody | convertTo-Json
$tdata = invoke-RestMethod -method POST -headers $theaders -body $tpayload -ContentType 'application/json' -uri $turl

View solution in original post

3 Replies
carl1
Expert
Expert
Jump to solution

I am using cloud-accounts-vsphere for the url, but this should be similar

$tbody = @{
  hostName = "${vCenterManagementIp}"
  acceptSelfSignedCertificate = $true
  regions = @(
  	@{
  		name='Datacenter:datacenter-3' 
  		externalRegionId='Datacenter:datacenter-3'
  	}
  )
  apiKey="${apiToken}"
  nsxHostName="${nsxHostName}"
  sddcId="$sddcId"
  password="${vCenterPassword}"
  createDefaultZones=$true
  dcId="${proxy_id}"
  name="vmcexpert${kit}-${student}_VMConAWS"
  username="${vCenterUsername}"
  
}

$tpayload = $tbody | convertTo-Json
$tdata = invoke-RestMethod -method POST -headers $theaders -body $tpayload -ContentType 'application/json' -uri $turl
viShukla
Contributor
Contributor
Jump to solution

Hi @carl1 ,

Thanks for your help, the code is working now, even with cloud-accounts. I just had to convert the payload into json and send it through API, earlier I was sending it directly. After necessary change it worked.

Reply
0 Kudos
HenkEngelsman
VMware Employee
VMware Employee
Jump to solution

Glad to see you sorted this out.

I have created some PowerShell based examples for creating Cloud Accounts and Cloudzones.

See https://vtam.nl/2023/11/17/add-cloud-account-in-aria-automation-using-api/