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

Creating a new TrackingOption on an existing TrackingCategory #920

Open
rushork opened this issue Jul 2, 2024 · 2 comments
Open

Creating a new TrackingOption on an existing TrackingCategory #920

rushork opened this issue Jul 2, 2024 · 2 comments

Comments

@rushork
Copy link
Contributor

rushork commented Jul 2, 2024

Hi,

I'm trying to create tracking options and add them to an existing tracking category (that has tracking options) like this:

     $option = new TrackingCategory\TrackingOption();
     $option->setName($name);
     $tracking->addOption($option);
     $tracking->save();

Each time I do so, apart from adding the FIRST tracking option to a tracking category, I get the following exception:

A validation exception occurred (For each specified tracking option the name must be unique)
Validation errors:
For each specified tracking option the name must be unique.

The value of $name does not exist in the tracking category before this, but it still says it must be unique?

It only happens when I try to add a new one. I also notice that it does actually create the tracking option, but the error means that when I try adding the tracking variable to a line item and save it for an invoice - it does not save the line item as there has been an error.

Thanks

@rushork
Copy link
Contributor Author

rushork commented Jul 3, 2024

To further prove there is an issue, I instead made the requests through the XeroPHP\Remote\Request class and manually chose the endpoints I wanted.

I managed to get it to work using this method instead.

@bretto36
Copy link
Contributor

Hey, so judging by the xero docs - https://developer.xero.com/documentation/api/accounting/trackingcategories/#put-trackingcategories

If you have an existing tracking category, you supposed to use the option endpoint to create them

PUT https://api.xero.com/api.xro/2.0/TrackingCategories/{TrackingCategoryID}/Options
{
"Name": "New Option"
}

The docs are awful for this area. It doesn't list whether creating a new TrackingCategory allows Options to be added at the same time

To update one option's name
POST https://api.xero.com/api.xro/2.0/TrackingCategories/{TrackingCategoryID}/Options/{TrackingOptionID}
{
"Name": "New 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
Development

No branches or pull requests

2 participants