calcinai / xero-php

A php library for the Xero API, with a cleaner OAuth interface and ORM-like abstraction.
MIT License
359 stars 261 forks source link

Set default tracking category and branding theme on contact - validation error #383

Open latheesan-k opened 6 years ago

latheesan-k commented 6 years ago

I am trying to load a contact and update it with the default Sales Tracking Category and Branding Theme.

This is what I have tried:

// Load contacts matching account number
$contact = null;
$contacts = $xero->load('Accounting\\Contact')
    ->where('AccountNumber', (string) $recordId)
    ->execute();
foreach ($contacts as $contactItem) {
    $contact = $contactItem;
}

$brandingTheme = null;
$brandingThemes = $xero->load('Accounting\\BrandingTheme')
    ->where('Name', $updateData['branding_theme'])
    ->execute();
foreach ($brandingThemes as $brandingThemeItem) {
    $brandingTheme = $brandingThemeItem;
}

// Set default branding theme
$contact->setBrandingTheme($brandingTheme);

// Set default partner
$trackingCategoryItem = new \XeroPHP\Models\Accounting\TrackingCategory($xero);
$trackingCategoryItem
    ->setName('Partner')
    ->setOption($updateData['invoice_partner']);
$contact->addSalesTrackingCategory($trackingCategoryItem);

// Save
$contact->save();

The save above is causing this validation error:

SalesCategory is missing a TrackingCategoryName on file C:\xampp\htdocs\xero-updater\vendor\calcinai\xero-php\src\XeroPHP\Remote\Response.php at line 76

This library is more confusing than the api documentation. How is this supposed to be achieved?

LABCAT commented 6 years ago

You are using the setName function but what you actually need is a setTrackingCategoryName function.

However this function doesn't currently exist. I have created a pull request to add the required functions: https://github.com/calcinai/xero-php/pull/386

Also there is no setOption function, the one you are looking for is addOption.