I have recently started working on an attempt to do some automations and most of the payloads have been pretty straight forward. Although this one seems a bit more complex and i am not sure how to setup the array prior to converting it to json to get the expected format correct. The goal is to produce a payload that will create the aws account connection in a backup tool. (netbackup)
Here is what the expected format with an example is:
configurationRequest { "data": { "id": "string", "type": "plugininstance", "attributes": { "cloudpointHostname": "string", "configurationAttributes": [ { "name": "string", "singlevalue": "string", "multivalue": [ "string" ] } ] } } }
Example -
POST https://cloudpointhost/netbackup/config/snapshotproviders/configuredplugins/aws/instances
configurationRequest { "data": { "id": "ConfigurationName", "type": "plugininstance", "attributes": { "configurationAttributes": [ { "name": "accesskey", "singlevalue": "AccessKeyHere" }, { "name": "secretkey", "singlevalue": "SecretKeyHere" }, { "name": "regions", "multivalue": [ "ap-northeast-1", "ap-northeast-2" ] } ] } } }
Here is my current code.
$AccountList = Import-Csv $CSVFilename foreach ($Account in $AccountList) { $JSON = @{ awsid = $Account.aws_account_id awsalias = $Account.aws_account_alias id = $Account.aws_account_name type = "aws" accesskey = $Account.veritascloudpoint_aws_iam_access_key_id secretkey = $Account.veritascloudpoint_aws_iam_access_key_secret regions = $Account.regions.Split(',').Trim() -as [String[]] } | ConvertTo-Json $JSON }
Here is my sample file:
aws_account_id,aws_account_alias,aws_account_name,veritascloudpoint_aws_iam_access_key_id,veritascloudpoint_aws_iam_access_key_secret,regions
1111,uat,UAT ENV,key,skey,us-east-1
2222,ops,OPS ENV,key,skey,“eu-west-1, us-east-1”
Thanks for any help in advance.