For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at https://ascentbusiness.co.uk/zoho-services/uk-zoho-support.  For larger projects, talk to our experts and receive dedicated support from our hands-on project consultants at https://ascentbusiness.co.uk/zoho-services/zoho-crm-implementation.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at https://ascentbusiness.co.uk.

Zoho Books: Error 7008: There are no contact persons associated with this Invoice

What?
A quick article on how to get around this error.

Why?
The use-case here is that I am using the send invoice API and I kept getting this error despite including the customer_id and there was a primary contact on the customer record.
This is from within ZohoCreator, requesting for an invoice in ZohoBooks to be sent.

How?
So the key here is that there were no contact persons on the customer record. Instead, when building the invoice, this had to be added (don't ever remember having to do this) as contact_ids (array/list). Instead the below script will show you how to use this API having a few email addresses as the recipients:

A sample code snippet:
For the below, I have a connection to ZohoBooks from ZohoCreator called "zbooks". It has fullaccess as a scope but I'm sure you can lock it down to just the scopes you need.
copyraw
void ZohoBooks.fn_SendZohoBooksInvoice(int p_OrderID)
{
	v_OrderID = ifnull(input.p_OrderID,0).toLong();
	/* *******************************************************************************
	Function:       void ZohoBooks.fn_SendZohoBooksInvoice(int p_OrderID)
	Trigger:        On Demand when button in report is clicked
	Purpose:		This will send a ZohoBooks invoice directly to its recipient
	Inputs:         Zoho Creator record ID of the order
	Outputs:        -

	Date Created:   2023-03-06 (Joel Lipman)
					- Initial release
	Date Modified:  ???
					- ???
					
	More Info:  	Error 7008: There are no contact persons associated with this Invoice.
					- Encountered when trying to use the send an invoice API
					- Need the generated invoice to pre-select a contact person to email
					- Superceded by including "send=true" in the invoice creation request
	More Info:  	Error 1038: JSON is not well formed
					- Encountered when trying to use the send an invoice API
					- Was sending to_mail_ids in the URL instead of the body parameters
	******************************************************************************* */
	v_BooksOrgID = "12345678901";
	v_BooksInvoiceID = 0;
	v_ZB_CustomerID = 0;
	//
	// get this order details from ZohoCreator
	c_ThisOrder = Order[ID == v_OrderID];
	//
	// get this customer record from ZohoCreator
	c_ThisCustomer = Customer[ID == c_ThisOrder.Customer];
	if(c_ThisCustomer.count() > 0)
	{
		v_CustomerName = c_ThisCustomer.Customer;
		if(!c_ThisCustomer.ZohoBooks_Customer_ID.isBlank())
		{
			v_ZB_CustomerID = c_ThisCustomer.ZohoBooks_Customer_ID;
		}
	}
	if(c_ThisOrder.count() > 0)
	{
		//
		// get invoice details
		if(!c_ThisOrder.ZohoBooks_Invoice_ID.isBlank())
		{
			v_BooksInvoiceID = c_ThisOrder.ZohoBooks_Invoice_ID;
			r_ZB_InvoiceDetails = zoho.books.getRecordsByID("invoices",v_BooksOrgID,v_BooksInvoiceID.toString(),"zbooks");
			if(r_ZB_InvoiceDetails.get("invoice") != null)
			{
				m_ZB_InvoiceDetails = r_ZB_InvoiceDetails.get("invoice");
				//
				// determine recipients
				l_ZB_InvoiceRecipients = List();
				r_ZohoBooks_CustomerDetails = zoho.books.getRecordsByID("contacts",v_BooksOrgID,m_ZB_InvoiceDetails.get("customer_id"),"zbooks");
				if(r_ZohoBooks_CustomerDetails.get("contact") != null)
				{
					if(!r_ZohoBooks_CustomerDetails.get("contact").get("email").isBlank())
					{
						l_ZB_InvoiceRecipients.add(r_ZohoBooks_CustomerDetails.get("contact").get("email"));
					}
					if(r_ZohoBooks_CustomerDetails.get("contact").get("contact_persons") != null && l_ZB_InvoiceRecipients.isEmpty())
					{
						l_ZB_ContactPersons = r_ZohoBooks_CustomerDetails.get("contact").get("contact_persons");
						for each  m_ZB_Person in l_ZB_ContactPersons
						{
							if(!m_ZB_Person.get("email").isBlank() && l_ZB_InvoiceRecipients.isEmpty())
							{
								l_ZB_InvoiceRecipients.add(m_ZB_Person.get("email"));
							}
						}
					}
				}
				//
				// email the invoice (using template and updating comments/history) - also marks as sent
				m_Params = Map();
				// recipients is a list of emails unlike contact persons in invoice request
				m_Params.put("to_mail_ids",l_ZB_InvoiceRecipients);
				v_Endpoint = "https://www.zohoapis.com/books/v3/invoices/" + v_BooksInvoiceID + "/email?organization_id=" + v_BooksOrgID;
				r_SendInvoice = invokeurl
				[
					url :v_Endpoint
					type :POST
					parameters:m_Params.toString()
					connection:"zbooks"
				];
				info "------------";
				// 				info "Send Invoice Request:";
				// 				info m_Params;
				// 				info v_Endpoint;
				// 				info "Send Invoice Response:";
				info r_SendInvoice;
			}
			//
			// no need to mark as sent as sending via the above will automatically do that in ZohoBooks.
		}
	}
}
  1.  void ZohoBooks.fn_SendZohoBooksInvoice(int p_OrderID) 
  2.  { 
  3.      v_OrderID = ifnull(input.p_OrderID,0).toLong()
  4.      /* ******************************************************************************* 
  5.      Function:       void ZohoBooks.fn_SendZohoBooksInvoice(int p_OrderID) 
  6.      Trigger:        On Demand when button in report is clicked 
  7.      Purpose:        This will send a ZohoBooks invoice directly to its recipient 
  8.      Inputs:         Zoho Creator record ID of the order 
  9.      Outputs:        - 
  10.   
  11.      Date Created:   2023-03-06 (Joel Lipman) 
  12.                      - Initial release 
  13.      Date Modified:  ??? 
  14.                      - ??? 
  15.   
  16.      More Info:      Error 7008: There are no contact persons associated with this Invoice. 
  17.                      - Encountered when trying to use the send an invoice API 
  18.                      - Need the generated invoice to pre-select a contact person to email 
  19.                      - Superceded by including "send=true" in the invoice creation request 
  20.      More Info:      Error 1038: JSON is not well formed 
  21.                      - Encountered when trying to use the send an invoice API 
  22.                      - Was sending to_mail_ids in the URL instead of the body parameters 
  23.      ******************************************************************************* */ 
  24.      v_BooksOrgID = "12345678901"
  25.      v_BooksInvoiceID = 0
  26.      v_ZB_CustomerID = 0
  27.      // 
  28.      // get this order details from ZohoCreator 
  29.      c_ThisOrder = Order[ID == v_OrderID]
  30.      // 
  31.      // get this customer record from ZohoCreator 
  32.      c_ThisCustomer = Customer[ID == c_ThisOrder.Customer]
  33.      if(c_ThisCustomer.count() > 0) 
  34.      { 
  35.          v_CustomerName = c_ThisCustomer.Customer; 
  36.          if(!c_ThisCustomer.ZohoBooks_Customer_ID.isBlank()) 
  37.          { 
  38.              v_ZB_CustomerID = c_ThisCustomer.ZohoBooks_Customer_ID; 
  39.          } 
  40.      } 
  41.      if(c_ThisOrder.count() > 0) 
  42.      { 
  43.          // 
  44.          // get invoice details 
  45.          if(!c_ThisOrder.ZohoBooks_Invoice_ID.isBlank()) 
  46.          { 
  47.              v_BooksInvoiceID = c_ThisOrder.ZohoBooks_Invoice_ID; 
  48.              r_ZB_InvoiceDetails = zoho.books.getRecordsByID("invoices",v_BooksOrgID,v_BooksInvoiceID.toString(),"zbooks")
  49.              if(r_ZB_InvoiceDetails.get("invoice") != null) 
  50.              { 
  51.                  m_ZB_InvoiceDetails = r_ZB_InvoiceDetails.get("invoice")
  52.                  // 
  53.                  // determine recipients 
  54.                  l_ZB_InvoiceRecipients = List()
  55.                  r_ZohoBooks_CustomerDetails = zoho.books.getRecordsByID("contacts",v_BooksOrgID,m_ZB_InvoiceDetails.get("customer_id"),"zbooks")
  56.                  if(r_ZohoBooks_CustomerDetails.get("contact") != null) 
  57.                  { 
  58.                      if(!r_ZohoBooks_CustomerDetails.get("contact").get("email").isBlank()) 
  59.                      { 
  60.                          l_ZB_InvoiceRecipients.add(r_ZohoBooks_CustomerDetails.get("contact").get("email"))
  61.                      } 
  62.                      if(r_ZohoBooks_CustomerDetails.get("contact").get("contact_persons") != null && l_ZB_InvoiceRecipients.isEmpty()) 
  63.                      { 
  64.                          l_ZB_ContactPersons = r_ZohoBooks_CustomerDetails.get("contact").get("contact_persons")
  65.                          for each  m_ZB_Person in l_ZB_ContactPersons 
  66.                          { 
  67.                              if(!m_ZB_Person.get("email").isBlank() && l_ZB_InvoiceRecipients.isEmpty()) 
  68.                              { 
  69.                                  l_ZB_InvoiceRecipients.add(m_ZB_Person.get("email"))
  70.                              } 
  71.                          } 
  72.                      } 
  73.                  } 
  74.                  // 
  75.                  // email the invoice (using template and updating comments/history) - also marks as sent 
  76.                  m_Params = Map()
  77.                  // recipients is a list of emails unlike contact persons in invoice request 
  78.                  m_Params.put("to_mail_ids",l_ZB_InvoiceRecipients)
  79.                  v_Endpoint = "https://www.zohoapis.com/books/v3/invoices/" + v_BooksInvoiceID + "/email?organization_id=" + v_BooksOrgID; 
  80.                  r_SendInvoice = invokeUrl 
  81.                  [ 
  82.                      url :v_Endpoint 
  83.                      type :POST 
  84.                      parameters:m_Params.toString() 
  85.                      connection:"zbooks" 
  86.                  ]
  87.                  info "------------"; 
  88.                  //                 info "Send Invoice Request:"; 
  89.                  //                 info m_Params; 
  90.                  //                 info v_Endpoint; 
  91.                  //                 info "Send Invoice Response:"; 
  92.                  info r_SendInvoice; 
  93.              } 
  94.              // 
  95.              // no need to mark as sent as sending via the above will automatically do that in ZohoBooks. 
  96.          } 
  97.      } 
  98.  } 

Additional
You can include a parameter in the request when creating an invoice which is sent = true which will automatically send it and mark it as sent. As the function I use before this to generate the invoice, also updates an invoice, I wanted to keep the action of sending separate so that staff can control that without the worry of updating an invoice and re-sending it.

Category: Zoho :: Article: 868

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.