Node JS SDK Samples - Profile Operations
Get All Profiles
const ProfilesOperations = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/profiles/profiles_operations").ProfilesOperations;
const ResponseWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/profiles/response_wrapper").ResponseWrapper;
const APIException = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/profiles/api_exception").APIException;
class Profile{
/**
* Get Profiles
* This method is used to retrieve the profiles data through an API request and print the response.
*/
static async getProfiles(){
//Get instance of ProfilesOperations Class that takes If-Modified-Since header as parameter.
//To include If-Modified-Since header in the request, get the instance as follows
let profilesOperations = new ProfilesOperations(new Date(2020,9,1,12,12,12));
//To not include If-Modified-Since header to the request, get the instance as follows
// profilesOperations = new ProfilesOperations();
//Call getProfiles method
let response = await profilesOperations.getProfiles();
if(response != null){
//Get the status code from response
console.log("Status Code: " + response.statusCode);
if([204, 304].includes(response.statusCode)){
console.log(response.statusCode == 204? "No Content" : "Not Modified");
return;
}
//Get object from response
let responseObject = response.object;
if(responseObject != null){
if(responseObject instanceof ResponseWrapper){
let profiles = responseObject.getProfiles();
profiles.forEach(profile => {
//Get the DisplayLabel of the each Profile
console.log("Profile DisplayLabel: " + profile.getDisplayLabel());
if(profile.getCreatedTime() != null){
//Get the CreatedTime of each Profile
console.log("Profile CreatedTime: " + profile.getCreatedTime());
}
if(profile.getModifiedTime() != null){
//Get the ModifiedTime of each Profile
console.log("Profile ModifiedTime: " + profile.getModifiedTime());
}
//Get the Name of the each Profile
console.log("Profile Name: " + profile.getName());
//Get the modifiedBy User instance of each Profile
let modifiedBy = profile.getModifiedBy();
//Check if modifiedBy is not null
if(modifiedBy != null){
//Get the ID of the modifiedBy User
console.log("Profile Modified By User-ID: " + modifiedBy.getId());
//Get the name of the modifiedBy User
console.log("Profile Modified By User-Name: " + modifiedBy.getName());
//Get the Email of the modifiedBy User
console.log("Profile Modified By User-Email: " + modifiedBy.getEmail());
}
//Get the Description of the each Profile
console.log("Profile Description: " + profile.getDescription());
//Get the ID of the each Profile
console.log("Profile ID: " + profile.getId());
//Get the Category of the each Profile
console.log("Profile Category: " + profile.getCategory().toString());
//Get the createdBy User instance of each Profile
let createdBy = profile.getCreatedBy();
//Check if createdBy is not null
if(createdBy != null){
//Get the ID of the createdBy User
console.log("Profile Created By User-ID: " + createdBy.getId());
//Get the name of the createdBy User
console.log("Profile Created By User-Name: " + createdBy.getName());
//Get the Email of the createdBy User
console.log("Profile Created By User-Email: " + createdBy.getEmail());
}
});
}
//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());
}
}
}
}
}
module.exports = {Profile}
Get Specific Profile