intuit / QuickBooks-V3-PHP-SDK

Official PHP SDK for QuickBooks REST API v3.0: https://developer.intuit.com/
Apache License 2.0
241 stars 240 forks source link

IPPAttachable.AttachableRef.EntityRef.type is stripped out by DataService in query response #477

Open simplimation opened 1 year ago

simplimation commented 1 year ago

When querying Attachable objects, in the response the XML "type" attribute of EntityRef is not parse by DataService.php:1027 and so the IPPAttachable.AttachableRef.EntityRef.type is not defined. There is no way to see from the query results what type of object the EntityRef ID refers to. It parses the entity's ID but not the type.

Raw XML response ($responseBody at DataService:1019)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2023-03-07T09:35:47.705-08:00">
    <QueryResponse startPosition="1" maxResults="10">
        <Attachable domain="QBO" sparse="false">
            <Id>5000000000001184365</Id>
            <SyncToken>0</SyncToken>
            <MetaData>
                <CreateTime>2023-02-28T14:23:35-08:00</CreateTime>
                <LastUpdatedTime>2023-02-28T14:23:35-08:00</LastUpdatedTime>
            </MetaData>
            <AttachableRef>
                <EntityRef type="Customer">1</EntityRef>
                <IncludeOnSend>false</IncludeOnSend>
            </AttachableRef>
            <FileName>Sample-1677623013.pdf</FileName>
            <FileAccessUri>/v3/company/4620816365162761880/download/5000000000001184365
            </FileAccessUri>
            <TempDownloadUri>
                https://intuit-qbo-prod-19.s3.amazonaws.com/4620816365162761880/attachments/46b44f48-df7a-45cb-8222-67b959b8cadcSample-1677623013.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Date=20230307T173547Z&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Expires=900&amp;X-Amz-Credential=AKIA3V3MBG4KEF3MXKGR%2F20230307%2Fus-east-1%2Fs3%2Faws4_request&amp;X-Amz-Signature=85be92b2b49e2244c399b57550b7c590b96c1230ce8e29014b26a790418c6085
            </TempDownloadUri>
            <Size>2729</Size>
            <ContentType>application/pdf</ContentType>
        </Attachable>
        ...

Parsed XML object ($responseXmlObj DataService: 1028)

