Download Statement from Zoho Books and upload to Zoho CRM

Download Statement from Zoho Books and upload to Zoho CRM

Hi everybody! I don't know who needs to know this, but if you do, then here it is. 

This code:
  1. Searches for Contact in Books based on the Account ID in CRM
  2. Download the statement of account of the Contact in Books
  3. Upload as an attachment in Account record in CRM
By default, if you do not specify "start_date" and "end_date", it will download the current year's statement. Also, "accId" is mapped to "Account ID" in Zoho CRM. This function is for the Accounts module in CRM.
  1. //search for account in books
  2. orgId = {enter your Zoho Books Organization ID here as a string. e.g: "78634343"};
  3. booksCust = invokeurl
  4. [
  5. url :"https://www.zohoapis.com/books/v3/contacts?organization_id=" + orgId + "&zcrm_account_id=" + accId.toString()
  6. type :GET
  7. connection:"{your zoho books connection name, I'd choose full scope}"
  8. ];
  9. // check if there's a contact in Zoho Books with the Zoho CRM account ID
  10. if ( booksCust.get("code") == 0 && booksCust.get("contacts").size() > 0 ) 
  11. {
  12. contactId = booksCust.get("contacts").get(0).get("contact_id");
  13. //get statement
  14. getStatement = invokeurl
  15. [
  16. url:"https://www.zohoapis.com/books/v3/contacts/" + contactId + "/statements?organization_id=" + orgId
  17. type: GET
  18. connection: {your zoho books connection name, I'd choose full scope}"
  19. ];
  20. info getStatement;
  21. if ( getStatement != null ) 
  22.     {
  23. getStatement.setParamName("file");
  24. //upload to crm
  25. uploadStatement = invokeurl
  26. [
  27. url: "https://www.zohoapis.com/crm/v6/Accounts/" + accId.toString() + "/Attachments"
  28. type: POST
  29. files: getStatement
  30. connection: "{your zoho crm connection name}"
  31. ];
  32. info uploadStatement;
  33.     }
  34. }
Good luck!

Nik, aplikasi.us
Zoho Premium Partner