### Initialize Zoho CRM SDK
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/samples/cors-zcrm-apis/index.html
Initializes the Zoho CRM JavaScript SDK. This function must be called before making any other SDK calls to establish a connection and set up the client.
```javascript
ZCRMSample.init();
```
--------------------------------
### Show Lead Creation Form
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/samples/cors-zcrm-apis/index.html
Hides the lead list view and displays the form for creating a new lead.
```javascript
async function createLead() {
document.getElementById("listview").style.display = 'none';
document.getElementById("createView").style.display = 'block';
}
```
--------------------------------
### Initialize Zoho CRM SDK
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/samples/cors-zcrm-apis/index.html
Initializes the Zoho CRM JavaScript SDK. This function must be called before making any other SDK calls to establish a connection and set up the client.
```javascript
ZCRMSample.init();
```
--------------------------------
### ZET Framework Project Setup Commands
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
Commands for initializing, packaging, and running projects using the ZET framework, which is integrated with the Zoho CRM JavaScript SDK. These commands facilitate project creation and deployment.
```shell
zet init
# Choose the option `Catalyst` and give the project name.
```
```shell
zet pack
# From the project base folder, used to package the app for upload to CRM UI.
```
```shell
zet run
# Used to test the application locally on a web framework.
```
--------------------------------
### Show Lead Creation Form
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/samples/cors-zcrm-apis/index.html
Hides the lead list view and displays the form for creating a new lead.
```javascript
async function createLead() {
document.getElementById("listview").style.display = 'none';
document.getElementById("createView").style.display = 'block';
}
```
--------------------------------
### Initialize Zoho CRM SDK
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/cors-zcrm-apis/index.html
Initializes the Zoho CRM JavaScript SDK. This function must be called before making any other SDK calls to establish a connection and set up the client.
```javascript
ZCRMSample.init();
```
--------------------------------
### Fetch and Display Leads
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/samples/cors-zcrm-apis/index.html
Fetches lead records from Zoho CRM using the SDK and renders them in an HTML table. It handles toggling UI elements to show the list view.
```javascript
async function createListView() {
document.getElementById("createView").style.display = 'none';
document.getElementById("listview").style.display = 'none';
var html = "
| Name | School/College Name | Course Name | Email | Mobile |
"
html += await ZCRMSample.Lead.get("Leads");
html += "
";
document.getElementById('listview').innerHTML = html;
}
```
```javascript
async function createListViewafterBClick() {
document.getElementById("createView").style.display = 'none';
document.getElementById("listview").style.display = 'block';
var html = " | Name | School/College Name | Course Name | Email | Mobile |
"
html += await ZCRMSample.Lead.get("Leads");
html += "
";
document.getElementById('listview').innerHTML = html;
}
```
--------------------------------
### Show Lead Creation Form
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/cors-zcrm-apis/index.html
Hides the lead list view and displays the form for creating a new lead.
```javascript
async function createLead() {
document.getElementById("listview").style.display = 'none';
document.getElementById("createView").style.display = 'block';
}
```
--------------------------------
### Fetch and Display Leads
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/samples/cors-zcrm-apis/index.html
Fetches lead records from Zoho CRM using the SDK and renders them in an HTML table. It handles toggling UI elements to show the list view.
```javascript
async function createListView() {
document.getElementById("createView").style.display = 'none';
document.getElementById("listview").style.display = 'none';
var html = " | Name | School/College Name | Course Name | Email | Mobile |
"
html += await ZCRMSample.Lead.get("Leads");
html += "
";
document.getElementById('listview').innerHTML = html;
}
```
```javascript
async function createListViewafterBClick() {
document.getElementById("createView").style.display = 'none';
document.getElementById("listview").style.display = 'block';
var html = " | Name | School/College Name | Course Name | Email | Mobile |
"
html += await ZCRMSample.Lead.get("Leads");
html += "
";
document.getElementById('listview').innerHTML = html;
}
```
--------------------------------
### Call Zoho CRM Record Creation
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/samples/create_records_sample/index.html
Demonstrates calling a record creation method from the Zoho CRM JavaScript SDK. This function likely initiates the process of creating new records within Zoho CRM. It requires the SDK to be properly initialized and configured.
```javascript
CreateRecords.call();
```
--------------------------------
### Call Zoho CRM Record Creation
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/samples/create_records_sample/index.html
Demonstrates calling a record creation method from the Zoho CRM JavaScript SDK. This function likely initiates the process of creating new records within Zoho CRM. It requires the SDK to be properly initialized and configured.
```javascript
CreateRecords.call();
```
--------------------------------
### Fetch and Display Leads
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/cors-zcrm-apis/index.html
Fetches lead records from Zoho CRM using the SDK and renders them in an HTML table. It handles toggling UI elements to show the list view.
```javascript
async function createListView() {
document.getElementById("createView").style.display = 'none';
document.getElementById("listview").style.display = 'none';
var html = " | Name | School/College Name | Course Name | Email | Mobile |
"
html += await ZCRMSample.Lead.get("Leads");
html += "
";
document.getElementById('listview').innerHTML = html;
}
```
```javascript
async function createListViewafterBClick() {
document.getElementById("createView").style.display = 'none';
document.getElementById("listview").style.display = 'block';
var html = " | Name | School/College Name | Course Name | Email | Mobile |
"
html += await ZCRMSample.Lead.get("Leads");
html += "
";
document.getElementById('listview').innerHTML = html;
}
```
--------------------------------
### Initialize ZCRM JS SDK
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/samples/cors-zcrm-apis/README.md
Provides a code example for initializing the ZCRM JavaScript SDK. This includes setting up logging, defining the data center environment, building the OAuth token with client ID and scopes, and configuring SDK settings like auto-refresh and caching.
```javascript
let logger = Logger.getInstance(Levels.ALL);
let environment = DataCenter.US.PRODUCTION();
let token = new OAuthBuilder()
.clientId("1000.xxxx")
.scope("ZohoCRM.modules.ALL,ZohoCRM.settings.ALL")
.redirectURL("http://127.0.0.1:5501/redirect.html")
.build();
let sdkConfig = new SDKConfigBuilder()
.autoRefreshFields(true)
.cacheStore(true)
.pickListValidation(false).build();
(await new InitializeBuilder())
.environment(environment)
.token(token)
.initialize();
```
--------------------------------
### Call Zoho CRM Record Creation
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/create_records_sample/index.html
Demonstrates calling a record creation method from the Zoho CRM JavaScript SDK. This function likely initiates the process of creating new records within Zoho CRM. It requires the SDK to be properly initialized and configured.
```javascript
CreateRecords.call();
```
--------------------------------
### Initialize ZCRM JS SDK
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/samples/cors-zcrm-apis/README.md
Provides a code example for initializing the ZCRM JavaScript SDK. This includes setting up logging, defining the data center environment, building the OAuth token with client ID and scopes, and configuring SDK settings like auto-refresh and caching.
```javascript
let logger = Logger.getInstance(Levels.ALL);
let environment = DataCenter.US.PRODUCTION();
let token = new OAuthBuilder()
.clientId("1000.xxxx")
.scope("ZohoCRM.modules.ALL,ZohoCRM.settings.ALL")
.redirectURL("http://127.0.0.1:5501/redirect.html")
.build();
let sdkConfig = new SDKConfigBuilder()
.autoRefreshFields(true)
.cacheStore(true)
.pickListValidation(false).build();
(await new InitializeBuilder())
.environment(environment)
.token(token)
.initialize();
```
--------------------------------
### Create Lead Record from Form
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/samples/cors-zcrm-apis/index.html
Serializes form data, creates a new lead record in Zoho CRM using the SDK, and then refreshes the lead list view. Returns false to prevent default form submission.
```javascript
async function createLeadForm() {
var formObj = {};
var inputs = $('#leadForm').serializeArray();
$.each(inputs, function (i, input) {
formObj[input.name] = input.value;
});
await ZCRMSample.Lead.create("Leads", formObj);
viewRecords();
return false;
}
```
--------------------------------
### Create Lead Record from Form
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/samples/cors-zcrm-apis/index.html
Serializes form data, creates a new lead record in Zoho CRM using the SDK, and then refreshes the lead list view. Returns false to prevent default form submission.
```javascript
async function createLeadForm() {
var formObj = {};
var inputs = $('#leadForm').serializeArray();
$.each(inputs, function (i, input) {
formObj[input.name] = input.value;
});
await ZCRMSample.Lead.create("Leads", formObj);
viewRecords();
return false;
}
```
--------------------------------
### Initialize ZCRM JS SDK
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/cors-zcrm-apis/README.md
Provides a code example for initializing the ZCRM JavaScript SDK. This includes setting up logging, defining the data center environment, building the OAuth token with client ID and scopes, and configuring SDK settings like auto-refresh and caching.
```javascript
let logger = Logger.getInstance(Levels.ALL);
let environment = DataCenter.US.PRODUCTION();
let token = new OAuthBuilder()
.clientId("1000.xxxx")
.scope("ZohoCRM.modules.ALL,ZohoCRM.settings.ALL")
.redirectURL("http://127.0.0.1:5501/redirect.html")
.build();
let sdkConfig = new SDKConfigBuilder()
.autoRefreshFields(true)
.cacheStore(true)
.pickListValidation(false).build();
(await new InitializeBuilder())
.environment(environment)
.token(token)
.initialize();
```
--------------------------------
### Create Lead Record from Form
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/cors-zcrm-apis/index.html
Serializes form data, creates a new lead record in Zoho CRM using the SDK, and then refreshes the lead list view. Returns false to prevent default form submission.
```javascript
async function createLeadForm() {
var formObj = {};
var inputs = $('#leadForm').serializeArray();
$.each(inputs, function (i, input) {
formObj[input.name] = input.value;
});
await ZCRMSample.Lead.create("Leads", formObj);
viewRecords();
return false;
}
```
--------------------------------
### ZET Framework CLI Commands
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Commands for initializing, packaging, and running Zoho Extension Toolkit (ZET) projects, essential for integrating the Zoho CRM JavaScript SDK.
```bash
zet init
# Choose 'Catalyst' option for Zoho CRM integration.
```
```bash
zet pack
# Packages the ZET project for deployment to Zoho CRM.
```
```bash
zet run
# Runs the ZET project locally for testing purposes.
```
--------------------------------
### Delete Lead Record
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/samples/cors-zcrm-apis/index.html
Deletes a lead record from Zoho CRM using its ID and then refreshes the lead list view.
```javascript
async function deleteR(id) {
await ZCRMSample.Lead.delete_0("Leads", id);
viewRecords();
}
```
--------------------------------
### Delete Lead Record
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/samples/cors-zcrm-apis/index.html
Deletes a lead record from Zoho CRM using its ID and then refreshes the lead list view.
```javascript
async function deleteR(id) {
await ZCRMSample.Lead.delete_0("Leads", id);
viewRecords();
}
```
--------------------------------
### Initialize Zoho CRM JavaScript SDK
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Demonstrates how to initialize the Zoho CRM JavaScript SDK with environment, token, configuration, and logger settings. Includes configuration options like auto-refresh fields, cache storage, picklist validation, and request timeouts.
```javascript
class SDKInitializer {
static async initializeSDK() {
/*
* Create an instance of Logger Class that takes parameter
* 1 -> Level of the log messages to be logged. Can be configured by typing Levels "." and choose any level from the list displayed.
*/
let logger = Logger.getInstance(Levels.ALL);
/*
* Configure the environment
* which is of the pattern Domain.Environment
* Available Domains: US, EU, IN, CN, AU, CA
* Available Environments: PRODUCTION(), DEVELOPER(), SANDBOX()
*/
let environment = DataCenter.US.PRODUCTION();
/*
* Create a Token instance
* clientId -> OAuth client id.
* scope -> OAuth client scope.
* redirectURL -> OAuth Redirect URL.
*/
let token = new OAuthBuilder()
.clientId("clientId")
.scope("scope")
.redirectURL("redirectURL")
.build();
/*
* autoRefreshFields
* if true - all the modules' fields will be auto-refreshed in the background, every hour.
* if false - the fields will not be auto-refreshed in the background. The user can manually delete the cache or refresh the fields using methods from ModuleFieldsHandler
*
* cacheStore
* A boolean field that allows or disallows the storage of module field information in cache.
* True - the SDK stores all the modules' field information in cache, and refreshes every hour, if autoRefreshFields is true.
* False - the SDK temporarily stores the modules' field information in a Map.
*
* pickListValidation
* A boolean field that validates user input for a pick list field and allows or disallows the addition of a new value to the list.
* True - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
* False - the SDK does not validate the input and makes the API request with the user’s input to the pick list
*
* timeout
* representing the number of milliseconds a request can take before automatically being terminated.
*/
let sdkConfig = new SDKConfigBuilder()
.autoRefreshFields(true)
.pickListValidation(false)
.cacheStore(true)
.build();
/*
* Call the static initialize method of Initializer class that takes the following arguments
* environment -> Environment instance
* SDKConfig -> SDKConfig instance
* token -> Token instance
* logger -> Logger instance
*/
(await new InitializeBuilder())
.environment(environment)
.token(token)
.SDKConfig(sdkConfig)
.logger(logger)
.initialize();
}
}
```
--------------------------------
### Delete Lead Record
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/cors-zcrm-apis/index.html
Deletes a lead record from Zoho CRM using its ID and then refreshes the lead list view.
```javascript
async function deleteR(id) {
await ZCRMSample.Lead.delete_0("Leads", id);
viewRecords();
}
```
--------------------------------
### Update Lead Record
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/samples/cors-zcrm-apis/index.html
Updates a specific lead record in Zoho CRM by appending '1' to the Last Name. It then refreshes the lead list view.
```javascript
async function edit(id) {
alert("This will update Last Name with 1")
var input = { "Last_Name": $("tr[data-id='" + id + "'] td")[1].innerHTML + "1" };
await ZCRMSample.Lead.update("Leads", id, input);
viewRecords();
}
```
--------------------------------
### Initialize Zoho CRM JavaScript SDK
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
Demonstrates how to initialize the Zoho CRM JavaScript SDK with environment, token, configuration, and logger settings. Includes configuration options like auto-refresh fields, cache storage, picklist validation, and request timeouts.
```javascript
class SDKInitializer {
static async initializeSDK() {
/*
* Create an instance of Logger Class that takes parameter
* 1 -> Level of the log messages to be logged. Can be configured by typing Levels "." and choose any level from the list displayed.
*/
let logger = Logger.getInstance(Levels.ALL);
/*
* Configure the environment
* which is of the pattern Domain.Environment
* Available Domains: US, EU, IN, CN, AU, CA
* Available Environments: PRODUCTION(), DEVELOPER(), SANDBOX()
*/
let environment = DataCenter.US.PRODUCTION();
/*
* Create a Token instance
* clientId -> OAuth client id.
* scope -> OAuth client scope.
* redirectURL -> OAuth Redirect URL.
*/
let token = new OAuthBuilder()
.clientId("clientId")
.scope("scope")
.redirectURL("redirectURL")
.build();
/*
* autoRefreshFields
* if true - all the modules' fields will be auto-refreshed in the background, every hour.
* if false - the fields will not be auto-refreshed in the background. The user can manually delete the cache or refresh the fields using methods from ModuleFieldsHandler
*
* cacheStore
* A boolean field that allows or disallows the storage of module field information in cache.
* True - the SDK stores all the modules' field information in cache, and refreshes every hour, if autoRefreshFields is true.
* False - the SDK temporarily stores the modules' field information in a Map.
*
* pickListValidation
* A boolean field that validates user input for a pick list field and allows or disallows the addition of a new value to the list.
* True - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
* False - the SDK does not validate the input and makes the API request with the user’s input to the pick list
*
* timeout
* representing the number of milliseconds a request can take before automatically being terminated.
*/
let sdkConfig = new SDKConfigBuilder()
.autoRefreshFields(true)
.pickListValidation(false)
.cacheStore(true)
.build();
/*
* Call the static initialize method of Initializer class that takes the following arguments
* environment -> Environment instance
* SDKConfig -> SDKConfig instance
* token -> Token instance
* logger -> Logger instance
*/
(await new InitializeBuilder())
.environment(environment)
.token(token)
.SDKConfig(sdkConfig)
.logger(logger)
.initialize();
}
}
```
--------------------------------
### Update Lead Record
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/samples/cors-zcrm-apis/index.html
Updates a specific lead record in Zoho CRM by appending '1' to the Last Name. It then refreshes the lead list view.
```javascript
async function edit(id) {
alert("This will update Last Name with 1")
var input = { "Last_Name": $("tr[data-id='" + id + "'] td")[1].innerHTML + "1" };
await ZCRMSample.Lead.update("Leads", id, input);
viewRecords();
}
```
--------------------------------
### Update Lead Record
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/cors-zcrm-apis/index.html
Updates a specific lead record in Zoho CRM by appending '1' to the Last Name. It then refreshes the lead list view.
```javascript
async function edit(id) {
alert("This will update Last Name with 1")
var input = { "Last_Name": $("tr[data-id='" + id + "'] td")[1].innerHTML + "1" };
await ZCRMSample.Lead.update("Leads", id, input);
viewRecords();
}
```
--------------------------------
### ZET Framework Project Structure and Configuration
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Details on configuring the ZET framework project, specifically updating the client ID and scopes in the plugin_manifest.json file.
```APIDOC
ZET Project Configuration:
1. After `zet init`, a project folder is created.
2. Inside the project folder, locate `plugin_manifest.json`.
3. Update the `client_id` in `plugin_manifest.json` with your registered Zoho Client ID.
4. Add required OAuth scopes to be used by the web app within the same file.
Example `plugin_manifest.json` snippet:
{
"client_id": "YOUR_ZOHO_CLIENT_ID",
"scopes": [
"ZohoCRM.users.ALL",
"ZohoCRM.settings.ALL"
],
// ... other configurations
}
```
--------------------------------
### Zoho API Console Registration Steps
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Steps to register a client application with Zoho API Console for OAuth2 authentication, including required fields and URIs.
```APIDOC
Register Zoho Client:
1. Visit https://api-console.zoho.com/
2. Click 'ADD CLIENT'.
3. Choose 'Client Type' as 'Client-based Applications'.
4. Enter:
- Client Name: Your application's name.
- Homepage URL: The main URL of your application.
- Authorized Redirect URIs: URLs where users will be redirected after authorization (e.g., https://yourdomain.com/callback).
- JavaScript Domain: The domain from which your JavaScript application will be served (e.g., https://yourdomain.com).
5. Click 'CREATE'.
Note: For Webapps Integration, the redirect URI might be dynamically generated and needs to be configured in the API Console. Example: "https://99000000223015.zappscontents.com/appfiles/99000000223015/1.0/1dd62561c00429f2c4970bf4f2b4dc09142d08b6949a17a5c3388f30851ec9cf/redirect.html"
```
--------------------------------
### Initialize Zoho CRM SDK and Create Records
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
This snippet demonstrates initializing the Zoho CRM JavaScript SDK with OAuth credentials and then creating new records for a specified module. It covers setting standard and custom fields, adding consent details, managing tags, and processing the API response, including detailed handling of success and API exception objects.
```javascript
class CreateRecords {
static async call() {
let environment = DataCenter.US.PRODUCTION();
let token = new OAuthBuilder()
.clientId("clientId")
.scope("scope")
.redirectURL("http://127.0.0.1:5500/redirect.html")
.build();
(await new InitializeBuilder())
.environment(environment)
.token(token)
.initialize();
await GetRecords.createRecords("Leads");
}
static async createRecords(moduleAPIName) {
let recordOperations = new ZCRM.Record.Operations(moduleAPIName);
let request = new ZCRM.Record.Model.BodyWrapper();
let recordsArray = [];
let record = new ZCRM.Record.Model.Record();
record.addFieldValue(ZCRM.Record.Model.Field.Leads.LAST_NAME, "JS SDK");
record.addFieldValue(ZCRM.Record.Model.Field.Leads.FIRST_NAME, "JS");
record.addFieldValue(ZCRM.Record.Model.Field.Leads.COMPANY, "ZCRM");
record.addFieldValue(ZCRM.Record.Model.Field.Leads.CITY, "City");
record.addKeyValue("Custom_field", "Value");
record.addKeyValue("Custom_field_2", "value");
record.addKeyValue("Date_1", new Date(2020, 10, 20));
//Used when GDPR is enabled
let dataConsent = new ZCRM.Record.Model.Consent();
dataConsent.setConsentRemarks("Approved.");
dataConsent.setConsentThrough("Email");
dataConsent.setContactThroughEmail(true);
dataConsent.setContactThroughSocial(false);
record.addKeyValue("Data_Processing_Basis_Details", dataConsent);
let tagsArray = [];
let tag = new ZCRM.Tag.Model.Tag();
tag.setName("Testtask");
tagsArray.push(tag);
record.setTag(tagsArray);
recordsArray.push(record);
request.setData(recordsArray);
let trigger = [];
trigger.push("approval");
trigger.push("workflow");
trigger.push("blueprint");
request.setTrigger(trigger);
let process = ["review_process"];
request.setProcess(process);
let headerInstance = new HeaderMap();
let response = await recordOperations.createRecords(request, headerInstance);
if (response != null) {
console.log("Status Code: " + response.getStatusCode());
let responseObject = response.getObject();
if (responseObject != null) {
if (responseObject instanceof ZCRM.Record.Model.ActionWrapper) {
let actionResponses = responseObject.getData();
actionResponses.forEach(actionResponse => {
if (actionResponse instanceof ZCRM.Record.Model.SuccessResponse) {
console.log("Status: " + actionResponse.getStatus().getValue());
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
let details = actionResponse.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + actionResponse.getMessage().getValue());
}
else if (actionResponse instanceof ZCRM.Record.Model.APIException) {
console.log("Status: " + actionResponse.getStatus().getValue());
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
let details = actionResponse.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + actionResponse.getMessage().getValue());
}
});
}
else if (responseObject instanceof ZCRM.Record.Model.APIException) {
console.log("Status: " + responseObject.getStatus().getValue());
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
let details = responseObject.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}
```
--------------------------------
### Initialize Zoho CRM SDK and Create Records
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
This snippet demonstrates initializing the Zoho CRM JavaScript SDK with OAuth credentials and then creating new records for a specified module. It covers setting standard and custom fields, adding consent details, managing tags, and processing the API response, including detailed handling of success and API exception objects.
```javascript
class CreateRecords {
static async call() {
let environment = DataCenter.US.PRODUCTION();
let token = new OAuthBuilder()
.clientId("clientId")
.scope("scope")
.redirectURL("http://127.0.0.1:5500/redirect.html")
.build();
(await new InitializeBuilder())
.environment(environment)
.token(token)
.initialize();
await GetRecords.createRecords("Leads");
}
static async createRecords(moduleAPIName) {
let recordOperations = new ZCRM.Record.Operations(moduleAPIName);
let request = new ZCRM.Record.Model.BodyWrapper();
let recordsArray = [];
let record = new ZCRM.Record.Model.Record();
record.addFieldValue(ZCRM.Record.Model.Field.Leads.LAST_NAME, "JS SDK");
record.addFieldValue(ZCRM.Record.Model.Field.Leads.FIRST_NAME, "JS");
record.addFieldValue(ZCRM.Record.Model.Field.Leads.COMPANY, "ZCRM");
record.addFieldValue(ZCRM.Record.Model.Field.Leads.CITY, "City");
record.addKeyValue("Custom_field", "Value");
record.addKeyValue("Custom_field_2", "value");
record.addKeyValue("Date_1", new Date(2020, 10, 20));
//Used when GDPR is enabled
let dataConsent = new ZCRM.Record.Model.Consent();
dataConsent.setConsentRemarks("Approved.");
dataConsent.setConsentThrough("Email");
dataConsent.setContactThroughEmail(true);
dataConsent.setContactThroughSocial(false);
record.addKeyValue("Data_Processing_Basis_Details", dataConsent);
let tagsArray = [];
let tag = new ZCRM.Tag.Model.Tag();
tag.setName("Testtask");
tagsArray.push(tag);
record.setTag(tagsArray);
recordsArray.push(record);
request.setData(recordsArray);
let trigger = [];
trigger.push("approval");
trigger.push("workflow");
trigger.push("blueprint");
request.setTrigger(trigger);
let process = ["review_process"];
request.setProcess(process);
let headerInstance = new HeaderMap();
let response = await recordOperations.createRecords(request, headerInstance);
if (response != null) {
console.log("Status Code: " + response.getStatusCode());
let responseObject = response.getObject();
if (responseObject != null) {
if (responseObject instanceof ZCRM.Record.Model.ActionWrapper) {
let actionResponses = responseObject.getData();
actionResponses.forEach(actionResponse => {
if (actionResponse instanceof ZCRM.Record.Model.SuccessResponse) {
console.log("Status: " + actionResponse.getStatus().getValue());
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
let details = actionResponse.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + actionResponse.getMessage().getValue());
}
else if (actionResponse instanceof ZCRM.Record.Model.APIException) {
console.log("Status: " + actionResponse.getStatus().getValue());
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
let details = actionResponse.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + actionResponse.getMessage().getValue());
}
});
}
else if (responseObject instanceof ZCRM.Record.Model.APIException) {
console.log("Status: " + responseObject.getStatus().getValue());
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
let details = responseObject.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}
```
--------------------------------
### Update DOM Element Content
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/samples/create_records_sample/index.html
Shows how to update the inner HTML content of a DOM element identified by its ID. This is a common client-side scripting task for dynamically changing web page content. It relies on the browser's Document Object Model (DOM) API.
```javascript
document.getElementById("method").innerHTML = "Test";
```
--------------------------------
### Include SDK via CDN
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Provides the CDN URL to directly include the Zoho CRM JavaScript SDK v8.0 in your HTML files for web applications.
```javascript
https://static.zohocdn.com/zohocrm/v8.0/sdk/2.0.0/zohocrmsdk-8-0.js
```
--------------------------------
### Update DOM Element Content
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/samples/create_records_sample/index.html
Shows how to update the inner HTML content of a DOM element identified by its ID. This is a common client-side scripting task for dynamically changing web page content. It relies on the browser's Document Object Model (DOM) API.
```javascript
document.getElementById("method").innerHTML = "Test";
```
--------------------------------
### Build Zoho CRM SDK OAuth Token (JavaScript)
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Creates an OAuth token instance using the OAuthBuilder. This requires client ID, scope, and redirect URL obtained after registering your Zoho client.
```JavaScript
/*
* Create a Token instance
* clientId -> OAuth client id.
* scope -> OAuth client scope.
* redirectURL -> OAuth Redirect URL.
*/
let token = new OAuthBuilder()
.clientId("clientId")
.scope("scope")
.redirectURL("redirectURL")
.build();
```
--------------------------------
### Update DOM Element Content
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/create_records_sample/index.html
Shows how to update the inner HTML content of a DOM element identified by its ID. This is a common client-side scripting task for dynamically changing web page content. It relies on the browser's Document Object Model (DOM) API.
```javascript
document.getElementById("method").innerHTML = "Test";
```
--------------------------------
### Build Zoho CRM SDK OAuth Token (JavaScript)
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
Creates an OAuth token instance using the OAuthBuilder. This requires client ID, scope, and redirect URL obtained after registering your Zoho client.
```JavaScript
/*
* Create a Token instance
* clientId -> OAuth client id.
* scope -> OAuth client scope.
* redirectURL -> OAuth Redirect URL.
*/
let token = new OAuthBuilder()
.clientId("clientId")
.scope("scope")
.redirectURL("redirectURL")
.build();
```
--------------------------------
### Create Zoho CRM SDK Logger Instance (JavaScript)
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
Creates an instance of the Logger Class to log exception and API information. The log level can be configured by selecting from the available levels.
```JavaScript
/*
* Create an instance of Logger Class that takes parameter
* 1 -> Level of the log messages to be logged. Can be configured by typing Levels "." and choose any level from the list displayed.
*/
let logger = Logger.getInstance(Levels.ALL);
```
--------------------------------
### Configure Zoho CRM SDK Options (JavaScript)
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Sets up various SDK configuration options including auto-refreshing module fields, cache storage, pick list validation, and request timeout duration.
```JavaScript
/*
* autoRefreshFields
* if true - all the modules' fields will be auto-refreshed in the background, every hour.
* if false - the fields will not be auto-refreshed in the background. The user can manually delete the cache or refresh the fields using methods from ModuleFieldsHandler
*
* cacheStore
* A boolean field that allows or disallows the storage of module field information in cache.
* True - the SDK stores all the modules' field information in cache, and refreshes every hour, if autoRefreshFields is true.
* False - the SDK temporarily stores the modules' field information in a Map.
*
* pickListValidation
* A boolean field that validates user input for a pick list field and allows or disallows the addition of a new value to the list.
* True - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
* False - the SDK does not validate the input and makes the API request with the user’s input to the pick list
*
* timeout
* representing the number of milliseconds a request can take before automatically being terminated.
*/
let sdkConfig = new SDKConfigBuilder()
.autoRefreshFields(true)
.pickListValidation(false)
.cacheStore(true)
.timeout(1000)
.build();
```
--------------------------------
### Configure Zoho CRM SDK Options (JavaScript)
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
Sets up various SDK configuration options including auto-refreshing module fields, cache storage, pick list validation, and request timeout duration.
```JavaScript
/*
* autoRefreshFields
* if true - all the modules' fields will be auto-refreshed in the background, every hour.
* if false - the fields will not be auto-refreshed in the background. The user can manually delete the cache or refresh the fields using methods from ModuleFieldsHandler
*
* cacheStore
* A boolean field that allows or disallows the storage of module field information in cache.
* True - the SDK stores all the modules' field information in cache, and refreshes every hour, if autoRefreshFields is true.
* False - the SDK temporarily stores the modules' field information in a Map.
*
* pickListValidation
* A boolean field that validates user input for a pick list field and allows or disallows the addition of a new value to the list.
* True - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
* False - the SDK does not validate the input and makes the API request with the user’s input to the pick list
*
* timeout
* representing the number of milliseconds a request can take before automatically being terminated.
*/
let sdkConfig = new SDKConfigBuilder()
.autoRefreshFields(true)
.pickListValidation(false)
.cacheStore(true)
.timeout(1000)
.build();
```
--------------------------------
### Create Zoho CRM SDK Logger Instance (JavaScript)
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Creates an instance of the Logger Class to log exception and API information. The log level can be configured by selecting from the available levels.
```JavaScript
/*
* Create an instance of Logger Class that takes parameter
* 1 -> Level of the log messages to be logged. Can be configured by typing Levels "." and choose any level from the list displayed.
*/
let logger = Logger.getInstance(Levels.ALL);
```
--------------------------------
### Backup API Response Structures
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Details the specific response structures for the Backup API. It includes a ResponseHandler interface that can contain either a HistoryWrapper for historical data or a UrlsWrapper for backup URLs, along with APIException for errors.
```APIDOC
Backup API Response Structures:
ResponseHandler: Interface for backup API responses.
HistoryWrapper: Handles application/json responses for backup history.
- Holds a list of History class instances.
- Holds an Info class instance.
UrlsWrapper: Handles application/json responses for backup URLs.
- Holds an instance of Urls class.
APIException: Handles API errors.
```
--------------------------------
### Configure Zoho CRM SDK API Environment (JavaScript)
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
Configures the API environment, which determines the domain and URL for making API calls. Supports various domains like US, EU, IN, CN, AU, CA and environments like PRODUCTION, DEVELOPER, SANDBOX.
```JavaScript
/*
* Configure the environment
* which is of the pattern Domain.Environment
* Available Domains: US, EU, IN, CN, AU, CA
* Available Environments: PRODUCTION(), DEVELOPER(), SANDBOX()
*/
let environment = DataCenter.US.PRODUCTION();
```
--------------------------------
### Including ZOHO CRM JS SDK via CDN
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
The CDN URL provided for directly including the ZOHO CRM JavaScript SDK version 8.0 into your HTML files.
```html
```
--------------------------------
### Backup API Response Structures
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
Details the specific response structures for the Backup API. It includes a ResponseHandler interface that can contain either a HistoryWrapper for historical data or a UrlsWrapper for backup URLs, along with APIException for errors.
```APIDOC
Backup API Response Structures:
ResponseHandler: Interface for backup API responses.
HistoryWrapper: Handles application/json responses for backup history.
- Holds a list of History class instances.
- Holds an Info class instance.
UrlsWrapper: Handles application/json responses for backup URLs.
- Holds an instance of Urls class.
APIException: Handles API errors.
```
--------------------------------
### Configure Zoho CRM SDK API Environment (JavaScript)
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Configures the API environment, which determines the domain and URL for making API calls. Supports various domains like US, EU, IN, CN, AU, CA and environments like PRODUCTION, DEVELOPER, SANDBOX.
```JavaScript
/*
* Configure the environment
* which is of the pattern Domain.Environment
* Available Domains: US, EU, IN, CN, AU, CA
* Available Environments: PRODUCTION(), DEVELOPER(), SANDBOX()
*/
let environment = DataCenter.US.PRODUCTION();
```
--------------------------------
### Download API Response Structure
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/2.0.0/README.md
Describes the response structure for file download operations. It uses a DownloadHandler interface that primarily contains a FileBodyWrapper for the downloaded file content and an APIException for any errors.
```APIDOC
Download API Response Structure:
DownloadHandler: Interface for file download responses.
FileBodyWrapper: Handles file download responses.
APIException: Handles API errors.
```
--------------------------------
### Download API Response Structure
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
Describes the response structure for file download operations. It uses a DownloadHandler interface that primarily contains a FileBodyWrapper for the downloaded file content and an APIException for any errors.
```APIDOC
Download API Response Structure:
DownloadHandler: Interface for file download responses.
FileBodyWrapper: Handles file download responses.
APIException: Handles API errors.
```
--------------------------------
### Handle URL Properties and Set Local Storage
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/create_records_sample/redirect.html
This snippet includes two JavaScript functions: `getPropertiesFromURL` which parses key-value pairs from the URL's hash or search string, and `setAccessToken` which utilizes these properties to store them in `localStorage` and then closes the current browser window. It's commonly used in OAuth redirect flows.
```javascript
function getPropertiesFromURL() {
var props = {};
var propertyString = window.location.hash || window.location.search;
if (propertyString) {
propertyString = (typeof propertyString === 'string') && propertyString.slice(1);
if (propertyString) {
propertyString
.split('&')
.forEach(function (prop) {
var key = prop.split('=')[0],
value = prop.split('=')[1];
props[key] = value;
});
}
}
return props;
}
function setAccessToken() {
var hashProps = getPropertiesFromURL();
if (hashProps) {
for (var key in hashProps) {
if (hashProps.hasOwnProperty(key)) {
var value = (key === 'api_domain') ? decodeURIComponent(hashProps[key]) : hashProps[key];
localStorage.setItem(key, value);
}
}
}
setTimeout(function () {
window.close();
}, 0);
}
setAccessToken();
```
--------------------------------
### Common API Response Structure
Source: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/versions/1.0.0/README.md
Describes the general response handling mechanism used across many Zoho CRM APIs. It includes the base ResponseHandler, ResponseWrapper for JSON data, FileBodyWrapper for file downloads, and APIException for error reporting.
```APIDOC
Common API Response Structure:
ResponseHandler: Base class for handling API responses.
ResponseWrapper: Handles application/json responses.
FileBodyWrapper: Handles file download responses.
APIException: Handles API errors.
```