Hi all,
I'm trying to get some custom automation going where only users in specific AD groups would be imported, and they'd be assigned different QuickSupport assignments based on those groups. I've got the ActiveDirectory side of the script working, and it's telling me what it'd do for each user correctly. However, I'm having trouble getting the API to work.
I've create company and user tokens, so I can test with either as needed. I can successfully ping the API using either token and get token_valid = true. I can also return a list of users, or a single user using parameters. It's when I try to add or remove users that things start to get sticky. (I've removed the tokens below for obvious reasons, but they're the actual tokens in my script)
PS C:\Users\user> $header
Name Value
---- -----
Authorization Bearer $userToken
PS C:\Users\user> $postHeader
Name Value
---- -----
Content-Type application/json
Authorization Bearer $userToken
PS C:\Users\user> Invoke-RestMethod -Method 'GET' -Headers $header -Uri "$baseUri/api/v1/users?email=john.testmoe@example.com.au"
users
-----
{}
PS C:\Users\user> $body
{
"email": "john.testmoe@example.com.au",
"name": "John TestMoe",
"language": "en",
"password": "Testing123"
}
PS C:\Users\user> Invoke-RestMethod -Method 'POST' -Headers $postHeader -Uri "$baseUri/api/v1/users" -Body $body
Invoke-RestMethod : {"error":"invalid_request","error_description":"This e-mail address is already in use","error_code":1}
At line:1 char:1
+ Invoke-RestMethod -Method 'POST' -Headers $postHeader -Uri "$baseUri/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
This appears to be because I had a test user with that address before, but it hasn't cleared from the system yet. So we'll try a new account.
PS C:\Users\user> $body = @{
>> 'email' = 'john.testmoe2@example.com.au';
>> 'language' = 'en';
>> 'name' = 'John TestMoe2';
>> 'password' = 'Testing123'
>> } | ConvertTo-Json
>>
PS C:\Users\user> Invoke-RestMethod -Method 'POST' -Headers $postHeader -Uri "$baseUri/api/v1/users" -Body $body
Invoke-RestMethod : {"error":"internal_error","error_code":3,"error_signature":"DwLxS4/88105bc5/060318"}
At line:1 char:1
+ Invoke-RestMethod -Method 'POST' -Headers $postHeader -Uri "$baseUri/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
error = internal_error, and error_code = 3. Not the most helpful of error messages. Can anyone tell me where I'm going wrong?
Cheers,
John Moe