datana-gmbh/zendesk-api

API for Zendesk

2.0.1 2024-01-31 10:43 UTC

This package is auto-updated.

Last update: 2024-10-30 02:05:30 UTC


README

Usage

Installation

composer require datana-gmbh/zendesk-api

Setup

use Zendesk\API\HttpClient;

$subdomain = 'company'
$username  = 'username'
$token  = '...'

$client = new HttpClient($subdomain);
$client->setAuth('basic', [ 'token' => $token, 'username' => $username ]);

Tickets

In your code you should type-hint to Datana\Zendesk\Api\TicketsApiInterface

Create a ticket

use Datana\Zendesk\Api\Domain\Value\Ticket;
use Datana\Zendesk\Api\TicketsApi;
use Zendesk\API\HttpClient;

$client = new HttpClient(/* ... */);

$ticketsApi = new TicketsApi($client);

$ticket = new Ticket(/* ... */);
$responseAsBool = $ticketsApi->create($ticket);

Create a ticket with attachments

use Datana\Zendesk\Api\Domain\Value\Ticket;
use Datana\Zendesk\Api\TicketsApi;
use Datana\Zendesk\Api\AttachmentsApi;
use Zendesk\API\HttpClient;

$client = new HttpClient(/* ... */);

$attachmentsApi = new AttachmentsApi($client);

$upload = $attachmentsApi->create(/** ... */)

$ticketsApi = new TicketsApi($client);

$ticket = new Ticket(/* ... */ );
$responseAsBool = $ticketsApi->create($ticket);

Custom field definition

<?php

declare(strict_types=1);

namespace App\Bridge\Zendesk\CustomFields;

use Datana\Zendesk\Api\Domain\Value\CustomFieldInterface;

final class SampleCustomField implements CustomFieldInterface
{
    public function id(): int
    {
        return 1231332332;
    }

    public function value(): mixed
    {
        return 'sample value';
    }
}