PHP code example of hutsi / yii2-zendesk

1. Go to this page and download the library: Download hutsi/yii2-zendesk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hutsi / yii2-zendesk example snippets


'components' =>
    'zendesk' => [
        'class' => 'hutsi\zendesk\Client',
        'apiKey' => 'YOUR_API_KEY',
        'user' => 'YOUR_USER',
        'baseUrl' => 'https://SUBDOMAIN.zendesk.com/api/v2',
        'password' => 'YOUR_PASSWORD',
        'authType' => 'basic'
    ]
]

$client = new hutsi\zendesk\Client();

$results = $client->get('/users.json', []);

use yii\helpers\StringHelper;
use hutsi\zendesk\Attachment;
use hutsi\zendesk\Search;
use hutsi\zendesk\Ticket;
use hutsi\zendesk\User;
use Yii;
use yii\web\UploadedFile;

$uploadedFile = new UploadedFile(['tempName' => 'YOUR_FILE_TEMPNAME', 'name' => 'YOUR_FILE_NAME]);

$zAttachment = new Attachment(['uploadedFile' => $uploadedFile]);
$token = $zAttachment->save();

$search = new Search(['query' => ['email' => '"[email protected]"']]);
if ($zUsers = $search->users()) {
    $zUser = $zUsers[0];
} else {
    $zUser = new User(['email' => '[email protected]');
    $zUser->save();
}

$zTicket = new Ticket([
    'requester_id' => $zUser->id,
    'requester' => [
        'email' => $zUser->email
    ],
    'subject' => StringHelper::truncate('Problem: Authorization', 100),
    'comment' => [
        'body' => 'Authorization not works!'
    ],
]);

$zTicket->comment['uploads'] = isset($token) && $token ? [$token] : null;
$zTicket->save();

$results = $client->execute('GET', '/users.json', []);