4. Contacts
Introduction:
In contacts we are handling bidirectional synchronization of contacts involves comparing any contacts which have changed since the last successful sync and pushing changes to the older contact record. Xero API supports the “If-modified-since” header parameter, which allows you to pull back only the records which are changed since the last successful sync.
We establish a foreign key relationship between the contact in our application and the one in Xero. We are accomplish this by storing the ContactID returned by Xero in our application. Based on the xero ContactID we are maintained synchronization between contacts in our application and in the Xero.
Creation of Contacts:
To create or modify an contact go to contact details layout, fill the details then press the button “Push to Xero”.
The following are the minimum required fields to create an contacts
- Company name.
Note:
The business rules around contacts in Xero may be changing in the future and ‘Contact Name’ may no longer be a unique field.
Script:
In contacts we have two different scripts for accessing the information from the Xero and sending information to the Xero.
- Pull contacts from xero:
We are using this script to accessing the contacts information from the xero. We are sending the request API URL based on the filemaker version using Base Elements plugin functions or FileMaker functions with parameters like API key, Method as contacts. Then we got a response which consists of all contact information from the Xero in a json formate. By using that information we are creating the records in FM.
Example JSON :
“method”: “contacts”
“ContactNumber”: “ID001”,
“Name”: “ABC Limited”,
“FirstName”: “John”,
“LastName”: “Smith”,
“EmailAddress”: “john.smith@gmail.com”,
“Addresses”: [
“AddressLine1”: “P O Box 123”,
“City”: “Wellington”,
“PostalCode”: “6011”
“TaxNumber”: “12-345-678”,
“AccountsReceivableTaxType”: “OUTPUT”,
“AccountsPayableTaxType”: “INPUT”,
“DefaultCurrency”: “NZD”
- Create_contacts_from_xero:
We are using this script to create or update the records in FileMaker by using Base Elements plugin functions and FileMaker functions.
- Contact_get_call_with_xero_id:
We are using this script to accessing the particular contact information from the xero. We are sending the request API URL based on the FileMaker version using Base Elements plugin functions or FileMaker functions with parameters like API key, Method as contacts and Xero contact id. Then we got a response which consists of that contact information from the Xero in json formate. By using that information we are updating the records in FM.
- Contact_build_xml:
We are using this script to create an XML file for a particular record.
Example XML :
<ContactID>eaa28f49-6028-4b6e-bb12-d8f6278073fc</ContactID>
<ContactNumber>ID001</ContactNumber>
<Name>ABC Limited</Name>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
<EmailAddress>john.smith@gmail.com</EmailAddress>
<Addresses >
<Address >
<AddressType>POBOX</AddressType>
<AddressLine1>P O Box 123</AddressLine1>
<City>Wellington</City>
<PostalCode>6011</PostalCode>
</Address >
</Addresses >
<BankAccountDetails>01-0123-0123456-00</BankAccountDetails>
<TaxNumber>12-345-678</TaxNumber>
<AccountsReceivableTaxType>OUTPUT</AccountsReceivableTaxType>
<AccountsPayableTaxType>INPUT</AccountsPayableTaxType>
<DefaultCurrency>NZD</DefaultCurrency>
</Contact>
- Push contacts to xero:
We are using this script to sending the contacts information to the xero. We are sending the request API URL based on the filemaker version using Base Elements plugin functions or FileMaker functions with parameters like API key, Method as contacts and XML of the contact. Here we are creating the XML for every record and sending to the xero then we got a response like success or error . We are displaying the response in the contacts layout to know the status to the user
“method”: “contacts”,
“xml”:<Contact>
<ContactID>eaa28f49-6028-4b6e-bb12-d8f6278073fc</ContactID>
<ContactNumber>ID001</ContactNumber>
<Name>ABC Limited</Name>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
<EmailAddress>john.smith@gmail.com</EmailAddress>
<Addresses >
<Address >
<AddressType>POBOX</AddressType>
<AddressLine1>P O Box 123</AddressLine1>
<City>Wellington</City>
<PostalCode>6011</PostalCode>
</Address >
</Addresses >
<BankAccountDetails>01-0123-0123456-00</BankAccountDetails>
<TaxNumber>12-345-678</TaxNumber>
<AccountsReceivableTaxType>OUTPUT</AccountsReceivableTaxType>
<AccountsPayableTaxType>INPUT</AccountsPayableTaxType>
<DefaultCurrency>NZD</DefaultCurrency>
</Contact>