施乐 创建新的跟踪选项



我似乎无法创建跟踪选项,类别本身创建得很好。

然而,首先 - 我应该指出我相信 PHP 的 Xero-API 中存在一个错误,在调试时根据此处的文档添加一个选项,PUT 应该是

https://api.xero.com/api.xro/2.0/TrackingCategories/{跟踪类别ID}/选项

然而,在 php 库中它是

https://api.xero.com/api.xro/2.0/TrackingCategories/{跟踪类别 ID}/跟踪选项

即使解决了这个问题,我也没有收到任何错误,但是没有创建跟踪选项,有什么想法吗?

$options = ['US', 'UK'];
$title = 'Region';
$trackingCategory = null;
if(!$trackingCategory) {
$trackingCategory = new XeroPHPModelsAccountingTrackingCategory($xero);
$trackingCategory->setName($title);
$trackingCategory->save();
}
try {
foreach($options as $option) {
$to = new XeroPHPModelsAccountingTrackingCategoryTrackingOption($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;
}

所以这似乎是一个错误,如此处报告。

源尚未修复,但是上面的链接解决了其他搜索者的问题。

在 XeroPHP 中将跟踪选项更改为选项工作寻求...但我仍然收到不同的错误。最终手动创建选项

注意:$this->_xero_oauth_object是我的\XeroPHP\应用程序\公共应用程序从身份验证

// Create the URL object based on an absolute URL
$url = new XeroPHPRemoteURL($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 XeroPHPRemoteRequest($this->_xero_oauth_object, $url, XeroPHPRemoteRequest::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 XeroPHPModelsAccountingTrackingCategory($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');

最新更新