5. Items
In items we are handling bidirectional synchronization of items involves comparing any items which have changed since the last successful sync and pushing changes to the older item 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 items in our application and the one in Xero. We are accomplish this by storing the ItemID returned by Xero in our application. Based on the xero ItemID we are maintained synchronization between items in our application and in the xero.
Creation of Items:
To create or modify an Item go to item details layout, fill the details then press the button “Push to xero”.
The following are the minimum required fields to create an Item
- SKU
Script:
In Items we have two different scripts for accessing the information from the xero and sending information to the xero.
- Pull items from xero:
We are using this script to accessing the items 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 items. Then we got a response which consists of all items information from the Xero in a json formate. By using that information we are creating the records in FM.
Example JSON :
“method”: “items”
“Code”: “Merino-2011-LG”,
“Description”: “2011 Merino Sweater – LARGE”,
“UpdatedDateUTC”: “\/Date(1488338552390+0000)\/”,
“PurchaseDetails”: {
“AccountCode”: 300,
“SalesDetails”: {
“AccountCode”: 200,
- Create_items_from_xero:
We are using this script to create or update the records in FileMaker by using Base Elements functions and FileMaker functions.
- items_build_xml:
We are using this script to create an XML file for a particular record.
<Code>FullTracked</Code>
<Description>Sell me</Description>
<PurchaseDescription>Purchase me</PurchaseDescription>
<PurchaseDetails >
<UnitPrice>75.5555</UnitPrice>
<COGSAccountCode>300</COGSAccountCode>
<TaxType>INPUT2</TaxType>
</PurchaseDetails >
<SalesDetails >
<UnitPrice>1020.5565</UnitPrice>
<AccountCode>260</AccountCode>
<TaxType>OUTPUT2</TaxType>
</SalesDetails >
<Name>Full Tracked Item</Name>
<InventoryAssetAccountCode>630</InventoryAssetAccountCode>
<IsSold>true</IsSold>
<IsPurchased>true</IsPurchased>
</Item>
- Push Items to xero:
We are using this script to sending the items information to the xero. We are sending the request API URL using the MBS curl functions with parameters like API key, Method as items and XML of the item. 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”: “items”,
“xml”: <Item>
<Code>FullTracked</Code>
<Description>Sell me</Description>
<PurchaseDescription>Purchase me</PurchaseDescription>
<PurchaseDetails >
<UnitPrice>75.5555</UnitPrice>
<COGSAccountCode>300</COGSAccountCode>
<TaxType>INPUT2</TaxType>
</PurchaseDetails >
<SalesDetails >
<UnitPrice>1020.5565</UnitPrice>
<AccountCode>260</AccountCode>
<TaxType>OUTPUT2</TaxType>
</SalesDetails >
<Name>Full Tracked Item</Name>
<InventoryAssetAccountCode>630</InventoryAssetAccountCode>
<IsSold>true</IsSold>
<IsPurchased>true</IsPurchased>
</Item>