Anteris-Dev / autotask-client

An HTTP client for the Autotask API built with PHP.
MIT License
23 stars 16 forks source link

TicketAttachment Data is empty #69

Open Darrrren opened 2 years ago

Darrrren commented 2 years ago

When requesting a TicketAttachment, the fields returned and their contents are all correct. However the data: field is null

Here's an example response:

Anteris\Autotask\API\TicketAttachments\TicketAttachmentCollection {#1249
  #items: array:1 [
    0 => Anteris\Autotask\API\TicketAttachments\TicketAttachmentEntity {#1231
      #exceptKeys: []
      #onlyKeys: []
      +attachDate: Carbon\Carbon @1663332465 {#1242
        #endOfTime: false
        #startOfTime: false
        #constructedObjectId: "00000000000004da0000000000000000"
        #localMonthsOverflow: null
        #localYearsOverflow: null
        #localStrictModeEnabled: null
        #localHumanDiffOptions: null
        #localToStringFormat: null
        #localSerializer: null
        #localMacros: null
        #localGenericMacros: null
        #localFormatFunction: null
        #localTranslator: null
        #dumpProperties: array:3 [
          0 => "date"
          1 => "timezone_type"
          2 => "timezone"
        ]
        #dumpLocale: null
        #dumpDateProperties: null
        date: 2022-09-16 12:47:45.607 +00:00
      }
      +attachedByContactID: null
      +attachedByResourceID: 29682955
      +attachmentType: "FILE_ATTACHMENT"
      +contentType: "image/png"
      +creatorType: 1
      +data: null
      +fileSize: 2359088.0
      +fullPath: "filetest.png"
      +id: 296079
      +impersonatorCreatorResourceID: null
      +opportunityID: null
      +parentAttachmentID: null
      +parentID: 72529
      +publish: 1
      +ticketID: 72529
      +ticketNoteID: null
      +timeEntryID: null
      +title: "Test Image"
      +userDefinedFields: null
    }
  ]
  #escapeWhenCastingToString: false
}

When querying the API directly, the data field contains the expected data:

Request:

$ticketid = 72529;
$attachmentid = 296079;

$atClient = new Client([
    'base_uri' => getenv('AT_URL'),
        'headers' => [
            'ApiIntegrationCode' => getenv('AT_INTEGRATIONCODE'),
            'UserName' => getenv('AT_USERNAME'),
            'Secret' => getenv('AT_SECRET'),
            'Content-Type' => 'application/json'
        ]
]);
$result = $atClient->request('GET','v1.0/Tickets/'.$ticketid.'/Attachments/'.$attachmentid);
$responseArray = json_decode($result->getBody(),true);
dump($responseArray);

Response:

 array:2 [
  "items" => array:1 [
    0 => array:19 [
      "id" => 296079
      "attachDate" => "2022-09-16T08:47:45.607"
      "attachedByContactID" => null
      "attachedByResourceID" => 29682955
      "attachmentType" => "FILE_ATTACHMENT"
      "contentType" => "image/png"
      "creatorType" => 1
      "fileSize" => 2359088.0
      "fullPath" => "filetest.png"
      "impersonatorCreatorResourceID" => null
      "opportunityID" => null
      "parentAttachmentID" => null
      "parentID" => 72529
      "publish" => 1
      "ticketID" => 72529
      "ticketNoteID" => null
      "timeEntryID" => null
      "title" => "Test Image"
      "data" => "iVBORw0KGgoAAAANSUhEUgAACpUAAAZFCAYAAADC48neAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAP+lSURBVHhe7P0HgB3Jdd6LFzDAYJAzFgtsxubITQxLLpNEUSIpJksiRcuWbFqWnBT5pOf4+H96z7IsW8GSJcvys2XJSpRoSqJIUWLOy8057wK7CyyARc4zgwH2f74Tqqv79k0zAyyW/H4z3VV16tSpU9V1+/adPtN3zo5de19MhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIeRbmrmeEkIIIYQQQgghhBBCCCGEEEIIIYQQQgghhJBvYRhUSgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIYVEoIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCGFRKCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgQGlRJCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQBpUSQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEAaVEkIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBCBQaWEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhEGlhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYRBpYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCFEYFApIYQQQgghhBB............ blah blah blah
Y8yfXIm36tfWO655bD8Wn8Wz5M2ZnPZsNiN5D9xkhvOSDvexobHt5qKKbI4Y5oY2jNak6lGTFh9rc/vfHjbNTuPnx2WzaKazyopoVNvsgg5cQqHr4DS30bre8D2wybR2Cr14Yjvj3tk+Fsynz9fP3ssLiSlY3ZWYR/lc6vtXArSUtag/G5R2XzaYjwXp2BmbfpMPq1vs5nPU+759zGAnI++9fiZ/DaOZzleAvrsoL8/xebQjuqjzNO6DT4LkMg954kyZw1g2BL8bNtaKZasZyS7hXnQX3t/dvo+C+CWH5yUj9/kj5yJSz6ddidPPbMs+OhydvtrH+8AfT7ccn/U5he1LBqUJ8G0vryM/y2dz8uOiZz/fs/4/u/LD/cSduSNzVhbVU631kmshK1Z21Vet9ZJrIS2xR0pcqZn09nPUSoYOaP1/eAe+ffv/TGMpvMyqxK4AAAAASUVORK5CYII="
    ]
  ]
  "pageDetails" => array:4 [
    "count" => 1
    "requestCount" => 1
    "prevPageUrl" => null
    "nextPageUrl" => null
  ]
]      
aidan-casey commented 1 year ago

@Darrrren - Sorry this has sat so long. 😅 Is this still a problem?

msullivanJIT commented 1 year ago

There's definitely an issue.

Using TicketAttachments()->findById($id)

In TicketAttachmentEntity->fromResponse() the response returned from getBody() includes ["items"] (plural) and the isset() === false is testing against ['item']; throwing the "Missing item key in response" exception.

returning $responseArray["items"][0] of course works, but that wouldn't be the best way to handle an array of items.

TicketAttachmentCollection also has no data for me too as Darrrren pointed out.