Getting 401 'Unauthorized' error when using CURL, works OK when pasted in browser

9 Comments

  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Hi Pierre Clouthier,

    This is indeed an encoding problem. Since your password contains special characters, you should use base64 encoding.

    Use base64 command in bash or any similar tool:

    echo 'myemail:mypassword' | base64

    You should get something like `bXllbWFpbDpteXBhc3N3b3JkCg==`

    Then instead of 

    -u myemail:mypassword, 

    Use

    -H 'Authorization:  Basic bXllbWFpbDpteXBhc3N3b3JkCg=='

    Luckily, this problem has saved your exact password from being revealed in the post. However, I urge you to reset your password immediately.

    0
  • Pierre Clouthier

    Thank you very much for your reply.

    I have tried this method, but I'm still getting rejected ("HTTP/1.1 401 Unauthorized").

    Does Zendesk have to turn on an option for my account?

    Why do I need to change my password? "my-domain" and " my@email.com:my#password" are made-up and fictitious.

    BTW the example includes the trailing line feed (x0A) ("Cg==").

    0
  • Pierre Clouthier

    I have removed the special character from the password, and I am still getting "HTTP/1.1 401 Unauthorized", so that does not appear to be the problem.

    Any suggestions?

    0
  • James Rodewig
    Zendesk Documentation Team

    Hi Pierre,

    Have you enabled password API access for your account?

    There is some related documentation here: https://support.zendesk.com/hc/en-us/articles/4408836402074-Using-the-API-dashboard#enabling_password_or_token_access

    I hope that helps!

    0
  • Pierre Clouthier

    Hi James -

    Thank you for your reply. API password access was indeed enabled for my account:

    Still not working.

    I'm using a password, not a Token.

    Note that it works if I copy & paste the URL in my browser. It's just the cURL call that fails.

    I would very much like it to work with cURL  :o)

    0
  • James Rodewig
    Zendesk Documentation Team

    Hi Pierre,

    Do you have 2-factor authentication enabled for your user profile? If you have 2-factor authentication enabled for your profile, you won't be able to use basic authentication. We call this out in the docs here.

    0
  • Pierre Clouthier

    Yes, I have 2FA activated. I will study the documentation and see if I can figure this out.

    Thank you again.

    0
  • Pierre Clouthier

    HOORAY! It works!

    The solution is to use:

    curl https://my-domain.zendesk.com/api/v2/users.json -v -u my@email.com/token:my-token

    The token is obtained in the Admin Center, "Apps and Integrations", "Zendesk API", Turn on Token Access, and "Add API token".

    Suggestion: it would be really helpful if this were referenced in the Users API documentation, for example https://developer.zendesk.com/api-reference/ticketing/users/users/

    Thank you again  :o)

     

    0
  • James Rodewig
    Zendesk Documentation Team

    Congrats, Pierre! I'm glad to hear you got everything working.

    0

Please sign in to leave a comment.

Powered by Zendesk