You can't directly add a file to a ticket, but y can upload a file and attach it to a ticket comment. The attachment appears in the ticket comment. You can only attach the uploaded file to a ticket comment with the Tickets API when adding the comment to a ticket you're creating or updating. To make things easier we use an existing php library.
Official API documentation: https://developer.zendesk.com/api-reference/ticketing/tickets/ticket-att...
Source code viewer
// https://github.com/zendesk/zendesk_api_client_php use Zendesk\API\HttpClient as ZendeskAPI; $client = new ZendeskAPI(ZENDESK_SUBDOMAIN); $client->setAuth('basic', ['username' => ZENDESK_USERNAME, 'token' => ZENDESK_TOKEN]); $domain = 'https://' . ZENDESK_SUBDOMAIN . '.zendesk.com/'; function putFile($path, $type, $name) { $attachment = $client->attachments()->upload([ 'file' => $path, 'type' => $type, 'name' => $name, ]); return $attachment->upload->token; } $client->tickets()->create([ // 'subject' => $data['subject'], // 'requester' => [ // 'locale' => $data['language'] === 'en' ? 'en-US' : $data['language'], // 'name' => $data['name'], // 'email' => $data['email'], // 'phone' => $data['phone'], // 'user_fields' => [ // ... // ], // ], // 'description' => $data['description'], // 'comment' => [ // 'public' => false, // 'html_body' => $data['comment'], 'uploads' => [ putFile($path, $type, $name) ], // ], // 'group_id' => $data['group_id'], // 'custom_fields' => $custom_fields, // 'priority' => 'normal', ]);Programming Language: PHP