Recent searches


No recent searches

Zendesk API and PowerShell



Posted Feb 15, 2024

I'd like to pull in some data from Zendesk using PowerShell.  I am using the example found. Unfortunately, there was an issue "error: cannot authenticate you"  The token and email address are correct.  

Is there a resolution to this issue or another way to pull the data?


0

7

7 comments

image avatar

Jakub

Zendesk Customer Care

Hello Tyler Duncan

I would appreciate it if you could share your API call so I can see if I can give you any tips what might be causing this error to be returned. Thanks!

0


Hi Jakub
I am using the example I have found on reddit.  The token and email address are correct.  The permissions are setup correctly. The API cannot be connected.  

$Username = "username@domain/token"
$Token = "kasjdfkljasdfkjds"
$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 @params
$Tickets = $result.tickets
$Tickets

0


image avatar

Jakub

Zendesk Customer Care

When using an API token to authenticate with the Zendesk API, the username should be followed by /token and then the actual API token. The format should be "{email_address}/token:{api_token}". It looks like you have the /token in the right place, but you might be missing the colon : before the actual token.
 
Here's the corrected code:
 
$Username = "username@domain.com/token"
$Token = "kasjdfkljasdfkjds"
$Base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($Username):$($Token)"))
 
$params = @{
    Uri = "https://{subdomain}.zendesk.com/api/v2/requests.json"
    Method = 'Get'
    Headers = @{
        Authorization = "Basic $Base64AuthInfo"
    }
}
 
$result = Invoke-RestMethod @params
$Tickets = $result.tickets
$Tickets
 
Make sure to replace {subdomain} with your actual Zendesk subdomain, and ensure that $Username and $Token contain the correct values for your Zendesk account.
 
Also, note that $result is being used to store the result of Invoke-RestMethod, but in your original code, you didn't assign the result to the $result variable. I've added that assignment in the corrected code above.

0


Jakub 
Thank you.  There must be an issue on where I am running it.  I am using PowerShell Universal to run the API, and unfortunately it will not authenticate my token and email. 

0


image avatar

Jakub

Zendesk Customer Care

Upon reviewing and checking some external documentation, I would recommend following these steps If you are experiencing authentication issues with Zendesk API in PowerShell Universal:
 
  1. Ensure that the script is running in an environment where it has access to the internet and is not being blocked by any firewalls or network policies.
     
  2. Double-check that the email address and token are correct. The email should be the one associated with your Zendesk account, and the token should be generated from the Zendesk Admin interface.
     
  3. Make sure you are using the correct API endpoint for your Zendesk subdomain. Replace {subdomain} with your actual Zendesk subdomain in the URI.
     
  4.  Ensure that you are encoding your credentials correctly. The $Username variable should include your email followed by "/token" and the $Token variable should be your API token.

0


Jakub
Thank you.  I think there may have been an issue with the token I was using.  Is there are difference in using the a token created in App Integration verses using the token that is created via Api (.../oauth/tokens/)?

0


image avatar

Jakub

Zendesk Customer Care

Yes, those are two different tokens, one is API token and the other one is Oauth token. You can read about each approach here

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post