我似乎无法创建跟踪选项,类别本身也很好。
但是首先-我应该指出,我相信Xero-API for PHP中存在错误,当根据文档here调试添加选项时,PUT应该是
https://api.xero.com/api.xro/2.0/TrackingCategories/ {TrackingCategoryID} /选项
但是在php lib中是
https://api.xero.com/api.xro/2.0/TrackingCategories/ {TrackingCategoryID} / TrackingOptions
即使解决该问题,我也不会出错,但是未创建跟踪选项,有什么想法吗?
$options = ['US', 'UK'];
$title = 'Region';
$trackingCategory = null;
if(!$trackingCategory) {
$trackingCategory = new \XeroPHP\Models\Accounting\TrackingCategory($xero);
$trackingCategory->setName($title);
$trackingCategory->save();
}
try {
foreach($options as $option) {
$to = new \XeroPHP\Models\Accounting\TrackingCategory\TrackingOption($xero);
$to->setName($option);
$trackingCategory->setOption($option);
$trackingCategory->save();
}
} catch(\Exception $e) {
$this->logger()->info($e->getTraceAsString());
$this->logger()->info("TRACKING: ". $e->getMessage());
return false;
}
答案 0 :(得分:0)
所以看来这是报告here的错误
来源尚未修复,但是上面的链接为其他任何搜索的人都解决了该问题。
答案 1 :(得分:0)
在XeroPHP中将TrackingOptions更改为Options确实可行……但是我仍然遇到另一个错误。最终手动创建了选项
注意:$ this-> _ xero_oauth_object是我来自身份验证的\ XeroPHP \ Application \ PublicApplication
// Create the URL object based on an absolute URL
$url = new \XeroPHP\Remote\URL($this->_xero_oauth_object, "https://api.xero.com/api.xro/2.0/TrackingCategories/{TrackCategoryGuid}/Options");
// Pass this to the request as a PUT request
$request = new \XeroPHP\Remote\Request($this->_xero_oauth_object, $url, \XeroPHP\Remote\Request::METHOD_PUT);
// Probably a better way but I just copied and paste the XML from the Xero API docs.
$request->setBody("<Options><Option><Name>My New Option Name</Name></Option></Options>");
// I wrapped this in a try - if it exists, there will be an error as you cant have duplicates.
try {
$request->send();
} catch (Exception $e) {
\Log::warn("Xero error: " . print_r($request->getResponse(), true));
}
// now option is created, new add the option to the tracking category
$tracking = new \XeroPHP\Models\Accounting\TrackingCategory($this->_xero_oauth_object);
$tracking->setTrackingCategoryID('3fceedc7-764e-490a-ac27-25684473af78');
// tracking category name - not sure if I need this
$tracking->setName('Contractor');
// match the option name above
$tracking->setOption('My New Option Name');