Skip to main content

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

Thread needs solution
Posts: 1
Comments: 0

can anyone tell me why i keep getting 401 errors saying i'm unauthorized?
i've removed the variable definitions    

    $site = ""
    $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


0 Users found this helpful
Support Engineer
Posts: 0
Comments: 57

hi Michael!


My only assumption is that either the login proedure fails or the login name that you use in $APIUser is not suitable for your calls.

Can you describe what you are trying to implement overall?

We can't do much in terms of helping you program entire thing, this should involve professional services, but if I can help, I will!