XeroAPI / xero-php-oauth2

Xero PHP SDK for oAuth 2 generated from Xero API OpenAPI Spec 3.0
MIT License
92 stars 66 forks source link

Credit notes line item array always null #276

Closed upultfs closed 2 years ago

upultfs commented 2 years ago

Hi There,

I try to get Credit notes data using this package but expect line items all other data can receive. could you pls tell me where I'm wrong? i have attached below the Request and Response data .thanks.

Request

$if_modified_since = $_GET["credit_notes_date"]; $statuses = 'Status=="PAID"'; $page = 1; $apiResponse2 = $apiInstance->getCreditNotes($xeroTenantId,$if_modified_since,$statuses,$page); var_dump($apiResponse2->getCreditNotes());

Response

/var/www/xerotfsapi/authorizedResource.php:307: array (size=1) 0 => object(XeroAPI\XeroPHP\Models\Accounting\CreditNote)[22] protected 'container' => array (size=30) 'type' => string 'ACCRECCREDIT' (length=12) 'contact' => object(XeroAPI\XeroPHP\Models\Accounting\Contact)[32] ... 'date' => string '/Date(1650585600000+0000)/' (length=26) 'due_date' => null 'status' => string 'PAID' (length=4) 'line_amount_types' => string 'Exclusive' (length=9) 'line_items' => array (size=0) ... 'sub_total' => float 2697.54 'total_tax' => float 404.63 'total' => float 3102.17 'cis_deduction' => null 'cis_rate' => null 'updated_date_utc' => string '/Date(1652822145173+0000)/' (length=26) 'currency_code' => string 'NZD' (length=3) 'fully_paid_on_date' => string '/Date(1650585600000+0000)/' (length=26) 'credit_note_id' => string 'baaa9b47-7a3f-4646-a7f0-91d54f84c2f1' (length=36) 'credit_note_number' => string 'CN-0007' (length=7) 'reference' => string '87675' (length=5) 'sent_to_contact' => null 'currency_rate' => float 1 'remaining_credit' => float 0 'allocations' => array (size=1) ... 'applied_amount' => null 'payments' => array (size=0) ... 'branding_theme_id' => string 'f8974d1a-6eb8-49d7-973e-f54a30f93bdc' (length=36) 'status_attribute_string' => null 'has_attachments' => boolean false 'has_errors' => boolean false 'validation_errors' => null 'warnings' => null

IanSimpson commented 2 years ago

I'm not sure why someone else hasn't chimed in, but I think this is expected behaviour.

Note on the API docs for Invoices (which is reference from the Credit Note docs) that it says

The line item details will be returned when you retrieve an individual invoice, either by specifying Invoice ID, Invoice Number, querying by Statuses or by using the optional paging parameter (below).

If you need line item detail you will need to pull them one-at-a-time with $apiInstance->getCreditNote($xeroTenantId, $credit_note_id);

RettBehrens commented 2 years ago

@IanSimpson thanks for the assist here.

@upultfs as Ian has pointed out, the response does not include the line items if pagination is not used.

I can see from your example code that you are trying to use the page param but it looks like you aren't using the params in the order the method expects them to be in. The method accepts up to 6 arguments:

getCreditNotes($xero_tenant_id, $if_modified_since = null, $where = null, $order = null, $page = null, $unitdp = null)

$result = $apiInstance->getCreditNotes($xeroTenantId);

NO LINE ITEMS RETURNED

{ "Type": "ACCPAYCREDIT", "Contact": { "ContactID": "4711f569-42bf-416a-9e22-452588101e41", "Name": "PC Complete", "ContactPersons": [], "Addresses": [], "Phones": [], "ContactGroups": [], "HasAttachments": false, "HasValidationErrors": false }, "Date": "\/Date(1649203200000+0000)\/", "Status": "PAID", "LineAmountTypes": "Inclusive", "LineItems": [], "SubTotal": 247.47, "TotalTax": 22.89, "Total": 270.36, "UpdatedDateUTC": "\/Date(1317419602060+0000)\/", "CurrencyCode": "USD", "FullyPaidOnDate": "\/Date(1649203200000+0000)\/", "CreditNoteID": "4f12681f-be5c-4762-a128-2c9bf439dcc6", "CreditNoteNumber": "160-2", "Reference": "", "CurrencyRate": 1, "RemainingCredit": 0, "Allocations": [ { "Invoice": { "LineItems": [], "InvoiceNumber": "160-2", "InvoiceID": "17d2167e-e325-4f71-943b-9da6701e5836", "HasAttachments": false, "IsDiscounted": false, "Payments": [], "Prepayments": [], "Overpayments": [], "CreditNotes": [], "HasErrors": false }, "Amount": 270.36, "Date": "\/Date(1649203200000+0000)\/" } ], "Payments": [], "HasAttachments": false, "HasErrors": false }

$result = $apiInstance->getCreditNotes($xeroTenantId, null, null, null, 1);

LINE ITEMS RETURNED

{ "Type": "ACCPAYCREDIT", "Contact": { "ContactID": "4711f569-42bf-416a-9e22-452588101e41", "Name": "PC Complete", "ContactPersons": [], "Addresses": [], "Phones": [], "ContactGroups": [], "HasAttachments": false, "HasValidationErrors": false }, "Date": "\/Date(1649203200000+0000)\/", "Status": "PAID", "LineAmountTypes": "Inclusive", "LineItems": [ { "Description": "Unable to supply DVD writer for laptop", "Quantity": 1, "UnitAmount": 270.36, "AccountCode": "652", "TaxType": "INPUT", "TaxAmount": 22.89, "LineAmount": 270.36, "Tracking": [] } ], "SubTotal": 247.47, "TotalTax": 22.89, "Total": 270.36, "UpdatedDateUTC": "\/Date(1317419602060+0000)\/", "CurrencyCode": "USD", "FullyPaidOnDate": "\/Date(1649203200000+0000)\/", "CreditNoteID": "4f12681f-be5c-4762-a128-2c9bf439dcc6", "CreditNoteNumber": "160-2", "Reference": "", "CurrencyRate": 1, "RemainingCredit": 0, "Allocations": [ { "Invoice": { "LineItems": [], "InvoiceNumber": "160-2", "InvoiceID": "17d2167e-e325-4f71-943b-9da6701e5836", "HasAttachments": false, "IsDiscounted": false, "Payments": [], "Prepayments": [], "Overpayments": [], "CreditNotes": [], "HasErrors": false }, "Amount": 270.36, "Date": "\/Date(1649203200000+0000)\/" } ], "Payments": [], "HasAttachments": false, "HasErrors": false }

upultfs commented 2 years ago

wonderful thanks @RettBehrens . Got my out put.