Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding TrackingOption to TrackingCategory issue #256

Closed
gitstashgithub opened this issue May 9, 2017 · 4 comments · Fixed by #640
Closed

Adding TrackingOption to TrackingCategory issue #256

gitstashgithub opened this issue May 9, 2017 · 4 comments · Fixed by #640

Comments

@gitstashgithub
Copy link

Hi,
I have issue to add TrackingOption to TrackingCategory by using TrackingCategory::addOption() function.
After I spent some time on it I found in the XeroPHP\Models\Accounting\TrackingCategory\TrackingOption file, the values getResourceURI() and getRootNodeName() return don't match the Xero API request url and body:
PUT https://api.xero.com/api.xro/2.0/TrackingCategories/{TrackingCategoryID}/Options

<Options>
  <Option>
    <Name>New Option</Name>
  </Option>
  <Option>
    <Name>Another New Option</Name>
  </Option>
</Options>
/**
     * Get the resource uri of the class (Contacts) etc
     *
     * @return string
     */
    public static function getResourceURI()
    {
        return 'TrackingOptions';
    }


    /**
     * Get the root node name.  Just the unqualified classname
     *
     * @return string
     */
    public static function getRootNodeName()
    {
        return 'TrackingOption';
    }

I changed them to

/**
     * Get the resource uri of the class (Contacts) etc
     *
     * @return string
     */
    public static function getResourceURI()
    {
        return 'Options';
    }


    /**
     * Get the root node name.  Just the unqualified classname
     *
     * @return string
     */
    public static function getRootNodeName()
    {
        return 'Option';
    }

, and now it works. Not sure it may cause some other issues or not, but it temporarily fixes the issue.

@zoborg
Copy link

zoborg commented Sep 25, 2018

This issue still persists!

@paul-ang
Copy link

paul-ang commented Mar 7, 2019

I am having the same issue.

@kgdiem
Copy link
Contributor

kgdiem commented Sep 25, 2019

bump, still an issue

kgdiem added a commit to kgdiem/xero-php that referenced this issue Sep 25, 2019
@aftersow
Copy link

Changing TrackingOptions to Options in XeroPHP worked soughta... but I was still getting a different error. I added a work around by making the option manually

Note: $this->_xero_oauth_object is my \XeroPHP\Application\PublicApplication from authentication

// 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));        
}

If anyone is interested, the rest of my code shows how to add it to the trackingCategory

// 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');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants