首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xero创建新的追踪选项

Xero创建新的追踪选项
EN

Stack Overflow用户
提问于 2018-09-25 08:59:38
回答 2查看 118关注 0票数 0

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

然而,首先-我应该指出,我认为在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选项,我也没有得到任何错误,有什么想法吗?

代码语言:javascript
复制
    $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;
    }
EN

回答 2

Stack Overflow用户

发布于 2018-09-25 09:07:38

所以这看起来像是一个here报告的错误

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

票数 0
EN

Stack Overflow用户

发布于 2019-11-20 14:08:35

在XeroPHP中将TrackingOptions更改为Options已生效...但是我仍然得到了一个不同的错误。最终手动创建了该选项

注意:$this->_xero_oauth_object是来自身份验证的my \XeroPHP\Application\PublicApplication

代码语言:javascript
复制
// 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');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52489189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档