none
Azure Batch API for jobs in PowerShell RRS feed

  • Question

  • Hello,

    I'm trying to do a GET request on the jobs API for Batch API testing. Typically when I interact with the Azure DevOps API, I use basic auth, which Batch does not support. I've been through multiple iterations of this code, but the one that I'm thinking is the "most accurate" is;

    $BatchAccount = "getvms"$Key = "primary_key_of_getvms_batch_account"$sharedKey = [System.Convert]::FromBase64String($Key)$date = [System.DateTime]::UtcNow.ToString("R")$stringToSign = "GET`n`n`n`n`n`n`n`n`n`n`n`nocp-date:$date`n /$BatchAccount/jobs\napi-version:2014-01-01.1.0\ntimeout:20"[byte[]]$dataBytes = ([System.Text.Encoding]::UTF8).GetBytes($stringToSign)$hmacsha256 = New-Object System.Security.Cryptography.HMACSHA256$hmacsha256.Key = [Convert]::FromBase64String($key)$sig = [Convert]::ToBase64String($hmacsha256.ComputeHash($dataBytes))$authhdr = "SharedKey $BatchAccount`:$sig"$headers = @{"Date" = $date;            "x-ms-version" = "2014-02-14";            "Authorization" = "$authhdr";            "Content-Length" = "0"}Invoke-restmethod -Headers $headers -ContentType "application/json" -Uri 'https://getvms.eastus.batch.azure.com/jobs/jd?api-version=2019-08-01.10.0'

    Any help on how to do this in PowerShell would be ridiculously helpful :)

    Sunday, November 24, 2019 8:26 PM

All replies

  • HI,

    I tried it out.

    Getting the below error.

    {
          "key":"AuthenticationErrorDetail","value":"The MAC signature found in the HTTP request '"Xxxxxxxxxxxxxxxxxxxxxxxx' is not the same as any computed signature. Server used following string to sign: 'GET\n\n\n\n\n\nMon, 25 Nov 2019 
    11:59:53 GMT\n\n\n\n\n\n/account/jobs/myjob\napi-version:2019-08-01.10.0'."
        }

    I made some changes. But unable to resolve this error.

    I will share the updates

    Monday, November 25, 2019 12:02 PM
    Moderator
  • Hello,

    As we are also running into same issue, we need to work with support team to get this resolved.

    As this issue needs deeper investigation, I request you to open a support case.

    If you don't have the ability to open a technical support ticket, you can email me at AzCommunity@microsoft.com and provide with your SubscriptionID and link to this thread. I can then enable your subscription for one time free support.

    Once the issue is resolved, requesting you to reply back with the solution on this thread for the benefit of the community.

    Thanks.

    Friday, November 29, 2019 9:01 AM
    Moderator