ASP.NET MVC

How To Create User Using Zoho CRM In ASP.NET MVC

Introduction

In this article, we will learn how to create a User using Zoho CRM in ASP.NET MVC Web application.

Let’s begin

Please read this article first of all here.

C# Code Example

Open the HomeController.cs file and add the below code in it.

public Void CreateUser()
  {
      
          ZCRMUser user = ZCRMUser.GetInstance("Enter Last Name", "Enter Email Address"); //last_name and email of the user
          ZCRMOrganization OrgInstance = ZCRMRestClient.GetInstance().GetOrganizationInstance();
          user.Country = "US";
          long roleData = Convert.ToInt64(GetRoles());
          user.Role = ZCRMRole.GetInstance(roleData, "Manager");
          user.CountryLocale = "en_US";
          user.FirstName = "Enter First Name";
          long profileData = Convert.ToInt64(GetProfiles());
          user.Profile = ZCRMProfile.GetInstance(profileData, "Standard");
          user.DateOfBirth = "1998-12-25";
          user.DateFormat = "06/16/2020";

          user.SetFieldValue("FieldApiName", "FieldValue");
          APIResponse response = OrgInstance.CreateUser(user);

         
   }

  public string GetRoles()
  {
      string roleid = string.Empty;
      try
      {
          ZCRMRestClient restClient = ZCRMRestClient.GetInstance();
          BulkAPIResponse<ZCRMRole> response = restClient.GetOrganizationInstance().GetAllRoles();
          List<ZCRMRole> roles = response.BulkData;
          roleid = Convert.ToString(roles[1].Id);
      }
      catch (Exception ex)
      {

          roleid = "";
      }
      return roleid;
  }

  public string GetProfiles()
  {
      string profileid = string.Empty;
      try
      {
          ZCRMRestClient restClient = ZCRMRestClient.GetInstance();
          BulkAPIResponse<ZCRMProfile> response = restClient.GetOrganizationInstance().GetAllProfiles();
          List<ZCRMProfile> roles = response.BulkData;
          profileid = Convert.ToString(roles[1].Id);
      }
      catch (Exception ex)
      {

          profileid = "";
      }
      return profileid;
  }

 

Get All Users Data

public List<ZCRMUser> GetZohoUsers()
 {
     List<ZCRMUser> result = new List<ZCRMUser>();
     try
     {
         ZCRMRestClient restClient = ZCRMRestClient.GetInstance();
         BulkAPIResponse<ZCRMUser> response = restClient.GetOrganizationInstance().GetAllUsers();
         if (response.HttpStatusCode == ResponseCode.OK)
         {
             List<ZCRMUser> allUsers = response.BulkData; //response - list of ZCRMUser instances


         }


         return result;
     }
     catch (Exception ex)
     {
         return result;
     }
 }

 

Update User

public Void UpdateUser()
  {
    
          ZCRMUser user = ZCRMUser.GetInstance(Enter User Id);//user id
          ZCRMOrganization OrgInstance = ZCRMRestClient.GetInstance().GetOrganizationInstance();
          user.Country = "US";
          long roleData = Convert.ToInt64(GetRoles());
          user.Role = ZCRMRole.GetInstance(roleData, "Manager");
          user.City = "Chennai";
          user.Street = "street";
          user.Alias = "alias";
          user.State = "state";
          user.Fax = "fax";
          user.CountryLocale = "en_US";
          user.FirstName = "Your First Name";
          user.Zip = "39500";
          user.Website = "https://www.zoho.com";
          long profileData = Convert.ToInt64(GetProfiles());
          user.Profile = ZCRMProfile.GetInstance(profileData, "Standard");
          user.Mobile = "Your Mobile No";
          user.Phone = "Your Phone no";
          user.DateOfBirth = "1995-05-05";
          user.DateFormat = "06/17/2020";

          //user.SetFieldValue("FieldApiName", "FieldApiValue");
          APIResponse response = OrgInstance.UpdateUser(user);
         
      
      
  }

 

Delete User

public void DeleteUser()
{
        ZCRMOrganization OrgInstance = ZCRMRestClient.GetInstance().GetOrganizationInstance();
        APIResponse response = OrgInstance.DeleteUser(Enter User Id); //user ID

 }

 

if you have any questions or issues about this article, please let me know and more details here.

Sagar Rana

Sagar Rana is a Web Developer in Vision Infotech. He has strong skills and knowledge of ASP.NET C#, ASP.NET MVC, .Net Core, Jquery, JavaScript, WEB API, React.js, ADO.Net, Entity Framework, SQL and different integration like Xero, Stripe, Zoho CRM, Square, PayTM, PayKUN, RazorPay, Quickbook Desktop etc.

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago