Question
How can I authenticate API requests using one of Zendesk v2 APIs?
Answer
You must be a verified user to make authenticated API requests. To authenticate API requests, use basic authentication with your email address and password, your email address and an API token, or an OAuth access token.
All methods of authentication set the authorization header differently. Credentials sent in the payload or URL are not processed. Each option is listed below:
- Password authentication
- API token authentication
- OAuth access token authentication
- Viewing your authorization header
Password authentication
If you use basic authentication, combine your email address and password to generate the authorization header. To use basic authentication, enable Password access in Admin Center under Apps and integrations > APIs > Zendesk API, as well as within the relevant authentication section, either team member or end user.
Format the email address and password combination to be an Base-64
encoded string. For an example of how to format the authorization header, see the code block below.
Authorization: Basic {base-64-encoded email_address:password}
API token authentication
If you use an API token, combine your email address and API token to generate the authorization header. Format the email address and API token combination to be an Base-64
encoded string. For an example of how to format the authorization header, see the code block below.
Authorization: Basic {base-64-encoded email_address/token:api_token}
OAuth access token authentication
If you use OAuth to authenticate, format the authorization header this way:
Authorization: Bearer oauth_access_token
For more information, see this article: Using OAuth authentication with your application.
Viewing your authorization header
To see exactly what your app sends, use a third-party page such as Request Bin. Compare your headers to those being generated by a webhook using an OAuth authentication. Point the webhook to your requestb.in URL and, on the Add webhook page, click Test webhook to see this in action.
Once the request hits your requestb.in, it appears like this:
The string after Authorization: Bearer
is the API key provided by RequestBin in your account settings under Programmatic Access.
If you use Python to make requests, set your session headers as follows:
session = requests.Session()
session.headers = {'Content-Type': 'application/json', 'Authorization': 'Basic Basic_64_encoded_code'}
For more information, see the developer documentation: Security and authentication.
20 comments
Bonaliza Garcia
Hi, I'm working on a custom request form for our end-users (but still within our Zendesk subdomain). When I try to submit the form and send the data to create the request, it returns with a 403 error. The same code works on postman and the request is being created.
I'm having a hard time figuring out why im getting a 403. I tried both email/token:api_key authentication and basic email:password authentication.
https://support.zendesk.com/hc/en-us/community/posts/1260800839050-403-error-when-creating-request-via-API
0
Tomer Ben Arye
@...
I think my code 5 post above will help you.
https://support.zendesk.com/hc/en-us/articles/115000510267/comments/360005066074
0
Bonaliza Garcia
@Tomer did you mean the base64 encoded? I did that, my email/token:api_token is encoded. I tried manually encoding it using one of the websites and also dis btoa('email/token:api_token'); but both gave me a 403 error.
0
Bheem Aitha
Hi @...
I am getting the same authentication error. Can you please help me on this? I also created a ticket on this.
C:\Users\yyy> curl https://<subdomain>.zendesk.com/api/v2/users.json -u yyy@<company>.com/token:xxxxxxx
{"error":"Couldn't authenticate you"}
Thanks
-Bheem
1
Waseem Khan
Hi Team,
Precindition: Token is created in zendesk
I as an admin share my email address and token with other team member. Can they acess the API's? or is it like i need to login to zendesk from the same system/pc from where the user is trying to access the API's?
Or they can just pass my email address and token simply without i being logged in to zendesk?
Regards,
Waseem
0
Dwight Bussman
Waseem Khan
Simply having your email & API token is sufficient for any user to make API requests on behalf of your user. This gives them the ability to do anything your user would be able to do via the API. This includes deleting things like tickets/users/organizations/articles/sections/categories/triggers which can be very destructive. For this reason, I would encourage you to be very selective about who has access to these tokens.
0
Nick Bolton
Please make it clearer on this page that you have to Base-64 encode the token. Here's the command that I used on Mac to Base-64 encode my token.
4
Dwight Bussman
HeyO Nick,
Thanks for the feedback. I will make updates to this article to make that clearer.
1
Dan Reyes-Cairo
I just ran into and resolved an issue using Postman for API requests where the following was returned:
Per the API documentation I was using the following so everything should have been set up correctly:
Turns out, when the base64 encoded Authentication value was being decoded in Postman, it was adding an additional colon : to the decoded username string (I had to check this using a third-party decoding site).
To resolve, I had to:
At that point my requests started going through. Hope this helps anyone else that runs into this with Postman!
2
Ramy Ben Aroya
I have setup SSO for my end users.
I want to show some of the Zendesk content on my own web app platform without having to proxy the requests to Zendesk API through my server.
Is there any option to issue /api/v2/help_center/* requests with the JWT token I get from /access/jwt endpoint?
Also what about CORS? Of course for now I get only 401 response but I see it is not supporting cross origin requests.
2
Fraser, Vanessa
Hi! I'm trying to use Azure Logic Apps to Authentic for a POC but I keep getting 401 Couldn't authenticate you.
I've encoded my username/token:aaaa via powershell this way but I must be missing something.
$text = "myname@mydomain.com/token:tokentexthere"
$encoded = [convert]::ToBase64String([text.encoding]::Unicode.GetBytes($text))
$encoded
I went through this article and tried OAuth, api, user/password but just not getting authenticated.
Any ideas would be welcome!
0
Dwight Bussman
Hi Fraser, Vanessa
After doing that encoding are you passing the encoded value in as a Basic Authorization header as documented here: https://developer.zendesk.com/api-reference/introduction/security-and-auth/#basic-authentication
If that doesn't help sort things out for you, I recommend contacting our support team to look into logs for your specific account.
0
Fraser, Vanessa
I'm sure it is something I'm doing wrong but I have been over and over that article and am not seeing what I have done wrong. I'll contact support. Also I can curl using the email/token:tokeninfo so it has to do with my encoding of the email/token:tokeninfo.
0
Felipe Costa
Hello, SSO authentication works to customer's side?
We don't have our customer's zendesk password.
0
Dane
Yes, you can use SSO for your end users. Please refer to Providing multiple sign-in options for team members and end users.
-1
Dermot Doran Cato Networks
Hi All!
If you are working on macOS, I recommend that you follow the tip given by Nick Bolton. I tried to create the base64 code using the -i option of the base64 comman, but it kept adding an extra character to the end of encoded output.
Cheers!!
Dermot
0
Benedikt Hild
Hi All,
I ran into the same issues described by some people. Here's my working solution:
I enconded the credentials mentioned on the dokumention '{email_address}/token:{api_token}'
with UTF-8.
$Base64AuthInfo = "{email_address}/token:{api_token}"
$Base64AuthInfo = [convert]::ToBase64String([text.encoding]::UTF8.GetBytes($Base64AuthInfo))
My previous attempt encoding with unicode did not work.
$Base64AuthInfo = "{email_address}/token:{api_token}"
$Base64AuthInfo = [convert]::ToBase64String([text.encoding]::Unicode.GetBytes($Base64AuthInfo))
Maybe a mention of that could be usefull inside the API documentation.
Cheers!!
Benedikt
2
Glenn Chen
Hi all
I have similar concern with Ramy Ben Aroya' s comment here
I want to show some Zendesk content in my web app. As far as I know, I can do it either through Oauth2 or by making a request on behalf of an user, but eventually I will need end users' passwords, is there a way I can do it without having to request their passwords?
0
Paolo
If you need the actual user's password, unfortunately, there is no way on getting this unless you ask them. In addition, it is not recommended to have your end user's password as this may arise security concerns. Can you please explain further the purpose of why the actual user password is needed, and the an OAuth or a token is not sufficient?
Best,
Paolo | Technical Support Engineer | Zendesk
0
Glenn Chen
Hi Paolo,
First, I need to emphasize that “I don't want to ask users about their passwords”.
I want to show some Zendesk content in my web app based on users' authorization status.
If I go with Oauth2, I will need to ask user's password, this is the example from Oauth2 Password grant type
If I go with Making API requests on behalf of end users, I also need password from the user.
Either way I need users' passwords to do it, is there a way I can do it without requesting their passwords?
0