When I add tracking to invoices or credit notes via the api it works fine. but when i try to add it on purchase order it fails and I cannot seem to get a clear error message out of it.
I am using accounting api https://xeroapi.github.io/xero-php-oauth2/docs/v2/accounting/index.html#api-Accounting-updatePurchaseOrder
Error I get is message: "[400] Client error:
POST https://api.xero.com/api.xro/2.0/PurchaseOrders/42797164-58c9-483c-9af8-96165c31a26f` resulted in a 400 Bad Request
response:\n{\r\n "ErrorNumber": 10,\r\n "Type": "ValidationException",\r\n "Message": "A validation exception occurred",\r\n "Elements" (truncated...)\n"
`
Code I am using to try set it after I have created the purchase order.
[$trackingCategoryId, $trackingOptionId] = $this->getTrackingCategoryByNameFromXero($projectName, 'Project');
$purchaseOrder = null;
$xeroTenantId = $this->xero_account->tenantId;
try {
$purchaseOrders = $this->accountingApi->getPurchaseOrder($xeroTenantId, $purchaseOrderId);
foreach ($purchaseOrders as $model) {
if ($model->getPurchaseOrderId() == $purchaseOrderId) {
$purchaseOrder = $model;
break;
}
}
} catch (Exception $e) {
echo 'Exception when calling AccountingApi->getPurchaseOrder: ', $e->getMessage(), PHP_EOL;
}
if ($purchaseOrder instanceof PurchaseOrder) {
$lineItems = $purchaseOrder->getLineItems();
foreach ($lineItems as $lineItem) {
$tc = new LineItemTracking();
$tc->setTrackingCategoryId($trackingCategoryId);
$tc->setTrackingOptionId($trackingOptionId);
$lineItem->setTracking([$tc]);
$lineItems[] = $lineItem;
}
$purchaseOrder->setLineItems($lineItems);
$purchaseOrders = new PurchaseOrders();
$arr_purchase_orders[] = $purchaseOrder;
$purchaseOrders->setPurchaseOrders($arr_purchase_orders);
$summarizeErrors = true;
try {
$x = $this->accountingApi->updatePurchaseOrder(
$this->xero_account->tenantId,
$purchaseOrderId,
$purchaseOrders
);
} catch (\ApiException $e) {
print_r($e->getMessage());die;
}
}