Trying to create api via c#



投稿日時:2025年4月22日

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?


0

1

1件のコメント

      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.

      0


      サインインしてコメントを残します。

      お探しのものが見つかりませんか?

      新規投稿