homedesignshops/laravel-zendesk

A Laravel Zendesk wrapper for the Zendesk API client

1.0.3 2019-02-25 10:17 UTC

This package is auto-updated.

Last update: 2024-11-04 09:40:04 UTC


README

Build Status Total Downloads Latest Stable Version License

Laravel Zendesk

This package provides an elegant wrapper for the official Zendesk API php library. It supports creating tickets, retrieving and updating tickets, deleting tickets, etc.

Installation

Install this package via Composer using:

composer require homedesignshops/laravel-zendesk

Laravel 5.5+ users: Skip the Service Provider installation below, because the package is configured for Package Discovery.

// config/app.php
'providers' => [
    ...
    Huddle\Zendesk\Providers\ZendeskServiceProvider::class,
    ...
];

Configuration

Publish the config file to app/config/zendesk.php run:

php artisan vendor:publish --provider="HomeDesignShops\Zendesk\ZendeskServiceProvider"

Set your configuration using environment variables in your .env file:

ZENDESK_SUBDOMAIN

The subdomain part of your Zendesk organisation.

Example: If your organisation domain is https://homedesignshops.zendesk.com, then use homedesignshops as the subdomain

ZENDESK_USERNAME
The username for the authenticating account in your Zendesk organisation.

ZENDESK_TOKEN
The API access token. This can be a basic token or your oauth token. You can manage your tokens one at: https://{SUBDOMAIN}.zendesk.com/agent/admin/api/settings

Usage

Helper

The Zendesk helper acts as a wrapper for an instance of the Zendesk\API\Client class. You can find all the methods available on this class in the zendesk/zendesk_api_client_php repository. All of the methods are available through the helper.

Examples

<?php
// Get all tickets
zendesk()->tickets()->findAll();

// Create a new ticket
zendesk()->tickets()->create([
  'subject' => 'Ticket subject',
  'comment' => [
      'body' => 'Test ticket content'
  ],
  'priority' => 'normal'
]);

// Update ticket status to urgent
zendesk()->tickets(123)->update([
  'status' => 'urgent'
]);

// Delete a ticket
zendesk()->tickets(123)->delete();

Dependency injection

<?php

use HomeDesignShops\Zendesk\ZendeskClient;

class TicketsClass {

    protected $zendeskClient;

    public function __construct(ZendeskClient $zendeskClient) {
        $this->zendeskClient = $zendeskClient;
    }

    public function addTicket() {
        $this->zendeskClient->tickets()->create([
              'subject' => 'Subject',
              'comment' => [
                    'body' => 'Ticket content.'
              ],
              'priority' => 'normal'
        ]);
    }

}

This package is available under the MIT license.