Trying to create api via c# | Community
Skip to main content

Trying to create api via c#

  • April 22, 2025
  • 1 reply
  • 0 views

I'm attempting to create a class in my application that will integrate with Zendesk.  However when I'm attempting to create a ticket I keep getting an error…
The remote server returned an error: (401) Unauthorized.Error content: {"error":"Couldn't authenticate you"} 

 

This is the code I'm using to create the api

            public ZendeskHelper()
           {
               string subdomain = ConfigurationManager.AppSettings["ZendeskSubdomain"];
               string email = ConfigurationManager.AppSettings["ZendeskEmail"];
               string apiToken = ConfigurationManager.AppSettings["ZendeskApiToken"];
               // Ensure credentials are not null or empty
               if (string.IsNullOrEmpty(subdomain) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(apiToken))
               {
                   throw new InvalidOperationException("Zendesk API credentials are not properly configured in Web.config.");
               }
               
               api = new ZendeskApi($"https://{subdomain}.zendesk.com/api/v2/users/me.json", email, apiToken);
           }

 

How do I resolve this?

1 reply

  • April 22, 2025

Hi Eduardo, 

Does the string in your `email` variable include the suffix ‘/token’? Example:

jdoe@example.com/token’

See https://developer.zendesk.com/api-reference/introduction/security-and-auth/#api-token.