Search code examples
c#.netoauth-2.0xero-api

Get Contact Details based on Contact Name from Xero API using Oauth2


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


Solution

  • 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