0

I am fetching contact's details from Xero based on name via Xero API ( using OAuth2). Now the problem is,I can get contact's details but some details are always null e.g Tracking Categories.

I contacted Xero support for this. they suggested to fetch contact by GUID. But the thing is i need to fetch by name as i am searching for contacts who share same name in Xero. so there could be multiple contacts and if i fetch by name it doesn't give me tracking category details.

Here's how i am fetching contacts.

List<Contact> contactList = new List<Contact>();
                
var AccountingApi = new AccountingApi();
var response = await AccountingApi.GetContactsAsync(accessToken, xeroTenantId, null,
                                string.Format("FirstName != Null && FirstName.ToLower().Contains(\"{0}\")", "aaron"));

contactList = response._Contacts.ToList();

Note: Contact refers to Xero.NetStandard.OAuth2.Model.Accounting
AccountingApi refers to Xero.NetStandard.OAuth2.Api

By this code i can get contacts but tracking categories are always null. How can i get all the details of contacts without searching by GUID.

Can anybody help me here ?

Xero Contact : https://developer.xero.com/documentation/api/contacts
Tracking Categories : https://developer.xero.com/documentation/api/tracking-categories

Jolly
  • 314
  • 3
  • 15

2 Answers2

0

I see in the docs and the API spec that contacts have SalesTrackingCategories and PurchasesTrackingCategories but I'm having trouble actually setting that via the UI or the API.

Can you screenshot on your Xero UI where that user's tracking category is set, and some other data about what is coming back from UI?

Hey - got them set in the UI.. I only had tracking setup for invoice not contacts. Thanks.

So have you clicked through that key to the nested array?

SalesTrackingCategories might have a nested SalesTrackingCategory array that contains the values?

I double checked in another SDK and it serialized that data correct so my hunch is this is likely an issue with the SDK having logic problems in parsing that out as an array..

success-serialization-contacts-tracking

Best to create an issue directly in the repo with a link to this question - https://github.com/XeroAPI/Xero-NetStandard/issues and I will tag my colleague who manages that.

For reference - the endpoint call JSON needs to be structured like this to succeed in updating those.

// POST https://api.xero.com/api.xro/2.0/Contacts/<contact-uuid>
{
  "SalesTrackingCategories": [{
    "TrackingCategoryName": "Contact Tracking",
    "TrackingOptionName": "Cool customer"
  }]
}
SerKnight
  • 2,502
  • 1
  • 16
  • 18
  • For my organization i have set one tracking category named 'Jobs' . So in UI it will come as a drop down in sales settings and purchase settings. For your image it will come under the Default account. there will be one more drop down named default Jobs.( https://central.xero.com/s/article/Set-up-tracking-categories-GL ). I have asked this to Xero Support here's the case : https://central.xero.com/s/case?caseId=5003m0000174dtJAAQ. But they are suggesting to use ContactId or paging in where clause. which i can't use. – Jolly Feb 08 '21 at 06:25
  • [1]: https://i.stack.imgur.com/Hc2kk.png [2]: https://i.stack.imgur.com/gCjFj.png – Jolly Feb 08 '21 at 06:45
  • @Jolly - updated my answer. I think we need to open an issue in SDK as I've got it tested and ensured API is returning data in another sdk. – SerKnight Feb 08 '21 at 20:28
  • Raised an issue in GitHub. Is there any other SDK available for .Net ? last year when i developed my requirement using oauth1 then also this was the problem but that time i could find Xero Core API which would give me everything exactly i need. – Jolly Feb 09 '21 at 04:59
0

after discussing with Xero support team i found out that they intentionally wrap the data when you search like this, so if i want to fetch all the details of contact based on common name or like that i will have to pass page number. in my case page=1. (supposing that there won't be more than hundred records sharing same name in one page as it checks for top 100 records which matches the where condition). If you have more than 100 contacts named like what you passed, then page=2 will return the second set of 100 contacts.

Reference : https://central.xero.com/s/case?caseId=5003m0000174dtJAAQ

Jolly
  • 314
  • 3
  • 15