we need help with a powershell script accessing acronis' API v2

can anyone tell me why i keep getting 401 errors saying i'm unauthorized? i've removed the variable definitions [code] $site = "https://us5-cloud.acronis.com" $api = "$site/api/2" $headers = @{} $headers.Add("Authorization", "Basic") $headers.add("username" , '$APIUser') $headers.add('password' ,'$APIPassword') $userCreateArgs = @{ name = $customer_full_name parentid = $parentid kind = $kind language = "en" customer_id = $customer_id contact = {$contactCreatedArgs} } | ConvertTo-Json $contactCreateArgs = @{ email = $customer_email address1 = $customer_billing_address address2 = $customer_billing_address_2 country = "USA" state = $customer_billing_state zipcode = $customer_billing_zip city = $customer_billing_city phone = $customer_phone lastname = $contact_last_name firstname = $contact_first_name } add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy Invoke-RestMethod "$api/tenants" -Headers $headers -Method Post -ContentType "application/json" -Body $userCreateArgs
[/code]

- Accedi per poter commentare

For reference, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#Basic_authentication_scheme
You should add one header only:
$APIUser = 'someuser' $APIPassword = 'somepassword' $Credentials = "${APIUser}:${APIPassword}" $Bytes = [System.Text.Encoding]::Unicode.GetBytes($Credentials) $EncodedCredentials = [Convert]::ToBase64String($Bytes) $headers = @{} $headers.Add("Authorization", "Basic ${EncodedCredentials}")
For example:
PS C:\Users\alexander.yakovlev> $APIUser = 'someuser' PS C:\Users\alexander.yakovlev> $APIPassword = 'somepassword' PS C:\Users\alexander.yakovlev> $Credentials = "${APIUser}:${APIPassword}" PS C:\Users\alexander.yakovlev> $Bytes = [System.Text.Encoding]::Unicode.GetBytes($Credentials) PS C:\Users\alexander.yakovlev> $EncodedCredentials = [Convert]::ToBase64String($Bytes) PS C:\Users\alexander.yakovlev> $headers = @{} PS C:\Users\alexander.yakovlev> $headers.Add("Authorization", "Basic ${EncodedCredentials}") PS C:\Users\alexander.yakovlev> $headers Name Value ---- ----- Authorization Basic cwBvAG0AZQB1AHMAZQByADoAcwBvAG0AZQBwAGEAcwBzAHcAbwByAGQA
- Accedi per poter commentare

Dear Michael,
If you continue have some questions regarding the authorization process and others APIs usage you can find detailed documentation at Acronis Developer Network portal https://developer.acronis.com/doc/
- Accedi per poter commentare
Stas Pavlov | Technology Evangelist
Acronis Developer Network | Acronis Cyber Cloud Solutions Portal | Acronis Cyber Platform
For more answers to your questions, try our Knowledge Base and Video Tutorials
Our mission is to create Customers and Partners success. Our management team welcomes your comments and suggestions on how we can improve the overall support we provide to you. Please send your comments, suggestions, or concerns to Managers or submit your feedback here.

Please see our full functional PowerShell examples on GitHub https://github.com/acronis/acronis-cyber-platform-powershell-examples
- Accedi per poter commentare
Stas Pavlov | Technology Evangelist
Acronis Developer Network | Acronis Cyber Cloud Solutions Portal | Acronis Cyber Platform
For more answers to your questions, try our Knowledge Base and Video Tutorials
Our mission is to create Customers and Partners success. Our management team welcomes your comments and suggestions on how we can improve the overall support we provide to you. Please send your comments, suggestions, or concerns to Managers or submit your feedback here.