REST API authentication changes - .NET/PowerShell



  • Matt McGrath
    Comment actions Permalink

    Thanks also to Alex Perez from Zendesk Support who pointed us in the right direction!

  • Matt McGrath
    Comment actions Permalink

    Our developers were horrified that I said we couldn't get the splatting to work properly. I meant to say 'at the time'... We now have it working correctly :)

  • Maximilian Kless
    Comment actions Permalink

    Thanks for this! It didn't work for me at first (perhaps there was another update to the API) but I got it working by using "/token:" instead of ":" in the headers.

    So, my params object is:

    $params = @{

                    Uri = "";

                    Method = 'Get';

                    Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($username)/token:$($token)"));}


  • JD Mills
    Comment actions Permalink

    Thanks all, I was able to work token authentication into my own scripts using the examples you provided. Here's an example of a quick PowerShell script that returns a ticket using an ID you specify. I hope it helps someone.


    $headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($env:ZendeskAPI_Username):$($env:ZendeskAPI_Token)"));}
    #where $env:ZendeskAPI_Username and $env:ZendeskAPI_Token are system environmental variables.
    #where $env:ZendeskAPI_Username is set to

    $ticketID = Read-Host "What is the Zendesk ticket number?"

    $ticketsURI = "$ticketID.json"

    $ticket = Invoke-RestMethod -Uri $ticketsURI -Method Get -Headers $headers -ContentType "application/json"

    $ticket = $ticket.ticket

    return $ticket
  • Peter Hochstrasser
    Comment actions Permalink

    A short notice to PS Users: Since about May or June 2018, the script above will not authenticate. The reason is TLS - while Windows apparently defaults to 1.0, Zendesk wants to use 1.2.

    The error you'll get is something like this:

    The underlying connection was closed. An unexpected error occurred on a send.

    The correction is simple, once you find the solution in a post like this one:


    Simply add the line 

      [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;

    before calling the Invoke-RestMethod commandlet, and all works as before.


  • Joey
    Comment actions Permalink

    Thanks for the tip, Peter!

  • Rlindstrom
    Comment actions Permalink

    Thanks for the help.  I had to add the following line to the C# code in my CLR to use TLS 1.2 to communicate with the REST API.

    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;

    Once this line was added before the WebRequest was issued the API calls worked again.


Post is closed for comments.

Powered by Zendesk