Print

Zoho CRM & Zoho Books: Get Books Currency and Tax IDs

What?
A quick note for when I want to quickly generate maps of a currency or a tax from a client's Zoho Books.

Why?
The use-case here is that we are creating a Sales Order in Zoho Books from Zoho CRM and want to map the correct currency and tax by their ID numbers.

How?
Using the REST API and InvokeURL in Zoho Deluge to look at Zoho Books. This uses up an extra 2 calls so you could run them once, store them as a map on your function if you don't want to use up these 2 every time your sales team push a CRM Sales Order to Zoho Books. Or leave as 2 calls at the beginning of your function in case they add a currency or tax rate and want to push a sales order immediately over.

Get Currencies
Remember to replace the v_BooksOrgID with your client's Organization ID for Zoho Books and check the URL for whether it will be https://books.zoho.eu or https://books.zoho.com. You will also need your own CRM to Books connection name (joel_books) with scope to read settings:
copyraw
// our made up books org id but enter your own
v_BooksOrgID=20210924095;
//
// get currencies
m_Currencies = Map();
r_Currencies = invokeurl
[
	url :"https://books.zoho.eu/api/v3/settings/currencies?organization_id=" + v_BooksOrgID
	type :GET
	connection:"joel_books"
];
for each  r_Currency in r_Currencies.get("currencies")
{
	m_Currencies.put(r_Currency.get("currency_code"),r_Currency.get("currency_id"));
}
info m_Currencies;
//
// get Books ID for a currency from an CRM account record
r_AccountDetails = zoho.crm.getRecordByID("Accounts", 9012345678901234567);
v_BooksCurrencyID = m_Currencies.get(ifnull(r_AccountDetails.get("Currency"),"GBP"));
info v_BooksCurrencyID;
  1.  // our made up books org id but enter your own 
  2.  v_BooksOrgID=20210924095
  3.  // 
  4.  // get currencies 
  5.  m_Currencies = Map()
  6.  r_Currencies = invokeUrl 
  7.  [ 
  8.      url :"https://books.zoho.eu/api/v3/settings/currencies?organization_id=" + v_BooksOrgID 
  9.      type :GET 
  10.      connection:"joel_books" 
  11.  ]
  12.  for each  r_Currency in r_Currencies.get("currencies") 
  13.  { 
  14.      m_Currencies.put(r_Currency.get("currency_code"),r_Currency.get("currency_id"))
  15.  } 
  16.  info m_Currencies; 
  17.  // 
  18.  // get Books ID for a currency from an CRM account record 
  19.  r_AccountDetails = zoho.crm.getRecordByID("Accounts", 9012345678901234567)
  20.  v_BooksCurrencyID = m_Currencies.get(ifnull(r_AccountDetails.get("Currency"),"GBP"))
  21.  info v_BooksCurrencyID; 
Yields something like:
copyraw
{
  "EUR": "123456789012345678",
  "GBP": "234567890123456789",
  "USD": "345678901234567890",
}

234567890123456789
  1.  { 
  2.    "EUR": "123456789012345678", 
  3.    "GBP": "234567890123456789", 
  4.    "USD": "345678901234567890", 
  5.  } 
  6.   
  7.  234567890123456789 


Get Taxes
Same as above but to get the tax rates and their IDs:
copyraw
// our made up books org id but enter your own
v_BooksOrgID=20210924095;
//
// get taxes
m_Taxes = Map();
r_Taxes = invokeUrl
[
	url: "https://books.zoho.eu/api/v3/settings/taxes?organization_id="+v_BooksOrgID
	type: GET
	connection: "joel_books"
];
for each r_Tax in r_Taxes.get("taxes")
{
	m_Taxes.put(r_Tax.get("tax_percentage").toString(), r_Tax.get("tax_id"));
}
info m_Taxes;
//
// set Tax ID for a sales order line item
l_LineItems = List();
r_SoDetails = zoho.crm.getRecordById("Sales_Orders",0123456789012345678);
for each  r_LineItem in r_SoDetails.get("Product_Details")
{
	m_LineItem = Map();
	if(r_LineItem.get("Tax") > 0)
	{
		for each r_LineTax in r_LineItem.get("line_tax")
		{
			if(r_LineTax.get("percentage") > 0)
			{
				v_BooksTaxID = ifnull(m_Taxes.get(r_LineTax.get("percentage")),678901234567890123);
				m_LineItem.put("tax_id",v_BooksTaxID);
				m_LineItem.put("tax_percentage",r_LineTax.get("percentage"));
			}
		}
	}
	l_LineItems.add(m_LineItem);
}
info v_BooksTaxID;
  1.  // our made up books org id but enter your own 
  2.  v_BooksOrgID=20210924095
  3.  // 
  4.  // get taxes 
  5.  m_Taxes = Map()
  6.  r_Taxes = invokeUrl 
  7.  [ 
  8.      url: "https://books.zoho.eu/api/v3/settings/taxes?organization_id="+v_BooksOrgID 
  9.      type: GET 
  10.      connection: "joel_books" 
  11.  ]
  12.  for each r_Tax in r_Taxes.get("taxes") 
  13.  { 
  14.      m_Taxes.put(r_Tax.get("tax_percentage").toString(), r_Tax.get("tax_id"))
  15.  } 
  16.  info m_Taxes; 
  17.  // 
  18.  // set Tax ID for a sales order line item 
  19.  l_LineItems = List()
  20.  r_SoDetails = zoho.crm.getRecordById("Sales_Orders",0123456789012345678)
  21.  for each  r_LineItem in r_SoDetails.get("Product_Details") 
  22.  { 
  23.      m_LineItem = Map()
  24.      if(r_LineItem.get("Tax") > 0) 
  25.      { 
  26.          for each r_LineTax in r_LineItem.get("line_tax") 
  27.          { 
  28.              if(r_LineTax.get("percentage") > 0) 
  29.              { 
  30.                  v_BooksTaxID = ifnull(m_Taxes.get(r_LineTax.get("percentage")),678901234567890123)
  31.                  m_LineItem.put("tax_id",v_BooksTaxID)
  32.                  m_LineItem.put("tax_percentage",r_LineTax.get("percentage"))
  33.              } 
  34.          } 
  35.      } 
  36.      l_LineItems.add(m_LineItem)
  37.  } 
  38.  info v_BooksTaxID; 
Yields something like:
copyraw
{
  "0": "456789012345678901",
  "5": "567890123456789012",
  "20": "678901234567890123",
}

678901234567890123
  1.  { 
  2.    "0": "456789012345678901", 
  3.    "5": "567890123456789012", 
  4.    "20": "678901234567890123", 
  5.  } 
  6.   
  7.  678901234567890123 


Category: Zoho :: Article: 773