-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from zendesk/kcasas/tickets-with-attachments
Creation of tickets with attachment on readme and sample
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
include("../../vendor/autoload.php"); | ||
|
||
use Zendesk\API\HttpClient as ZendeskAPI; | ||
|
||
/** | ||
* Replace the following with your own. | ||
*/ | ||
|
||
$subdomain = "subdomain"; | ||
$username = "email@example.com"; | ||
$token = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; | ||
$attachment = getcwd().'/sample.jpg'; | ||
|
||
$client = new ZendeskAPI($subdomain); | ||
$client->setAuth('basic', ['username' => $username, 'token' => $token]); | ||
|
||
try { | ||
// Upload file | ||
$attachment = $client->attachments()->upload([ | ||
'file' => $attachment, | ||
'type' => 'image/jpg', | ||
'name' => 'sample.jpg' | ||
]); | ||
|
||
// Create a new ticket with attachment | ||
$newTicket = $client->tickets()->create(array( | ||
'type' => 'problem', | ||
'tags' => array('demo', 'testing', 'api', 'zendesk'), | ||
'subject' => 'The quick brown fox jumps over the lazy dog', | ||
'comment' => array( | ||
'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', | ||
'uploads' => [$attachment->upload->token] | ||
), | ||
'requester' => array( | ||
'locale_id' => '1', | ||
'name' => 'Example User', | ||
'email' => 'customer@example.com', | ||
), | ||
'priority' => 'normal', | ||
)); | ||
|
||
// Show result | ||
echo "<pre>"; | ||
print_r($newTicket); | ||
echo "</pre>"; | ||
} catch (\Zendesk\API\Exceptions\ApiResponseException $e) { | ||
echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; | ||
} |