I'm trying to achieve this with xero api and xero-node:
- Make an API call using Xero API and fetch all the contacts.
- Perform a check for new Contacts with a null value in Account Number in Contacts.
- Create unique CRN(customer reference number) and perform a check that this unique number has not been used previously.
- Update this unique CRN to Contact [ Account Number ].
What I've been able to achieve for now:
- All available contacts fetched using xero-node "get" method
- Check applied to the contacts to find those with no account number and stored them in an array
- Update action done on all the contacts stored in array but that is only updating the last contact for now.
This is the code for update method
noAccountNumContacts is the array of the IDs of those contact which has no account number
let xero = new XeroClient(config);
let noAccountNumContacts = [];
const result = await xero.contacts.get();
const contacts = result.Contacts;
contacts.map(contact => {
const { ContactID, Name, AccountNumber } = contact;
if (AccountNumber === undefined) {
noAccountNumContacts.push(ContactID);
}
});
noAccountNumContacts.map(contact => {
xero.contacts.update({
ContactID: contact,
AccountNumber: 123456
});
});
I expect this code to update the account number of the IDs stored in array(noAccountNumContacts). But what I'm getting for now is that the update call only updates a single contact rather than updating all the contacts.
After trying a lot I was unable to find the solution. Can you please help me understand what I'm doing wrong? Also, how can I generate a unique CRN which can be used as Account Number for Contact?