For Zoho services only


I'm currently part of a wider delivery team at Ascent Business Solutions, recognised as a leading Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions support organisations with everything from targeted technical fixes through to full Zoho CRM implementations and long-term platform adoption. Working as a team rather than a one-person consultancy allows projects to move forward consistently, with access to the right skills at each stage.

The team I manage specialises in API integrations between Zoho and third-party finance and commerce platforms such as Xero, Shopify, WooCommerce, and eBay. Much of our work involves solving integration challenges that fall outside standard documentation, supporting new ideas, new sectors, and evolving business models.

Success is measured through practical outcomes and return on investment, ranging from scaling small operations into high-turnover businesses to delivering rapid gains through online payments, automation, and streamlined digital workflows.

If you are looking for structured Zoho expertise backed by an established consultancy, you can contact Ascent Business Solutions on 0121 392 8140 (UK), email info@ascentbusiness.co.uk, or visit https://www.ascentbusiness.co.uk.
ZohoBooks: Error 7008: There are no contact persons associated with this Invoice

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 Books :: Article: 397

Accreditation

Badge - Zoho Creator Certified Developer Associate
Badge - Zoho Deluge Certified Developer
Badge - Certified Zoho CRM Developer

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

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