OpenSourced: The ZendeskApiClient

Introducing the JUSTEAT ZendeskApiClient

A few months ago we started using Zendesk to manage our engagements with our customer and with our partners. Zendesk provides an API which is a really important tool for us as we need to be able to hook our internal systems into the data we have saved in Zendesk.
We wanted a lightweight tool to enable us to RESTfully connect with the Zendesk Api with a minimal code. We wanted to only be returned data for the objects we were working with. We needed to make sure our solution was well tested. Finally, we wanted to be able to reuse the code within a number of our internal systems. The result was the ZendeskApiClient

So how does this thing work?

The ZendeskApiClient comes as a NuGet package. Install it, then create yourself a client:

IZendeskClient client = new ZendeskClient(
    new Uri("https://my-zendesk-api-host-endpoint"),
    "my-zendesk-username",
    "my-zendesk-token"
);

Once you’ve got your client, you’ll have access to a number of resources:

client.Tickets...
client.Organizations...
client.Users...
client.Groups...

These resources can be called RESTfully like this:

IResponse response = client.Tickets.Get((long)1234);
IListResponse response = client.Tickets.GetAll(new List { 1234, 4321 });
IResponse response = client.Tickets.Put(new TicketRequest{ Item = ticket });
IResponse response = client.Tickets.Post(new TicketRequest { Item = ticket });
client.Tickets.Delete((long)1234));

Paging and filtering is also pretty useful when you’re working with organisations and tickets in Zendesk, so we added that into the client.

IZendeskQuery query = new ZendeskQuery();
query.WithPaging(pageNumber:2, pageSize:10);
query.WithCustomFilter(field:"name", value:"Coffee Express");
query.WithOrdering(orderBy:OrderBy.created_at, order:Order.Relevance);
IResponse response = client.Search.Find(query);

We hate reading documentation as much as the next developer, so we went for a discoverable approach:

IResponse response = client.Search.Find(
    new ZendeskQuery()
    .WithCustomFilter("email", "[email protected]")
);
IResponse response = client.Search.Find(
    new ZendeskQuery()
    .WithCustomFilter("name", "Cupcake Cafe")
);

So is this an all signing, all dancing client?

Well… no. We work in a pretty Agile way so we only implemented the methods that we needed. Having said that, we are making good use of Zendesk so the client is likely to provide you with most of the resources you need to get started. We like our code clean and we tried to make the client easily extensible and well tested. Hopefully this will make it easy to extend and work with if you do need to add more functionality and collaborate with us on this project.

Can I steal it?

Yes. Take it. Put it into your application. Sell it on Ebay. Give it to your mum as a birthday present. We like to be pretty liberal about the stuff we open source. Check out the license on our GitHub repo. If you do take it and you’re feeling community spirited, contribute back.

Downloads

Source code is available on GitHub here:
https://github.com/justeat/ZendeskApiClient
NuGet packages available here:
http://www.nuget.org/packages/ZendeskApiClient

  1. Hi,
    I dont seem to be able to pass the correct arguments? I get a build error ‘has some invalid arguments’
    I dont know if my endpoint is wrong or am i missing arguments?
    regards
    Tony
    ***
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using ZendeskApi.Client;
    using ZendeskApi.Contracts;
    using Newtonsoft.Json;
    namespace zen2
    {
    class Program
    {
    static void Main(string[] args)
    {
    string user = “[email protected]”;
    string token = “4HVltXNHiTv9aTJuVVla3xxxxxxxxxxxxxxxxx”;
    Uri endPoint = new Uri(“https://company.zendesk.com/api/v2”);
    Uri endPoint2 = new Uri(“https://company.zendesk.com/api/v2/users/me.json”);
    Uri endPoint3 = new Uri(“https://company.zendesk.com/”);
    IZendeskClient client = new ZendeskClient(endPoint,user,token);
    }
    }
    }

    1. Hello,
      Try is without the ‘api/v2’ on the end like this ‘Uri endPoint = new Uri(“https://company.zendesk.com/”);’.
      Let me know if that works,
      Kate

  2. Hi, I get an error when trying to use the query:
    IZendeskQuery query = new ZendeskQuery();
    This results in error: Using the generic type ‘IZendeskQuery’ requires 1 type arguments, is this a bug or Im I doing something wrong?
    Furthermore I wonder how syntax for getting total amount of created tickets during a day would be like
    I have tried with “IListResponse response = client.Tickets.GetAll(new List { 1234, 4321 });”
    however that only returns count of specific ID(in this case 2 since we have tickets with ID 1234 and 4321).
    I wanna get all records during a specific day, is this possible?
    My code (that does not work since I have to insert two specific ID´s as far as I understand)
    var url = “https://MyOrganization.zendesk.com/api/v2/search.json?”;
    var query = “query=type:ticket created:2016-09-27”;
    var encodedQuery = HttpUtility.UrlEncode(query);
    var fullURL = url + query;
    IZendeskClient client = new ZendeskClient(
    new Uri(fullURL),
    new ZendeskDefaultConfiguration(“UserName”, “Password”));
    IListResponse response = client.Tickets.GetAll(new List {});
    response.TotalCount.ToString();

  3. Hello-
    I wanted to check how can I utilize the Create or Update multiple users endpoint of Zendesk API using this package. Basically I am trying to insert or update some end user accounts to our company’s Zendesk account. Thanks.

Comments are closed.