ExZendesk

Simple HTTPoison based helper library to interact with the Zendesk API

Installation

If available in Hex, the package can be installed as:

  1. Add ex_zendesk to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:ex_zendesk, "~> 0.1.0"}]
end
```
  1. Ensure ex_zendesk is started before your application:
```elixir
def application do
  [applications: [:ex_zendesk]]
end
```

Configuration

First you must configure the subdomain, username, and password. The library will check environment variables first and fall back to application configuration.

This library currently supports Basic authentication or API token authentication.

Usage

This library is a thin wrapper on top of HTTPoison

ExZendesk.start

ExZendesk.get "/api/v2/tickets.json?per_page=1"
  # => {:ok,
  # %HTTPoison.Response{body: %{count: 114,
  #  next_page: "https://storestartup.zendesk.com/api/v2/tickets.json?page=2&per_page=1",
  #  previous_page: nil,
  #  tickets: [%{allow_channelback: false, assignee_id: 1802891567,
  #     brand_id: 572847, collaborator_ids: [],
  #     created_at: "2016-03-01T07:03:12Z", custom_fields: [],
  #     description: "Hello,\r\nThis is a test ticket",
  #     due_at: nil, external_id: nil, fields: [], followup_ids: [],
  #     forum_topic_id: nil, group_id: 26814467, has_incidents: false, id: 38,
  #     organization_id: nil, priority: nil, problem_id: nil,
  #     raw_subject: "Test ticket", recipient: nil,
  #     requester_id: 5022882178, satisfaction_rating: nil,
  #     sharing_agreement_ids: [], status: "closed",
  #     subject: "Test Ticket",
  #     submitter_id: 5022882178, tags: [], type: nil,
  #     updated_at: "2016-05-07T17:01:56Z",
  #     url: "https://storestartup.zendesk.com/api/v2/tickets/38.json",
  #     via: %{channel: "web", source: %{from: %{}, rel: nil, to: %{}}}}]},
  # headers: [{"Server", "nginx"}, {"Date", "Fri, 12 Aug 2016 16:33:01 GMT"},
  # {"Content-Type", "application/json; charset=UTF-8"},
  # {"Content-Length", "1291"}, {"Connection", "keep-alive"},
  # {"X-Zendesk-API-Version", "v2"},
  # {"X-Zendesk-Application-Version", "v3.94.2"},
  # {"X-Zendesk-API-Warn",
  #  "Removed restricted keys [\"_json\"] from parameters according to whitelist"},
  # {"X-Frame-Options", "SAMEORIGIN"}, {"X-Rate-Limit", "700"},
  # {"X-Rate-Limit-Remaining", "699"},
  # {"Strict-Transport-Security", "max-age=31536000;"},
  # {"X-UA-Compatible", "IE=Edge,chrome=1"},
  # {"ETag", "\"8cd9c3920ce86f5b21141e6bcef72358\""},
  # {"Cache-Control", "must-revalidate, private, max-age=0"},
  # {"X-Zendesk-Origin-Server", "app41.pod6.iad1.zdsys.com"},
  # {"X-Request-Id", "5aa337af-21ba-4ef0-ce53-b8ca3a6bb1dc"},
  # {"X-Runtime", "0.188008"}, {"X-Rack-Cache", "miss"},
  # {"X-Zendesk-Request-Id", "1fcdee3a31262d9d3064"},
  # {"X-Content-Type-Options", "nosniff"}], status_code: 200}}

sample_ticket = %{ticket: %{subject: "testing", comment: %{body: "this is a test"}, requester: %{name: "John Doe", email: "jdoe@gmail.com"}}}

ExZendesk.post "/api/v2/tickets.json", sample_ticket
  # => {:ok,
  # %HTTPoison.Response{body: %{audit: %{author_id: 1802891567,
  #    created_at: "2016-08-12T16:40:14Z",
  #    events: [%{attachments: [], audit_id: 145382499768, author_id: 9343852848,
  #       body: "this is a test",
  #       html_body: "<div class=\"zd-comment\"><p dir=\"auto\">this is a test</p></div>",
  #       id: 145382499848, public: true, type: "Comment"},
  #     %{field_name: "subject", id: 145382500008, type: "Create",
  #       value: "testing"},
  #     %{field_name: "status", id: 145382500068, type: "Create", value: "open"},
  #     %{field_name: "priority", id: 145382500148, type: "Create", value: nil},
  #     %{field_name: "type", id: 145382500188, type: "Create", value: nil},
  #     %{field_name: "assignee_id", id: 145382500248, type: "Create",
  #       value: "1802891567"},
  #     %{field_name: "group_id", id: 145382500288, type: "Create",
  #       value: "26814467"},
  #     %{field_name: "requester_id", id: 145382500368, type: "Create",
  #       value: "9343852848"},
  #     %{body: "Your request ({{ticket.id}}) has been received and is being reviewed by our support staff.\n\nTo add additional # # comments, reply to this email.\n\n{{ticket.comments_formatted}}",
  #       id: 145382500448, recipients: [9343852848],
  #       subject: "[Request received] {{ticket.title}}", type: "Notification",
  #       via: %{channel: "rule",
  #         source: %{from: %{id: 64041887,
  #             title: "Notify requester of received request"}, rel: "trigger",
  #           to: %{}}}},
  #     %{body: "A ticket (\#{{ticket.id}}) by {{ticket.requester.name}} has been received. It is unassigned.\n\n{{ticket.comments_formatted}}",
  #       id: 145382500608, recipients: [1802891567],
  #       subject: "[{{ticket.account}}] {{ticket.title}}", type: "Notification",
  #       via: %{channel: "rule",
  #         source: %{from: %{id: 64041947,
  #             title: "Notify all agents of received request"}, rel: "trigger",
  #           to: %{}}}}], id: 145382499768,
  #    metadata: %{custom: %{},
  #      system: %{client: "Elixir/ExZendesk", ip_address: "173.65.209.214",
  #        latitude: 27.88669999999999, location: "Tampa, FL, United States",
  #        longitude: -82.5117}}, ticket_id: 173,
  #    via: %{channel: "api", source: %{from: %{}, rel: nil, to: %{}}}},
  #  ticket: %{allow_channelback: false, assignee_id: 1802891567,
  #    brand_id: 572847, collaborator_ids: [],
  #    created_at: "2016-08-12T16:40:14Z", custom_fields: [],
  #    description: "this is a test", due_at: nil, external_id: nil, fields: [],
  #    forum_topic_id: nil, group_id: 26814467, has_incidents: false, id: 173,
  #    organization_id: nil, priority: nil, problem_id: nil,
  #    raw_subject: "testing", recipient: nil, requester_id: 9343852848,
  #    satisfaction_rating: nil, sharing_agreement_ids: [], status: "open",
  #    subject: "testing", submitter_id: 9343852848, tags: [], type: nil,
  #    updated_at: "2016-08-12T16:40:14Z",
  #    url: "https://storestartup.zendesk.com/api/v2/tickets/173.json",
  #    via: %{channel: "api", source: %{from: %{}, rel: nil, to: %{}}}}},
  # headers: [{"Server", "nginx"}, {"Date", "Fri, 12 Aug 2016 16:40:14 GMT"},
  # {"Content-Type", "application/json; charset=UTF-8"},
  # {"Content-Length", "2665"}, {"Connection", "keep-alive"},
  # {"X-Zendesk-API-Version", "v2"},
  # {"X-Zendesk-Application-Version", "v3.94.2"},
  # {"X-Frame-Options", "SAMEORIGIN"},
  # {"Location", "https://partially.zendesk.com/api/v2/tickets/173.json"},
  # {"X-Rate-Limit", "700"}, {"X-Rate-Limit-Remaining", "699"},
  # {"Strict-Transport-Security", "max-age=31536000;"},
  # {"X-UA-Compatible", "IE=Edge,chrome=1"},
  # {"ETag", "\"71ffe41cfa9ce1e92dfd15a1de13822d\""},
  # {"Cache-Control", "max-age=0, private, must-revalidate"},
  # {"X-Zendesk-Origin-Server", "app44.pod6.iad1.zdsys.com"},
  # {"X-Request-Id", "deeaf0fd-e352-4102-c1e6-b8ca3a6bbce0"},
  # {"X-Runtime", "0.679025"}, {"X-Rack-Cache", "invalidate, pass"},
  # {"X-Zendesk-Request-Id", "4e1deda0879800940aeb"},
  # {"X-Content-Type-Options", "nosniff"}], status_code: 201}}