Skip to content

Commit

Permalink
Merge pull request #292 from zendesk/kcasas/tickets-with-attachments
Browse files Browse the repository at this point in the history
Creation of tickets with attachment on readme and sample
  • Loading branch information
kcasas authored Nov 17, 2016
2 parents 5b61a38 + 314d217 commit c9cf285
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ $attachment = $client->attachments()->upload([
]);
```

Attaching files to comments

``` php
$ticket = $client->tickets()->create([
'subject' => 'The quick brown fox jumps over the lazy dog',
'comment' => [
'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' .
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
'uploads' => [$attachment->upload->token]
]
]);
```

### Side-loading

Side-loading allows you to retrieve related records as part of a single request. See [the documentation] for more information. (https://developer.zendesk.com/rest_api/docs/core/side_loading).
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<strong>Tickets</strong>
<ul>
<li><a href="samples/tickets/qcreateTicket.php">Create a new ticket.</a></li>
<li><a href="samples/tickets/createTicketWithAttachment.php">Create a new ticket with attachment.</a></li>
<li><a href="samples/tickets/createTicket.php">Create a new ticket with the requester's email address, if the requester's identity doesn't exist.</a></li>
<div class="clearfix">&nbsp;</div>
Expand Down
49 changes: 49 additions & 0 deletions samples/tickets/createTicketWithAttachment.php
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.';
}

0 comments on commit c9cf285

Please sign in to comment.