我似乎不能创建跟踪选项,类别本身创建得很好。
然而,首先-我应该指出,我认为在Xero-API for PHP中有一个bug,在调试时根据文档here添加一个选项PUT应该是
https://api.xero.com/api.xro/2.0/TrackingCategories/{TrackingCategoryID}/Options
然而,在php lib中,它是
https://api.xero.com/api.xro/2.0/TrackingCategories/{TrackingCategoryID}/TrackingOptions
即使解决了这个问题,创建了not tracking选项,我也没有得到任何错误,有什么想法吗?
$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;
}发布于 2018-09-25 09:07:38
所以这看起来像是一个here报告的错误
来源尚未修复,但上面的链接解决了任何其他搜索的问题。
发布于 2019-11-20 14:08:35
在XeroPHP中将TrackingOptions更改为Options已生效...但是我仍然得到了一个不同的错误。最终手动创建了该选项
注意:$this->_xero_oauth_object是来自身份验证的my \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');https://stackoverflow.com/questions/52489189
复制相似问题