Does anyone have experience using Invoke-RESTMethod to POST to the ServiceNow Import Set API? I tried to do it the same as connecting directly to the tables (code below), and I end up with a ‘Too many automatic redirections were attempted.’ error. I saw a few articles referencing that you need to store cookies but I am not sure how to do this.
$POSTuri = 'https://test2.service-now.com/now/import/u_api_test' $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add('Authorization',('Basic YJH%#IOJ#GGdfgdsfXBpX2Jn3jhkl390f329213nkjfasfpX2l0YWM6QVNET01XMjasdfas33$#%^45M2Mz$K%#%')) $headers.Add('Accept','application/json') $headers.Add('Content-Type','application/json') # Specify request body $body = @{ 'assigned_to' = 'Edmond Yee' 'work_notes' = 'Assigning ticket to me. Test 10/4/16 11:20am' 'number' = "$item" }#end body $json = $body | ConvertTo-Json Invoke-WebRequest -Method Post -Headers $headers -Uri $POSTuri -Body $json