Managing vendor agreements across procurement and finance systems often requires manually downloading executed contracts and attaching them to vendor records. This can become time-consuming and difficult to manage when dealing with a large number of contracts.
In this post, we’ll share a simple automation built using Zoho Flow, Zoho Contracts APIs, and Zoho Books that connects procurement, legal, and finance workflows.
This integration automatically:
- Creates counterparties and contracts in Zoho Contracts when a vendor is added in Zoho Books
- Detects when a contract is executed in Zoho Contracts
- Downloads the executed contract
- Attaches the signed contract to the vendor record in Zoho Books
This enables a seamless Procure-to-Pay vendor contract workflow and demonstrates how Zoho Contracts can be integrated with finance systems to streamline vendor agreement management.
Business Use Case – Procure to Pay
A typical vendor agreement lifecycle involves:
- Vendor onboarding in Zoho Books
- Contract creation, negotiation, and execution in Zoho Contracts
- Executed agreement available for the finance team’s reference
Without automation, finance teams must manually download the executed agreement and attach it to the vendor record.
Prerequisites
Before implementing this automation, ensure the following setup is completed:
- Zoho Books and Zoho Contracts are configured in your organization
- Zoho Flow is enabled and connected to both Zoho Books and Zoho Contracts
- API connections are configured for Zoho Books and Zoho Contracts in Zoho Flow
- Appropriate permissions are available to create counterparties and contracts in Zoho Contracts
- Additionally, create a custom field in Zoho Books (Vendor module) to store the Zoho Contracts Counterparty API Name.
Example:
- Field Name: Contracts Counterparty ID
- Field Type: Text
- Module: Vendors
This field helps map vendors in Zoho Books with their corresponding counterparties in Zoho Contracts.
Solution Overview
Zoho applications involved:
- Zoho Contracts
- Zoho Books
- Zoho Flow
The automation is implemented using two flows.
Flow 1 – Vendor Creation → Contract Creation
Trigger: A new vendor is created in Zoho Books.
Actions:
- Zoho Flow detects the new vendor.
- A custom function checks whether a corresponding counterparty exists in Zoho Contracts
- If the counterparty does not exist, a new counterparty is created in Zoho Contracts
- The counterparty API name is stored in Zoho Books
- A contract is automatically created in Zoho Contracts for that vendor
Custom Function Snippet (Create Counterparty and Contract):
Note: The custom functions shared below are working reference implementations. However, depending on your environment, you may need to update certain values before using them in your setup.
Please review and update the following as applicable:
- Connection names used in the invokeurl statements
- Organization ID used for Zoho Books API calls
- Custom field API names used to store the Counterparty reference in Zoho Books
- Contract type API names configured in Zoho Contracts
Ensure these values are updated according to your configuration before deploying the automation
.
- map createContract1(string vendorName, string vendorID, string counterpartyID)
- {
- result = Map();
- createdCounterPartyAPIName = "";
- if(counterpartyID != null && counterpartyID != "")
- {
- existingCounterpartyResponse = invokeurl
- [
- url :"https://contracts.zoho.in/api/v1/counterparties/" + counterpartyID
- type :GET
- connection:"zcontractsconn"
- ];
- if(existingCounterpartyResponse.get("counterparty") != null)
- {
- createdCounterPartyAPIName = existingCounterpartyResponse.get("counterparty").get("apiName");
- }
- }
- if(createdCounterPartyAPIName == "")
- {
- counterpartyMap = Map();
- counterpartyMap.put("name",vendorName);
- counterpartyMap.put("counterPartyType","vendor");
- createResponse = invokeurl
- [
- url :"https://contracts.zoho.in/api/v1/counterparties"
- type :POST
- parameters:counterpartyMap.toString()
- connection:"zcontractsconn"
- ];
- counterpartyDetail = createResponse.getJSON("counterparties").get(0);
- createdCounterPartyAPIName = counterpartyDetail.get("organizationApiName");
- customFields = List();
- cf = Map();
- cf.put("api_name","cf_contracts_counterparty_id");
- cf.put("value",createdCounterPartyAPIName);
- customFields.add(cf);
- updateMap = Map();
- updateMap.put("custom_fields",customFields);
- updateVendor = invokeurl
- [
- url :"https://books.zoho.in/api/v3/vendors/" + vendorID + "?organization_id=60047651581"
- type :PUT
- parameters:updateMap
- connection:"zbooks"
- ];
- }
- info "STEP 4 STARTED - Preparing Contract Variables";
- newContractType = "master-subscription-agreement-pro-plus";
- newContractName = "Agreement with " + vendorName;
- isNewContractTermIsDefinite = false;
- isNewContractRenewable = false;
- contractEffectiveDate = 1;
- info "Contract Type: " + newContractType;
- info "Contract Name: " + newContractName;
- info "Counterparty API Name: " + createdCounterPartyAPIName;
- newContractDetail = {"externalSource":true,"inputfields":{{"metaApiName":"contract-type","inputs":{{"inputApiName":"contract-type","inputValue":newContractType}}},{"metaApiName":"contract-term","inputs":{{"inputApiName":"contract-term","inputValue":isNewContractTermIsDefinite}}},{"metaApiName":"is-renewable","inputs":{{"inputApiName":"is-renewable","inputValue":isNewContractRenewable}}},{"metaApiName":"title","inputs":{{"inputApiName":"title","inputValue":newContractName}}},{"metaApiName":"party-b-name","inputs":{{"inputApiName":"party-b-name","inputValue":createdCounterPartyAPIName}}},{"metaApiName":"contract-effective-date","inputs":{{"inputApiName":"contract-effective-date","inputValue":contractEffectiveDate}}}}};
- createContractResponse = invokeurl
- [
- url :"https://contracts.zoho.in/api/v1/createcontract"
- type :POST
- body:newContractDetail.toString()
- headers:{"Content-Type":"application/json"}
- connection:"zcontractsconn"
- ];
- info createContractResponse;
- result.put("counterpartyApiName",createdCounterPartyAPIName);
- result.put("contractResponse",createContractResponse);
- return result;
- }
Flow 2 – Contract Execution → Attach Signed Agreement
Trigger: Contract signing is completed in Zoho Contracts
Actions:
- Zoho Flow detects the contract execution event
- A custom function calls the Zoho Contracts API to download the executed contract document.
- The function identifies the corresponding vendor in Zoho Books.
- The executed agreement is automatically attached to the vendor record in Zoho Books.
Custom Function Snippet (Retrieve and Attach Signed Contract):
- map attachSignedContractToVendor(string contractApiName, string contractTitle)
- {
- result = Map();
- orgID = "60047651581";
- info "FLOW 2 STARTED";
- info contractApiName;
- info contractTitle;
- if(contractApiName.startsWith("contract/"))
- {
- contractApiName = contractApiName.replaceAll("contract/","");
- }
- info "Clean Contract API Name: " + contractApiName;
- if(contractTitle.startsWith("Agreement with "))
- {
- vendorName = contractTitle.subString(15);
- }
- else
- {
- vendorName = contractTitle;
- }
- info "Vendor Extracted: " + vendorName;
- vendorSearch = invokeurl
- [
- url :"https://books.zoho.in/api/v3/contacts?contact_name=" + vendorName + "&organization_id=" + orgID
- type :GET
- connection:"zbooks"
- ];
- info vendorSearch;
- contactsList = vendorSearch.get("contacts");
- if(contactsList == null || contactsList.size() == 0)
- {
- info "Vendor not found";
- result.put("status","vendor_not_found");
- return result;
- }
- vendorID = contactsList.get(0).get("contact_id");
- info "Vendor ID: " + vendorID;
- info "Downloading signed contract";
- signedFile = invokeurl
- [
- url :"https://contracts.zoho.in/api/v1/download/contracts/" + contractApiName + "/signed/document"
- type :GET
- connection:"zcontractsconn"
- ];
- info signedFile;
- fileMap = Map();
- fileMap.put("attachment",signedFile);
- fileMap.put("organization_id",orgID);
- info "Uploading attachment to Zoho Books";
- uploadResponse = invokeurl
- [
- url :"https://books.zoho.in/api/v3/contacts/" + vendorID + "/attachment?organization_id=" + orgID
- type :POST
- parameters:fileMap
- connection:"zbooks"
- content-type:"multipart/form-data"
- ];
- info uploadResponse;
- result.put("uploadResponse",uploadResponse);
- info "FLOW 2 COMPLETED";
- return result;
- }
Benefits
- This automation provides several advantages:
- Eliminates manual document handling
- Ensures finance teams always have access to executed agreements
- Connects legal and finance workflows
- Improves compliance and audit readiness
- Reduces operational friction
Closing
If you're implementing Procure-to-Pay contract workflows, this approach can help streamline the connection between Zoho Contracts and finance systems like Zoho Books.
We’d be happy to discuss variations of this implementation or answer any questions.
If you're planning to implement a similar workflow and need guidance, feel free to reach out to the Zoho Contracts support team at
support@zohocontracts.com.
.
Stay tuned for more tips, tricks, and automation ideas around Zoho Contracts.
Cheers,
Sathyakeerthi
Zoho Contracts Team