hutsi / yii2-zendesk
Yii2 zendesk plugin
Installs: 1 351
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 3
Forks: 3
Open Issues: 1
Type:extension
Requires
- php: >=5.4.0
- understeam/yii2-httpclient: >=0.2
- yiisoft/yii2: >=2.0.0
This package is not auto-updated.
Last update: 2025-03-29 20:03:48 UTC
README
Yii2 plugin for zendesk service support (https://www.zendesk.com)
How to use:
Add the following line to composer.json, require section
"require": { "hutsi/yii2-zendesk": ">=3.3", }
Add a component to your main.php config file
'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' ] ]
The most simple example is: Create an instance of Zendesk Client
$client = new hutsi\zendesk\Client();
Execute
$results = $client->execute('GET', '/users.json', []);
OR
$results = $client->get('/users.json', []);
Another variant is to use build-in plugin functions to work with Users, Tickets, Search, Attachments instances. In your form handler use:
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;
If you wants to use upload, you should use a well-known \yii\web\UploadedFile
instanse
$uploadedFile = new UploadedFile(['tempName' => 'YOUR_FILE_TEMPNAME', 'name' => 'YOUR_FILE_NAME]);
Then - create and save zendesk Attachment instance from UploadedFile
$zAttachment = new Attachment(['uploadedFile' => $uploadedFile]); $token = $zAttachment->save();
You can also use zendesk search API for existing Users of your zendesk account If there are no such users - let's create it
$search = new Search(['query' => ['email' => '"user@example.com"']]); if ($zUsers = $search->users()) { $zUser = $zUsers[0]; } else { $zUser = new User(['email' => 'user@example.com'); $zUser->save(); }
And finally, it's time to create a Ticket instance
$zTicket = new Ticket([ 'requester_id' => $zUser->id, 'requester' => [ 'email' => $zUser->email ], 'subject' => StringHelper::truncate('Problem: Authorization', 100), 'comment' => [ 'body' => 'Authorization not works!' ], ]);
If we had an uploads - attach them to a ticket comment field
$zTicket->comment['uploads'] = isset($token) && $token ? [$token] : null; $zTicket->save();
Thats all.