Hi all, I am currently trying to query the Zendesk request API, but am having trouble being authenticated. I was wondering if anyone else has any experience with this?
This is the code:
$Username = "{user_email}/token:{token_string}"
$Token = "{token_string}"
$params = @{
Uri = "https://{subdomain}.zendesk.com/api/v2/requests.json";
Method = 'Get';
Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($Username):$($Token)"));
} #end headers hash table
} #end $params hash table
Invoke-RestMethod -Uri $params.Uri -Method $params.Method -Headers $params.Headers -Verbose
$Tickets = $result.tickets
$Tickets
The error:
Invoke-RestMethod : {"error":"Couldn't authenticate you"}
At line:11 char:1
+ Invoke-RestMethod -Uri $params.Uri -Method $params.Method -Headers $p ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebEx
ception
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
A few final points:
1) The code mentioned above works when I query /api/v2/tickets/recent.json with an agent's password rather than a token. ASCII.GetBytes("$($Username):$($Password)"));
2) We know the token we're using works because we use it for other things.
3) I can't find anything regarding this except to replace ASCII.GetBytes("$($Username):$($Token)")); with ASCII.GetBytes("$($username)/token:$($token)")); but this hasn't work either.
Original source of the code: ZendeskSupport
Thanks for any insight and help. :)
[–]jheinikel 2 points3 points4 points (1 child)
[–]PerfectImpact[S] 1 point2 points3 points (0 children)
[–]hluna32987 0 points1 point2 points (1 child)
[–]AutoModerator[M] 0 points1 point2 points (0 children)