What?

A quick note on changing the delivery address of a purchase order in Zoho Books using Deluge: create an organisation address, capture its ID, then assign that address to the purchase order.

Why?

I encountered the same error covered in my earlier article on updating a sales order's shipping address:

Please ensure that the shipping_address has less than 100 characters.

This time, it appeared when I included the shipping-address map while creating a purchase order. The sales-order solution uses a separate shipping-address endpoint; that route was not available for purchase orders. The following organisation-address method worked in my function.

How?

  1. Create the purchase order without the shipping_address map, or use an existing purchase order.
  2. Create the delivery address through POST /books/v3/organizations/address.
  3. Capture organization_address.organization_address_id from the response.
  4. Update the purchase order using that ID as delivery_org_address_id.

The extract below keeps the working requests and flags from my function. Replace the placeholder IDs, example address and books_connection connection name. The API domain shown is the EU domain used in my example.

// The purchase order must already exist.
v_BooksApiDomain = "https://www.zohoapis.eu";
v_BooksOrgId = "YOUR_ORGANIZATION_ID";
v_ZB_PO_ID = "YOUR_PURCHASEORDER_ID";

// Build the delivery address using your own values.
m_ZB_POShipping = Map();
m_ZB_POShipping.put("address","Example House");
m_ZB_POShipping.put("street2","1 Example Road");
m_ZB_POShipping.put("city","Example Town");
m_ZB_POShipping.put("state","Example County");
m_ZB_POShipping.put("zip","XX1 1XX");
m_ZB_POShipping.put("country","United Kingdom");

// Create an organisation address.
r_CreateOrgAddress = invokeurl
[
    url :v_BooksApiDomain + "/books/v3/organizations/address?organization_id=" + v_BooksOrgId
    type :POST
    parameters:m_ZB_POShipping.toString()
    headers:{"Content-Type":"application/json"}
    connection:"books_connection"
];

// Capture the newly created organisation address ID.
v_ZB_OrgAddressID = r_CreateOrgAddress.get("organization_address").get("organization_address_id");

// Assign that address to the purchase order.
v_Endpoint = v_BooksApiDomain + "/books/v3/purchaseorders/" + v_ZB_PO_ID + "?organization_id=" + v_BooksOrgId;
m_ZB_UpdatePO = Map();
m_ZB_UpdatePO.put("delivery_org_address_id",v_ZB_OrgAddressID);
m_ZB_UpdatePO.put("is_one_off_address",true);
m_ZB_UpdatePO.put("is_update_customer",false);

r_UpdatePO = invokeurl
[
    url :v_Endpoint
    type :PUT
    parameters:m_ZB_UpdatePO.toString()
    connection:"books_connection"
];
info r_UpdatePO;

The key detail: the response field is organization_address_id, but the purchase-order update field is delivery_org_address_id. Both flags above are retained from the working function.

When creating the purchase order first, its ID comes from r_ZB_PO.get("purchaseorder").get("purchaseorder_id"). Check that the organisation-address request succeeds before using its returned ID. Each run of the POST creates another organisation address.


Caveat(s)
  • After 5000 customers where I ask the supplier/vendor to send the item directly to the customer, means that my organization will have 5000 different addresses. I'm not sure if that's possible or if there is a limit.