0

I have a whole lot of requests that need to be made, hundreds infact. I run a simple for loop which then runs a new request for each object in an array.

The odd thing is that initially, these requests all succeed. However, once we get to the later hundreds, like 500 or so it then breaks and throws the following error constantly for each request

Invoke-WebRequest : Access Denied Your credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.

I found a few references to this issue being somethign that crops up regularly with regards to proxies in powershell but honestly can't make sense of their solutions.

Relevant Links:

Can anyone help me make sense of this? Here is my code in full for better clarification

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$user = '*********'
$base = "https://*********.com/api/xm/1/groups"
$pass = ConvertTo-SecureString '*********' -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pass
$req  = Invoke-WebRequest -Credential $cred -Uri https://*********.com/api/xm/1/groups?limit=999
$res  = ConvertFrom-Json $req.Content
$content = $res.data

for($x = 0; $x -lt $content.length; $x++) {
    $group_name = $content[$x].targetName
    $del_path   = "$base/$group_name/shifts/MAX"
    $del_path_2 = "$base/$group_name/shifts/MAX-Default Shift"

    Invoke-RestMethod -Credential $cred -Uri $del_path -Method DELETE
    Invoke-RestMethod -Credential $cred -Uri $del_path_2 -Method DELETE

    if ($x -eq 200 -or $x -eq 350 -or $x -eq 500) {
        Start-Sleep -s 30
    }
}
  • 1
    Does the documentation for this talk about rate limiting? I wonder if this is happening because of the request frequency. Although I would expect the error to be different. – Matt Nov 14 '18 at 18:55
  • Nope. Just checked in their docs. This would throw a 429 if that was the case, which it's not. This is something local to my machine running the script. –  Nov 14 '18 at 18:58

0 Answers0