How to get ticket attachment by API (PHP)

2 Comments

  • Satria Faestha
    Comment actions Permalink

    Okay. I got the answer from https://develop.zendesk.com/hc/en-us/community/posts/360001643548-How-to-get-attachment-id-from-a-ticket-id-

    But I still need to modify Zendesk/API/Resources/Core/Attachments.php to add new function 'comments'. it seems the naming not good and confusing but it's working for me.

    protected function setUpRoutes()
    {
       $this->setRoutes([
          'upload' => "uploads.json",
          'deleteUpload' => "uploads/{token}.json",
          'show' => "attachments/{id}.json",
          'comments' => "tickets/{id}/comments.json"
       ]);
    }

    public function comments($id=null)
    {
       $response = Http::send(
          $this->client,
          $this->getRoute(__FUNCTION__, ['id' => $id]),
          ['method' => 'GET']
       );

       return $response;
    }

    Then I call the function like this:
    $attachments = $client->attachments()->comments($ticketId);

    0
  • Greg - Community Manager
    Comment actions Permalink

    Thank you for sharing your solution, Satria Faestha! IF you've moved this into further testing/production, could you let us know if you've run into any problems with this? If so, please let us know to see if we can help.

    0

Please sign in to leave a comment.

Powered by Zendesk