# Get tickets

## getTickets()

This will return all tickets sorted by the last changed date. hostware uses this information to check if any tickets have new admin answers, which are then imported using another function (TODO).

### Parameters

None.

### Response

Collection of TicketResponse() classes. Each class contains the following attributes:

<table><thead><tr><th width="142">Type</th><th width="166">Name</th><th>Description</th></tr></thead><tbody><tr><td>mixed</td><td>id</td><td>The ID of the ticked. Usually integer or UUID.</td></tr><tr><td>mixed</td><td>number</td><td>The number of the ticket. Sometimes, ticket systems have a readable display number</td></tr><tr><td>mixed</td><td>customerId</td><td>The ID of the customer/contact in the ticketsystem. No mapping necessary</td></tr><tr><td>mixed</td><td>customerEmail</td><td>The mail of the customer/contact in the ticketsystem.</td></tr><tr><td>mixed</td><td>subject </td><td>The subject of the ticket.</td></tr><tr><td>mixed</td><td>statusId</td><td>The current status of the ticket</td></tr><tr><td>Carbon</td><td>createdAt</td><td>The date of creation</td></tr><tr><td>Carbon</td><td>lastChangeAt</td><td>The date of last change</td></tr><tr><td>Int or Null</td><td>departmentId</td><td>The department id in the ticketsystem</td></tr><tr><td>String or Null</td><td>notes</td><td>Optional notes attached to the ticket</td></tr></tbody></table>

### Example Code

```php
public function getTickets(): Collection {
	$response = $this->makeRequest("conversations", "GET", [
		"sortField" => "updatedAt",
		"sortOrder" => "desc",
		"pageSize" => 150
	]);
	$tickets = [];

//		dd(count($response->_embedded->conversations));

	foreach ($response->_embedded->conversations as $conversation) {
		if ($conversation->customer === null) {
			continue;
		}

		$tickets[] = new TicketResponse(
			$conversation->id,
			$conversation->number,
			$conversation->customer->id,
			$conversation->customer->email,
			$conversation->subject,
			$conversation->status,
			Carbon::parse($conversation->createdAt, "UTC")->setTimezone("Europe/Berlin"),
			Carbon::parse($conversation->updatedAt, "UTC")->setTimezone("Europe/Berlin"),
			$conversation->mailboxId,
			null
		);
	}

	return collect($tickets);
}
```

### Testing

You can test this function when executing the following console command. This requires that you have a ticket in the database, where the ticket\_provider\_id is equal to your provider name.

The function gets called synchronously, you can dump() and debug as you like.

```bash
php artisan hw:synchronizeTicketProviders
```
