diff --git a/src/Zendesk/API/Resources/Core/Tickets.php b/src/Zendesk/API/Resources/Core/Tickets.php index 624817b5..3d8f66ca 100755 --- a/src/Zendesk/API/Resources/Core/Tickets.php +++ b/src/Zendesk/API/Resources/Core/Tickets.php @@ -93,6 +93,7 @@ protected function setUpRoutes() 'deleteMany' => 'tickets/destroy_many.json', 'collaborators' => 'tickets/{id}/collaborators.json', 'incidents' => 'tickets/{id}/incidents.json', + 'merge' => 'tickets/{id}/merge.json', 'problems' => 'problems.json', 'export' => 'exports/tickets.json', 'problemAutoComplete' => 'problems/autocomplete.json' @@ -378,7 +379,7 @@ public function export(array $params) $response = Http::send( $this->client, $this->getRoute('export'), - ["queryParams" => $queryParams] + ['queryParams' => $queryParams] ); return $response; @@ -406,4 +407,34 @@ public function attach(array $params = []) return $this; } + + /** + * @param array $params + * + * @throws MissingParametersException + * @throws ResponseException + * @return Tickets + */ + public function merge(array $params = []) + { + $params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]); + + if (! $this->hasKeys($params, ['id', 'ids'])) { + throw new MissingParametersException(__METHOD__, ['id', 'ids']); + } + + $route = $this->getRoute(__FUNCTION__, ['id' => $params['id']]); + unset($params['id']); + + $response = Http::send( + $this->client, + $route, + [ + 'method' => 'POST', + 'postFields' => $params, + ] + ); + + return $response; + } } diff --git a/tests/Zendesk/API/UnitTests/Core/TicketsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketsTest.php index 16bf0ea7..2965fd04 100755 --- a/tests/Zendesk/API/UnitTests/Core/TicketsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/TicketsTest.php @@ -295,4 +295,20 @@ public function testMarkManyAsSpam() $this->client->tickets()->markAsSpam([12345, 54321]); }, 'tickets/mark_many_as_spam.json', 'PUT', ['queryParams' => ['ids' => '12345,54321']]); } + + /** + * Tests if the client can call the merge endpoint. + */ + public function testMerge() + { + $params = [ + 'ids' => [123, 234], + 'target_comment' => 'Closing in favor of #345', + 'source_comment' => 'Combining with #123, #234', + ]; + $ticketId = 345; + $this->assertEndpointCalled(function () use ($ticketId, $params) { + $this->client->tickets($ticketId)->merge($params); + }, "tickets/{$ticketId}/merge.json", 'POST', $params); + } }