Create Contract API Endpoint Unclear "inputfields" Requirements
Hello,
I'm trying to create a Deluge function that accepts inputs from a form in Zoho Creator and creates a barebones contract of a given type. See below for the current code, cleaned of authentication information.
- // Fetch form data
- // Hidden field
- client_name = input.Client_Name;
- if(client_name == null || client_name == "")
- {
- client_name = "Testing Client";
- }
- // Dropdown field
- contract_type = input.Contract_Type;
- // Single line field
- title = input.Title;
- // Multi-line field
- description = input.Description;
- // Dropdown field
- signer_name = input.Signer_Name;
- //
- // Define the access token and refresh token
- accessToken = "ACCESS_TOKEN";
- refreshToken = "REFRESH_TOKEN";
- //
- // Define headers for token refresh request
- tokenRefreshHeaders = Map();
- tokenRefreshHeaders.put("Content-Type","application/x-www-form-urlencoded");
- tokenRefreshParameters = Map();
- tokenRefreshParameters.put("grant_type","refresh_token");
- tokenRefreshParameters.put("client_id","CLIENT_ID");
- tokenRefreshParameters.put("client_secret","CLIENT_SECRET");
- tokenRefreshParameters.put("refresh_token",refreshToken);
- //
- // Refresh the access token
- response = invokeurl
- [
- url :"https://accounts.zoho.com/oauth/v2/token"
- type :POST
- parameters:tokenRefreshParameters
- headers:tokenRefreshHeaders
- ];
- if(response.get("access_token") != null)
- {
- accessToken = response.get("access_token");
- }
- //
- // Define headers for Zoho Contracts API request
- contractsHeaders = Map();
- contractsHeaders.put("Authorization","Zoho-oauthtoken " + accessToken);
- contractsHeaders.put("Content-Type","application/json");
- //
- // Prepare contract data
- contract_type = lower(replaceAll(contract_type," ","-"));
- client_name = lower(replaceAll(client_name," ","-"));
- signerNameContainsTitle = signer_name.containsIgnoreCase(". ");
- signerFirstSpace = signer_name.find(" ");
- if(signerNameContainsTitle)
- {
- signerTitle = signer_name.left(signerFirstSpace);
- signerFullName = signer_name.remove(signerTitle).trim();
- signerFirstSpace = signerFullName.find(" ");
- signerFirstName = signerFullName.left(signerFirstSpace);
- signerLastName = signerFullName.remove(signerFirstName).trim();
- }
- else
- {
- signerFirstName = signer_name.left(signerFirstSpace);
- signerLastName = signer_name.remove(signerFirstName).trim();
- }
- signer_record = zoho.crm.searchRecords("Contacts","(First_Name:equals:" + signerFirstName + ") and (Last_Name:equals:" + signerLastName + ")");
- signer_email = signer_record.get(0).get("Email");
- //
- // Create nested maps/lists in the structure of the contracts API JSON
- contractDataMap = Map();
- contractDataMap.put("source",1);
- inputFieldsList = List();
- contractTypeInputFieldMap = Map();
- contractTypeInputFieldMap.put("metaApiName","contract-type");
- contractTypeInputsList = List();
- contractTypeInput = Map();
- contractTypeInput.put("inputApiName","contract-type");
- contractTypeInput.put("inputValue","non-disclosure-agreement");
- contractTypeInputsList.add(contractTypeInput);
- contractTypeInputFieldMap.put("inputs",contractTypeInputsList);
- inputFieldsList.add(contractTypeInputFieldMap);
- titleInputFieldMap = Map();
- titleInputFieldMap.put("metaApiName","title");
- titleInputsList = List();
- titleInput = Map();
- titleInput.put("inputApiName","title");
- titleInput.put("inputValue",title);
- titleInputsList.add(titleInput);
- titleInputFieldMap.put("inputs",titleInputsList);
- inputFieldsList.add(titleInputFieldMap);
- descriptionInputFieldMap = Map();
- descriptionInputFieldMap.put("metaApiName","description");
- descriptionInputsList = List();
- descriptionInput = Map();
- descriptionInput.put("inputApiName","description");
- descriptionInput.put("inputValue",description);
- descriptionInputsList.add(descriptionInput);
- descriptionInputFieldMap.put("inputs",descriptionInputsList);
- inputFieldsList.add(descriptionInputFieldMap);
- requesterNameInputFieldMap = Map();
- requesterNameInputFieldMap.put("metaApiName","requester-name");
- requesterNameInputsList = List();
- requesterNameInput = Map();
- requesterNameInput.put("inputApiName","requester-name");
- requesterNameInput.put("inputValue","Tom Rismeyer");
- requesterNameInputsList.add(requesterNameInput);
- requesterNameInputFieldMap.put("inputs",requesterNameInputsList);
- inputFieldsList.add(requesterNameInputFieldMap);
- requesterDepartmentInputFieldMap = Map();
- requesterDepartmentInputFieldMap.put("metaApiName","requester-department");
- requesterDepartmentInputsList = List();
- requesterDepartmentInput = Map();
- requesterDepartmentInput.put("inputApiName","requester-department");
- requesterDepartmentInput.put("inputValue","sales");
- requesterDepartmentInputsList.add(requesterDepartmentInput);
- requesterDepartmentInputFieldMap.put("inputs",requesterDepartmentInputsList);
- inputFieldsList.add(requesterDepartmentInputFieldMap);
- partyBNameInputFieldMap = Map();
- partyBNameInputFieldMap.put("metaApiName","party-b-name");
- partyBNameInputsList = List();
- partyBNameInput = Map();
- partyBNameInput.put("inputApiName","party-b-name");
- partyBNameInput.put("inputValue","guy-mcnobody);
- partyBNameInputsList.add(partyBNameInput);
- partyBNameInputFieldMap.put("inputs",partyBNameInputsList);
- inputFieldsList.add(partyBNameInputFieldMap);
- counterpartyPrimaryContactInputFieldMap = Map();
- counterpartyPrimaryContactInputFieldMap.put("metaApiName","counterparty-primary-contact");
- counterpartyPrimaryContactInputsList = List();
- counterpartyPrimaryContactInput = Map();
- counterpartyPrimaryContactInput.put("inputApiName","party-b-primary-contact-name");
- counterpartyPrimaryContactInput.put("inputValue",signer_email);
- counterpartyPrimaryContactInputsList.add(counterpartyPrimaryContactInput);
- counterpartyPrimaryContactInputFieldMap.put("inputs",counterpartyPrimaryContactInputsList);
- inputFieldsList.add(counterpartyPrimaryContactInputFieldMap);
- contractTermInputFieldMap = Map();
- contractTermInputFieldMap.put("metaApiName","contract-term");
- contractTermInputsList = List();
- contractTermInput = Map();
- contractTermInput.put("inputApiName","contract-term");
- contractTermInput.put("inputValue",false);
- contractTermInputsList.add(contractTermInput);
- contractTermInputFieldMap.put("inputs",contractTermInputsList);
- inputFieldsList.add(contractTermInputFieldMap);
- contractEffectiveDateInputFieldMap = Map();
- contractEffectiveDateInputFieldMap.put("metaApiName","contract-effective-date");
- contractEffectiveDateInputsList = List();
- contractEffectiveDateInput = Map();
- contractEffectiveDateInput.put("inputApiName","contract-effective-date");
- contractEffectiveDateInput.put("inputValue",1);
- contractEffectiveDateInputsList.add(contractEffectiveDateInput);
- contractEffectiveDateInputFieldMap.put("inputs",contractEffectiveDateInputsList);
- inputFieldsList.add(contractEffectiveDateInputFieldMap);
- renewalTypeInputFieldMap = Map();
- renewalTypeInputFieldMap.put("metaApiName","renewal-type");
- renewalTypeInputsList = List();
- renewalTypeInput = Map();
- renewalTypeInput.put("inputApiName","renewal-type");
- renewalTypeInput.put("inputValue",1);
- renewalTypeInputsList.add(renewalTypeInput);
- renewalTypeInputFieldMap.put("inputs",renewalTypeInputsList);
- inputFieldsList.add(renewalTypeInputFieldMap);
- contractDataMap.put("inputfields",inputFieldsList);
- //
- // Create the contract in Zoho Contracts
- response = invokeurl
- [
- url :"https://contracts.zoho.com/api/v1/contracts"
- type :POST
- parameters:contractDataMap
- headers:contractsHeaders
- ];
- if(response.get("code") == 201)
- {
- alert "Contract created successfully";
- }
- else
- {
- alert "Error in creating contract: " + response.toString();
- cancel submit;
- }
Here is the resulting JSON per logging:
- {
- "source": 1,
- "inputfields": [
- {
- "metaApiName": "contract-type",
- "inputs": [
- {
- "inputApiName": "contract-type",
- "inputValue": "non-disclosure-agreement"
- }
- ]
- },
- {
- "metaApiName": "title",
- "inputs": [
- {
- "inputApiName": "title",
- "inputValue": "Test title"
- }
- ]
- },
- {
- "metaApiName": "description",
- "inputs": [
- {
- "inputApiName": "description",
- "inputValue": ""
- }
- ]
- },
- {
- "metaApiName": "requester-name",
- "inputs": [
- {
- "inputApiName": "requester-name",
- "inputValue": "Tom Rismeyer"
- }
- ]
- },
- {
- "metaApiName": "requester-department",
- "inputs": [
- {
- "inputApiName": "requester-department",
- "inputValue": "sales"
- }
- ]
- },
- {
- "metaApiName": "party-b-name",
- "inputs": [
- {
- "inputApiName": "party-b-name",
- "inputValue": "guy-mcnobody"
- }
- ]
- },
- {
- "metaApiName": "counterparty-primary-contact",
- "inputs": [
- {
- "inputApiName": "party-b-primary-contact-name",
- "inputValue": "contact@mail.com"
- }
- ]
- },
- {
- "metaApiName": "contract-term",
- "inputs": [
- {
- "inputApiName": "contract-term",
- "inputValue": false
- }
- ]
- },
- {
- "metaApiName": "contract-effective-date",
- "inputs": [
- {
- "inputApiName": "contract-effective-date",
- "inputValue": 1
- }
- ]
- },
- {
- "metaApiName": "renewal-type",
- "inputs": [
- {
- "inputApiName": "renewal-type",
- "inputValue": 1
- }
- ]
- }
- ]
- }
I'm getting this error when I submit the form, triggering the deluge function:
The error message is not very helpful, as it does not specify where it has an issue when parsing the JSON. The
API documentation does not specify which fields are required for the Create Contract Endpoint, so I'm either left posting here to request more info, or to just tinker with different combinations of fields included and excluded, so I'm posting here. Can anybody help determine exactly which fields I'm missing, using incorrectly, or other issues with the JSON?
Zoho Developer Community
Deliver unforgettable customer experiences
Deliver unforgettable customer experiences
New to Zoho Marketing Plus?
Everything you need to run your marketing
New to Zoho Marketing Plus?
Everything you need to run your marketing
Zoho Desk Resources
-
Desk Community Learning Series
-
-
-
-
-
-
-
-
-
Zoho TeamInbox Resources
Zoho DataPrep Resources
Zoho CRM Plus Resources
Zoho Books Resources
Zoho Subscriptions Resources
Zoho Projects Resources
Zoho Sprints Resources
Qntrl Resources
Zoho Creator Resources
Zoho WorkDrive Resources
Zoho Campaigns Resources
Zoho CRM Resources
Zoho Show Resources
Writer Get Started. Write Away!
Writer is a powerful online word processor, designed for collaborative work.