Print

ZohoCRM to ZohoBooks: Please ensure that the shipping_address has less than 100 characters.

What?
An article to note something I didn't realize I needed: How to address the above error and how to update a Shipping Address for a specific Sales Order in Zoho Books.

Why?
You might think the following request to create a Sales Order in Zoho Books would be enough:
copyraw
{
  "date": "2021-09-08",
  "zcrm_potential_id": "123456789012345678",
  "currency_code": "GBP",
  "reference_number": "Salespersons Test Reference",
  "terms": "These are our test terms and conditions",
  "customer_id": "234567890123456789",
  "payment_terms": 30,
  "salesperson_id": "345678901234567890",
  "line_items": [
    {
      "item_id": "456789012345678901",
      "discount": 0,
      "quantity": 1,
      "description": "A test product description"
    }
  ],
  "shipping_address": {
    "address": "Test Street",
    "street2": "Test Street 2",
    "city": "Test City",
    "state": "Test State",
    "zip": "Test Postal Code",
    "country": "Test Country"
  }
}
  1.  { 
  2.    "date": "2021-09-08", 
  3.    "zcrm_potential_id": "123456789012345678", 
  4.    "currency_code": "GBP", 
  5.    "reference_number": "Salespersons Test Reference", 
  6.    "terms": "These are our test terms and conditions", 
  7.    "customer_id": "234567890123456789", 
  8.    "payment_terms": 30, 
  9.    "salesperson_id": "345678901234567890", 
  10.    "line_items": [ 
  11.      { 
  12.        "item_id": "456789012345678901", 
  13.        "discount": 0, 
  14.        "quantity": 1, 
  15.        "description": "A test product description" 
  16.      } 
  17.    ], 
  18.    "shipping_address": { 
  19.      "address": "Test Street", 
  20.      "street2": "Test Street 2", 
  21.      "city": "Test City", 
  22.      "state": "Test State", 
  23.      "zip": "Test Postal Code", 
  24.      "country": "Test Country" 
  25.    } 
  26.  } 
However, if you try forcing the billing or shipping address in you should get the following error:
Please ensure that the shipping_address has less than 100 characters.

How?
If you get the above error, the community forums will advise you to get the ID of the Shipping Address... But let's say I don't know how to create a shipping address and retrieve its ID then here's the method I use:
  1. Create the sales order in ZohoBooks (either in Zoho Deluge or however you're doing it), then
  2. Retrieve the ID of the created Sales Order (captured in response)
  3. Update the Shipping Address on the Sales Order in Zoho Books using the API

The following is the code template I use but you will need to adapt it for your own system:
copyraw
// init (specify your own organization ID for Zoho Books)
v_BooksOrgID = 20210922122;
m_BooksCreateSO = Map();
// get CRM record details
r_SoDetails = zoho.crm.getRecordById("Sales_Orders", 012345678901234567);
// build up your map to send to ZohoBooks to create the Sales Order
m_BooksCreateSO.put("date",zoho.currentdate);
//
// push to ZohoBooks
r_CreateSO = zoho.books.createRecord("salesorders",v_BooksOrgID,m_BooksCreateSO,"ab_books");
// output response
info r_CreateSO;
// read response
if(!isnull(r_CreateSO.get("salesorder")))
{
	v_SalesOrderID = r_CreateSO.get("salesorder").get("salesorder_id");
	//
	v_AddressIndex = 0;
	m_ShippingAddress = Map();
	// set field api names that we will read from and write to
	l_CrmShippingAddress = {"Shipping_Street","Shipping_Street_2","Shipping_City","Shipping_State","Shipping_Code","Shipping_Country"};
	l_BooksShippingAddress = {"address","street2","city","state","zip","country"};
	// loop through the CRM Sales Order address fields and build map of address to Books
	for each  v_AddressPart in l_CrmShippingAddress
	{
		m_ShippingAddress.put(l_BooksShippingAddress.get(v_AddressIndex),ifnull(r_SoDetails.get(v_AddressPart),""));
		v_AddressIndex = v_AddressIndex + 1;
	}
	// check that there was something to actually update rather than wasting an API call
	if(m_ShippingAddress.size() > 0)
	{
		// endpoint TLD is EU for Europe DC and COM for US DC
		v_Endpoint = "https://books.zoho.eu/api/v3/salesorders/"+v_SalesOrderID+"/address/shipping?organization_id=" + v_BooksOrgID;
		// saw this in the documentation example so will hopefully do what it says
		m_ShippingAddress.put("is_one_off_address",true);
		m_ShippingAddress.put("is_update_customer",false);
		// send the request via API (change connection name to your own)
		r_UpdateSO = invokeurl
		[
        	url: v_Endpoint
            type: PUT
            parameters: m_ShippingAddress.toString()
            connection: "joels_connector"
		];
		info r_UpdateSO;
	}	
}
  1.  // init (specify your own organization ID for Zoho Books) 
  2.  v_BooksOrgID = 20210922122
  3.  m_BooksCreateSO = Map()
  4.  // get CRM record details 
  5.  r_SoDetails = zoho.crm.getRecordById("Sales_Orders", 012345678901234567)
  6.  // build up your map to send to ZohoBooks to create the Sales Order 
  7.  m_BooksCreateSO.put("date",zoho.currentdate)
  8.  // 
  9.  // push to ZohoBooks 
  10.  r_CreateSO = zoho.books.createRecord("salesorders",v_BooksOrgID,m_BooksCreateSO,"ab_books")
  11.  // output response 
  12.  info r_CreateSO; 
  13.  // read response 
  14.  if(!isnull(r_CreateSO.get("salesorder"))) 
  15.  { 
  16.      v_SalesOrderID = r_CreateSO.get("salesorder").get("salesorder_id")
  17.      // 
  18.      v_AddressIndex = 0
  19.      m_ShippingAddress = Map()
  20.      // set field api names that we will read from and write to 
  21.      l_CrmShippingAddress = {"Shipping_Street","Shipping_Street_2","Shipping_City","Shipping_State","Shipping_Code","Shipping_Country"}
  22.      l_BooksShippingAddress = {"address","street2","city","state","zip","country"}
  23.      // loop through the CRM Sales Order address fields and build map of address to Books 
  24.      for each  v_AddressPart in l_CrmShippingAddress 
  25.      { 
  26.          m_ShippingAddress.put(l_BooksShippingAddress.get(v_AddressIndex),ifnull(r_SoDetails.get(v_AddressPart),""))
  27.          v_AddressIndex = v_AddressIndex + 1
  28.      } 
  29.      // check that there was something to actually update rather than wasting an API call 
  30.      if(m_ShippingAddress.size() > 0) 
  31.      { 
  32.          // endpoint TLD is EU for Europe DC and COM for US DC 
  33.          v_Endpoint = "https://books.zoho.eu/api/v3/salesorders/"+v_SalesOrderID+"/address/shipping?organization_id=" + v_BooksOrgID; 
  34.          // saw this in the documentation example so will hopefully do what it says 
  35.          m_ShippingAddress.put("is_one_off_address",true)
  36.          m_ShippingAddress.put("is_update_customer",false)
  37.          // send the request via API (change connection name to your own) 
  38.          r_UpdateSO = invokeUrl 
  39.          [ 
  40.              url: v_Endpoint 
  41.              type: PUT 
  42.              parameters: m_ShippingAddress.toString() 
  43.              connection: "joels_connector" 
  44.          ]
  45.          info r_UpdateSO; 
  46.      } 
  47.  } 

Source(s):
Category: Zoho :: Article: 772