TypeScript SDK Samples - Contact Roles Operations
Get Contact Roles
import {ContactRolesOperations, DeleteContactRolesParam} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_roles_operations";
import {ActionHandler} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_handler";
import { ActionResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_response";
import {SuccessResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/success_response";
import {ActionWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_wrapper";
import {APIException} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/api_exception";
import {BodyWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/body_wrapper";
import { APIResponse } from "@zohocrm/typescript-sdk-2.0/routes/controllers/api_response";
import { ResponseHandler } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_handler";
import { ResponseWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_wrapper";
import { ContactRole } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_role";
import { ParameterMap } from "@zohocrm/typescript-sdk-2.0/routes/parameter_map";
export class ContactRoles{
/**
* Get Contact Roles
* This method is used to get all the Contact Roles and print the response.
*/
public static async getContactRoles(){
//Get instance of ContactRolesOperations Class
let contactRolesOperations: ContactRolesOperations = new ContactRolesOperations();
//Call getContactRoles method
let response: APIResponse<ResponseHandler> = await contactRolesOperations.getContactRoles();
if(response !== null){
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
if([204, 304].includes(response.getStatusCode())){
console.log(response.getStatusCode() == 204? "No Content" : "Not Modified");
return;
}
//Get object from response
let responseObject: ResponseHandler = response.getObject();
if(responseObject !== null){
//Check if expected ResponseWrapper instance is received
if(responseObject instanceof ResponseWrapper){
//Get the array of obtained ContactRole instances
let contactRoles: ContactRole[] = responseObject.getContactRoles();
contactRoles.forEach(contactRole => {
//Get the ID of each ContactRole
console.log("ContactRole ID: " + contactRole.getId());
//Get the name of each ContactRole
console.log("ContactRole Name: " + contactRole.getName());
//Get the sequence number of each ContactRole
console.log("ContactRole SequenceNumber: " + contactRole.getSequenceNumber());
});
}
//Check if the request returned an exception
else if(responseObject instanceof APIException){
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = responseObject.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}
Create Contact Roles
import {ContactRolesOperations, DeleteContactRolesParam} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_roles_operations";
import {ActionHandler} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_handler";
import { ActionResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_response";
import {SuccessResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/success_response";
import {ActionWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_wrapper";
import {APIException} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/api_exception";
import {BodyWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/body_wrapper";
import { APIResponse } from "@zohocrm/typescript-sdk-2.0/routes/controllers/api_response";
import { ResponseHandler } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_handler";
import { ResponseWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_wrapper";
import { ContactRole } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_role";
import { ParameterMap } from "@zohocrm/typescript-sdk-2.0/routes/parameter_map";
export class ContactRoles{
/**
* Create Contact Roles
* This method is used to create Contact Roles and print the response.
*/
public static async createContactRoles(){
//Get instance of ContactRolesOperations Class
let contactRolesOperations: ContactRolesOperations = new ContactRolesOperations();
//Get instance of BodyWrapper Class that will contain the request body
let request: BodyWrapper = new BodyWrapper();
//Array to hold ContactRole instances
let contactRolesArray: ContactRole[] = [];
for (let index = 0; index < 5; index++) {
//Get instance of ContactRole Class
let contactRole: ContactRole = new ContactRole();
//Set name of the Contact Role
contactRole.setName("contactRole-ts" + index.toString());
//Set sequence number of the Contact Role
contactRole.setSequenceNumber(index+1);
//Add ContactRole instance to the array
contactRolesArray.push(contactRole);
}
//Set the array of contactRoles in BodyWrapper instance
request.setContactRoles(contactRolesArray);
//Call createContactRoles method that takes BodyWrapper instance as parameter
let response: APIResponse<ActionHandler> = await contactRolesOperations.createContactRoles(request);
if(response !== null){
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
//Get object from response
let responseObject: ActionHandler = response.getObject();
if(responseObject !== null){
//Check if expected ActionWrapper instance is received
if(responseObject instanceof ActionWrapper){
//Get the array of obtained ActionResponse instances
let actionResponses: ActionResponse[] = responseObject.getContactRoles();
actionResponses.forEach(actionResponse => {
//Check if the request is successful
if(actionResponse instanceof SuccessResponse){
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = actionResponse.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + actionResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if(actionResponse instanceof APIException){
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details = actionResponse.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + actionResponse.getMessage().getValue());
}
});
}
//Check if the request returned an exception
else if(responseObject instanceof APIException){
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
//Get the details map
let details = responseObject.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}
Update Contact Roles
import {ContactRolesOperations, DeleteContactRolesParam} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_roles_operations";
import {ActionHandler} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_handler";
import { ActionResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_response";
import {SuccessResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/success_response";
import {ActionWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_wrapper";
import {APIException} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/api_exception";
import {BodyWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/body_wrapper";
import { APIResponse } from "@zohocrm/typescript-sdk-2.0/routes/controllers/api_response";
import { ResponseHandler } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_handler";
import { ResponseWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_wrapper";
import { ContactRole } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_role";
import { ParameterMap } from "@zohocrm/typescript-sdk-2.0/routes/parameter_map";
export class ContactRoles{
/**
* Update Contact Roles
* This method is used to update Contact Roles and print the response.
*/
public static async updateContactRoles(){
//Get instance of ContactRolesOperations Class
let contactRolesOperations: ContactRolesOperations = new ContactRolesOperations();
//Get instance of BodyWrapper Class that will contain the request body
let request: BodyWrapper = new BodyWrapper();
//Array to hold ContactRole instances
let contactRolesArray: ContactRole[] = [];
//Get instance of ContactRole Class
let cr1: ContactRole = new ContactRole();
//Set ID to the ContactRole instance
cr1.setId(BigInt("34770619185001"));
//Set name to the ContactRole instance
cr1.setName("Edited1");
//Add ContactRole instance to the array
contactRolesArray.push(cr1);
//Get instance of ContactRole Class
cr1 = new ContactRole();
//Set ID to the ContactRole instance
cr1.setId(BigInt("34096431794001"));
//Set name to the ContactRole instance
cr1.setName("Edited12");
//Add ContactRole instance to the array
contactRolesArray.push(cr1);
//Set the array to contactRoles in BodyWrapper instance
request.setContactRoles(contactRolesArray);
//Call updateContactRoles method that takes BodyWrapper instance as parameter
let response: APIResponse<ActionHandler> = await contactRolesOperations.updateContactRoles(request);
if(response !== null){
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
//Get object from response
let responseObject: ActionHandler = response.getObject();
if(responseObject !== null){
//Check if expected ActionWrapper instance is received
if(responseObject instanceof ActionWrapper){
//Get the array of obtained ActionResponse instances
let actionResponses: ActionResponse[] = responseObject.getContactRoles();
actionResponses.forEach(actionResponse => {
//Check if the request is successful
if(actionResponse instanceof SuccessResponse){
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = actionResponse.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + actionResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if(actionResponse instanceof APIException){
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = actionResponse.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + actionResponse.getMessage().getValue());
}
});
}
//Check if the request returned an exception
else if(responseObject instanceof APIException){
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = responseObject.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}
Delete Contact Roles
import {ContactRolesOperations, DeleteContactRolesParam} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_roles_operations";
import {ActionHandler} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_handler";
import { ActionResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_response";
import {SuccessResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/success_response";
import {ActionWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_wrapper";
import {APIException} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/api_exception";
import {BodyWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/body_wrapper";
import { APIResponse } from "@zohocrm/typescript-sdk-2.0/routes/controllers/api_response";
import { ResponseHandler } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_handler";
import { ResponseWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_wrapper";
import { ContactRole } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_role";
import { ParameterMap } from "@zohocrm/typescript-sdk-2.0/routes/parameter_map";
export class ContactRoles{
/**
* <h3> Delete Contact Roles </h3>
* This method is used to delete Contact Roles and print the response.
* @param contactRoleIds The array of ContactRole IDs to be deleted.
*/
public static async deleteContactRoles(contactRoleIds: bigint[]){
//example
//let contactRoleIds = [34096432157002n, 34096431619001n, 34096430006883n];
//Get instance of ContactRolesOperations Class
let contactRolesOperations: ContactRolesOperations = new ContactRolesOperations();
//Get instance of ParameterMap Class
let paramInstance: ParameterMap = new ParameterMap();
//Add ids to ParameterMap instance
for(let contactRoleId of contactRoleIds) {
await paramInstance.add(DeleteContactRolesParam.IDS, contactRoleId);
}
//Call deleteContactRoles method that takes paramInstance as parameter
let response: APIResponse<ActionHandler> = await contactRolesOperations.deleteContactRoles(paramInstance);
if(response !== null){
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
//Get object from response
let responseObject: ActionHandler = response.getObject();
if(responseObject !== null){
//Check if expected ActionWrapper instance is received
if(responseObject instanceof ActionWrapper){
//Get the array of obtained ActionResponse instances
let actionResponses: ActionResponse[] = responseObject.getContactRoles();
actionResponses.forEach(actionResponse => {
//Check if the request is successful
if(actionResponse instanceof SuccessResponse){
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = actionResponse.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + actionResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if(actionResponse instanceof APIException){
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = actionResponse.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + actionResponse.getMessage().getValue());
}
});
}
//Check if the request returned an exception
else if(responseObject instanceof APIException){
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = responseObject.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}
Get a Contact Role
import {ContactRolesOperations, DeleteContactRolesParam} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_roles_operations";
import {ActionHandler} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_handler";
import { ActionResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_response";
import {SuccessResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/success_response";
import {ActionWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_wrapper";
import {APIException} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/api_exception";
import {BodyWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/body_wrapper";
import { APIResponse } from "@zohocrm/typescript-sdk-2.0/routes/controllers/api_response";
import { ResponseHandler } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_handler";
import { ResponseWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_wrapper";
import { ContactRole } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_role";
import { ParameterMap } from "@zohocrm/typescript-sdk-2.0/routes/parameter_map";
export class ContactRoles{
/**
* Get Contact Role
* This method is used to get single Contact Role with ID and print the response.
* @param contactRoleId The ID of the ContactRole to be obtained
*/
public static async getContactRole(contactRoleId: bigint){
//example
//let contactRoleId = 34096432212003n;
//Get instance of ContactRolesOperations Class
let contactRolesOperations: ContactRolesOperations = new ContactRolesOperations();
//Call getContactRole method that takes contactRoleId as parameter
let response: APIResponse<ResponseHandler> = await contactRolesOperations.getContactRole(contactRoleId);
if(response !== null){
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
if([204, 304].includes(response.getStatusCode())){
console.log(response.getStatusCode() == 204? "No Content" : "Not Modified");
return;
}
//Get object from response
let responseObject = response.getObject();
if(responseObject !== null){
//Check if expected ResponseWrapper instance is received
if(responseObject instanceof ResponseWrapper){
//Get the array of obtained ContactRole instances
let contactRoles: ContactRole[] = responseObject.getContactRoles();
contactRoles.forEach(contactRole => {
//Get the ID of each ContactRole
console.log("ContactRole ID: " + contactRole.getId());
//Get the name of each ContactRole
console.log("ContactRole Name: " + contactRole.getName());
//Get the sequence number of each ContactRole
console.log("ContactRole SequenceNumber: " + contactRole.getSequenceNumber());
});
}
//Check if the request returned an exception
else if(responseObject instanceof APIException){
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = responseObject.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}
Update a Contact Role
import {ContactRolesOperations, DeleteContactRolesParam} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_roles_operations";
import {ActionHandler} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_handler";
import { ActionResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_response";
import {SuccessResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/success_response";
import {ActionWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_wrapper";
import {APIException} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/api_exception";
import {BodyWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/body_wrapper";
import { APIResponse } from "@zohocrm/typescript-sdk-2.0/routes/controllers/api_response";
import { ResponseHandler } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_handler";
import { ResponseWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_wrapper";
import { ContactRole } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_role";
import { ParameterMap } from "@zohocrm/typescript-sdk-2.0/routes/parameter_map";
export class ContactRoles{
/**
* Update Contact Role
* This method is used to update single Contact Role with ID and print the response.
* @param contactRoleId The ID of the ContactRole to be updated
*/
public static async updateContactRole(contactRoleId: bigint){
//example
//let contactRoleId = 34096432212003n;
//Get instance of ContactRolesOperations Class
let contactRolesOperations: ContactRolesOperations = new ContactRolesOperations();
//Get instance of BodyWrapper Class that will contain the request body
let request: BodyWrapper = new BodyWrapper();
//Array to hold ContactRole instances
let contactRolesArray: ContactRole[] = [];
//Get instance of ContactRole Class
let cr1: ContactRole = new ContactRole();
//Set sequence number to the ContactRole instance
cr1.setName("Edited-cr");
//Add ContactRole instance to the array
contactRolesArray.push(cr1);
//Set the array to contactRoles in BodyWrapper instance
request.setContactRoles(contactRolesArray);
//Call updateContactRole method that takes BodyWrapper instance and contactRoleId as parameters
let response: APIResponse<ActionHandler> = await contactRolesOperations.updateContactRole(contactRoleId, request);
if(response !== null){
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
//Get object from response
let responseObject: ActionHandler = response.getObject();
if(responseObject !== null){
//Check if expected ActionWrapper instance is received
if(responseObject instanceof ActionWrapper){
//Get the array of obtained ActionResponse instances
let actionResponses: ActionResponse[] = responseObject.getContactRoles();
actionResponses.forEach(actionResponse => {
//Check if the request is successful
if(actionResponse instanceof SuccessResponse){
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = actionResponse.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + actionResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if(actionResponse instanceof APIException){
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = actionResponse.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + actionResponse.getMessage().getValue());
}
});
}
//Check if the request returned an exception
else if(responseObject instanceof APIException){
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = responseObject.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}
Delete a Contact Role
import {ContactRolesOperations, DeleteContactRolesParam} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_roles_operations";
import {ActionHandler} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_handler";
import { ActionResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_response";
import {SuccessResponse} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/success_response";
import {ActionWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/action_wrapper";
import {APIException} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/api_exception";
import {BodyWrapper} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/body_wrapper";
import { APIResponse } from "@zohocrm/typescript-sdk-2.0/routes/controllers/api_response";
import { ResponseHandler } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_handler";
import { ResponseWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/response_wrapper";
import { ContactRole } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/contact_roles/contact_role";
import { ParameterMap } from "@zohocrm/typescript-sdk-2.0/routes/parameter_map";
export class ContactRoles{
/**
* Delete Contact Role
* This method is used to delete single Contact Role with ID and print the response.
* @param contactRoleId ID of the ContactRole to be deleted
*/
public static async deleteContactRole(contactRoleId: bigint){
//example
//let contactRoleId = 34096432212003n;
//Get instance of ContactRolesOperations Class
let contactRolesOperations: ContactRolesOperations = new ContactRolesOperations();
//Call deleteContactRole which takes contactRoleId as parameter
let response: APIResponse<ActionHandler> = await contactRolesOperations.deleteContactRole(contactRoleId);
if(response !== null){
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
//Get object from response
let responseObject: ActionHandler = response.getObject();
if(responseObject !== null){
//Check if expected ActionWrapper instance is received
if(responseObject instanceof ActionWrapper){
//Get the array of obtained ActionResponse instances
let actionResponses: ActionResponse[] = responseObject.getContactRoles();
actionResponses.forEach(actionResponse => {
//Check if the request is successful
if(actionResponse instanceof SuccessResponse){
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = actionResponse.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + actionResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if(actionResponse instanceof APIException){
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = actionResponse.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + actionResponse.getMessage().getValue());
}
});
}
//Check if the request returned an exception
else if(responseObject instanceof APIException){
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string,any> = responseObject.getDetails();
if(details !== null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}