4

I have to access a page from the zendesk.com from my MVC application. I have username and authenticate ticket. When I try to access that page it is returning the error "The remote server returned an error: (401) Unauthorized". Here is the code for the authentication

 string authTicket = "asdfsafdsafsdafdsafsf";       
 username = "user@mysite.com";
 string api_url = "https://mysite.zendesk.com/users/current.json";  
 string base64_creds = Convert.ToBase64String(Encoding.UTF8.GetBytes(username + ":" + authTicket));
 HttpWebRequest request = WebRequest.Create(api_url) as HttpWebRequest;
 request.Headers.Add("Authorization", "Basic " + base64_creds);
 using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
 {
      StreamReader reader = new StreamReader(response.GetResponseStream());
      string content = reader.ReadToEnd();
      //return Content(content);
      return View("https://mysite.zendesk.com/entries/mypage");
 }
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Pankaj Saha
  • 869
  • 3
  • 17
  • 37

3 Answers3

0

Same sort of thing happened to me. Unfortunately, my background is in the Zendesk API Ruby client, but I'll try to help out.

It's not completely clear to me whether you're using token access with your API token or password access with a username/password combination, but it looks like you're using password access (if it's token access, then the colon format won't work). Double check the API docs and see whether the endpoint is only allowed for agents or end-users, and make sure the credentials you're providing match up with the required credentials.

Also, Log in to your Zendesk with an admin account and make sure you enabled token access if you're using a token, or password access if you're using your password.

tanbrian
  • 13
  • 3
0

Some of you will run into this issue when connecting to various Zendesk accounts around the place. Some percentage of Zendesk accounts have an IP whitelist setup, meaning that you can only make requests from explicitly allowed IP addresses or ranges. There is no specific error message for a blocked IP, but it's something like "Can't authenticate you".

Vincent
  • 2,963
  • 1
  • 19
  • 26
0

Not sure, but you might want to enable Zendesk API from Admin Center-> Apps and Integrations -> Zendesk API -> Settings (after enabling Zendesk API) -> Password Access. I got error: 403, and doing this solved the issue for me.

Parthesh Soni
  • 133
  • 1
  • 6