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
Yields something like:
// 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;
- // 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;
copyraw
{ "EUR": "123456789012345678", "GBP": "234567890123456789", "USD": "345678901234567890", } 234567890123456789
- {
- "EUR": "123456789012345678",
- "GBP": "234567890123456789",
- "USD": "345678901234567890",
- }
- 234567890123456789
Get Taxes
Same as above but to get the tax rates and their IDs:
copyraw
Yields something like:
// 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;
- // 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;
copyraw
{ "0": "456789012345678901", "5": "567890123456789012", "20": "678901234567890123", } 678901234567890123
- {
- "0": "456789012345678901",
- "5": "567890123456789012",
- "20": "678901234567890123",
- }
- 678901234567890123
Category: Zoho :: Article: 773