SimpleXMLElement::__set_state(array(
   '@attributes' => 
  array (
    'time' => '2023-03-07T09:41:54.383-08:00',
  ),
   'QueryResponse' => 
  SimpleXMLElement::__set_state(array(
     '@attributes' => 
    array (
      'startPosition' => '1',
      'maxResults' => '10',
    ),
     'Attachable' => 
    array (
      0 => 
      SimpleXMLElement::__set_state(array(
         '@attributes' => 
        array (
          'domain' => 'QBO',
          'sparse' => 'false',
        ),
         'Id' => '5000000000001184365',
         'SyncToken' => '0',
         'MetaData' => 
        SimpleXMLElement::__set_state(array(
           'CreateTime' => '2023-02-28T14:23:35-08:00',
           'LastUpdatedTime' => '2023-02-28T14:23:35-08:00',
        )),
         'AttachableRef' => 
        SimpleXMLElement::__set_state(array(
           'EntityRef' => '1',
           'IncludeOnSend' => 'false',
        )),
         'FileName' => 'Sample-1677623013.pdf',
         'FileAccessUri' => '/v3/company/4620816365162761880/download/5000000000001184365',
         'TempDownloadUri' => 'https://intuit-qbo-prod-19.s3.amazonaws.com/4620816365162761880/attachments/46b44f48-df7a-45cb-8222-67b959b8cadcSample-1677623013.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230307T174154Z&X-Amz-SignedHeaders=host&X-Amz-Expires=900&X-Amz-Credential=AKIA3V3MBG4KEF3MXKGR%2F20230307%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=6bb60622c95d73b80649709e4e59ffbd91567a1935a2101ef2fbc90150ff1ba7',
         'Size' => '2729',
         'ContentType' => 'application/pdf',
      )),
      ...

IPPAttachable object ($parsedResponseBody DataService:1031)

array (
  0 => 
  QuickBooksOnline\API\Data\IPPAttachable::__set_state(array(
     'FileName' => 'Sample-1677623013.pdf',
     'FileAccessUri' => '/v3/company/4620816365162761880/download/5000000000001184365',
     'TempDownloadUri' => 'https://intuit-qbo-prod-19.s3.amazonaws.com/4620816365162761880/attachments/46b44f48-df7a-45cb-8222-67b959b8cadcSample-1677623013.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230307T173547Z&X-Amz-SignedHeaders=host&X-Amz-Expires=900&X-Amz-Credential=AKIA3V3MBG4KEF3MXKGR%2F20230307%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=85be92b2b49e2244c399b57550b7c590b96c1230ce8e29014b26a790418c6085',
     'Size' => '2729',
     'ContentType' => 'application/pdf',
     'Category' => NULL,
     'Lat' => NULL,
     'Long' => NULL,
     'PlaceName' => NULL,
     'Note' => NULL,
     'Tag' => NULL,
     'ThumbnailFileAccessUri' => NULL,
     'ThumbnailTempDownloadUri' => NULL,
     'AttachableEx' => NULL,
     'Id' => '5000000000001184365',
     'SyncToken' => '0',
     'MetaData' => 
    QuickBooksOnline\API\Data\IPPModificationMetaData::__set_state(array(
       'CreatedByRef' => NULL,
       'CreateTime' => '2023-02-28T14:23:35-08:00',
       'LastModifiedByRef' => NULL,
       'LastUpdatedTime' => '2023-02-28T14:23:35-08:00',
       'LastChangedInQB' => NULL,
       'Synchronized' => NULL,
    )),
     'CustomField' => NULL,
     'AttachableRef' => 
    QuickBooksOnline\API\Data\IPPAttachableRef::__set_state(array(
       'EntityRef' => '1',
       'LineInfo' => NULL,
       'IncludeOnSend' => 'false',
       'CustomField' => NULL,
       'AttachableRefEx' => NULL,
    )),
     'domain' => NULL,
     'status' => NULL,
     'sparse' => NULL,
  )),
 ...
simplimation commented 1 year ago

Here is the raw result of a query using the API Explorer that shows the EntityRef value and type:

select * from attachable where AttachableRef.EntityRef.Type = 'customer' and AttachableRef.EntityRef.value = '1'


 "QueryResponse": {
  "Attachable": [
   {
    "FileName": "Sample-1677623013.pdf",
    "FileAccessUri": "/v3/company/4620816365162761880/download/5000000000001184365",
    "TempDownloadUri": "https://intuit-qbo-prod-19.s3.amazonaws.com/4620816365162761880/attachments/46b44f48-df7a-45cb-8222-67b959b8cadcSample-1677623013.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230307T181435Z&X-Amz-SignedHeaders=host&X-Amz-Expires=900&X-Amz-Credential=AKIA3V3MBG4KEF3MXKGR%2F20230307%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=882f0c09cdba8cdd0e0a5ece7f63f59b29d69a02a1031e17804e30a5a7f2b1c1",
    "Size": 2729,
    "ContentType": "application/pdf",
    "domain": "QBO",
    "sparse": false,
    "Id": "5000000000001184365",
    "SyncToken": "0",
    "MetaData": {
     "CreateTime": "2023-02-28T14:23:35-08:00",
     "LastUpdatedTime": "2023-02-28T14:23:35-08:00"
    },
    "AttachableRef": [
     {
      "EntityRef": {
       "value": "1",
       "type": "Customer"
      },
      "IncludeOnSend": false
     }
    ]
   },
  ...
simplimation commented 1 year ago

This also causes requests updating Attachable objects to throw a business validation error "The entity does not currently support Attachable". This is because FindById() doesn't return AttachableRef.EntityRef.type which is needed when updating the object.

exintrovert commented 9 months ago

The XSD seems to have "Type" listed as an element, but it is being received as an attribute in the received XML