Scala SDK Samples - Users Operations

Get Users
              
              
package com.zoho.crm.sample.users

import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.roles.Role
import com.zoho.crm.api.users.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, CustomizeInfo, Info, RequestWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, TabTheme, Territory, Theme, User, UsersOperations}
import com.zoho.crm.api.users.UsersOperations.GetUsersHeader
import com.zoho.crm.api.users.UsersOperations.GetUsersParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Users {
	/**
   *  Get Users 
   * This method is used to retrieve the users data specified in the API request.
   * You can specify the type of users that needs to be retrieved using the Users API.
   *
   * @throws Exception
   */
  @throws[Exception]
  def getUsers(): Unit = { //Get instance of UsersOperations Class
    val usersOperations = new UsersOperations
    //Get instance of ParameterMap Class
    val paramInstance = new ParameterMap
    paramInstance.add(new GetUsersParam().type1, "ActiveUsers")
    paramInstance.add(new GetUsersParam().page, 1)
    //paramInstance.add(GetUsersParam.PER_PAGE, 1)
    val headerInstance = new HeaderMap
    val ifmodifiedsince = OffsetDateTime.of(2019, 1, 2, 1, 0, 1, 0, ZoneOffset.of("+05:30"))
    headerInstance.add(new GetUsersHeader().IfModifiedSince, ifmodifiedsince)
    //Call getUsers method that takes ParameterMap instance and HeaderMap instance as parameters
    val responseOption = usersOperations.getUsers(Option(paramInstance), Option(headerInstance))
    if (responseOption.isDefined) { //check response
      var response= responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (util.Arrays.asList(204, 304).contains(response.getStatusCode)) {
        println(if (response.getStatusCode == 204) "No Content"
        else "Not Modified")
        return
      }
      //Check if expected response is received
      if (response.isExpected) { //Get object from response
        val responseHandler = response.getObject
        if (responseHandler.isInstanceOf[ResponseWrapper]) { //Get the received ResponseWrapper instance
          val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
          //Get the list of obtained User instances
          val users:ArrayBuffer[User] = responseWrapper.getUsers
          for (user {
              println(entry._1 + ": " + entry._2)
            })
            //Get the Message
            println("Message: " + exception.getMessage.getValue)
          }
        }
      }
      else { //If response is not as expected
        //Get model object from response
        val responseObject = response.getModel
        //Get the response object's class
        val clas = responseObject.getClass
        //Get all declared fields of the response class
        val fields = clas.getDeclaredFields
        for (field 
Add User
              
              
package com.zoho.crm.sample.users

import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.roles.Role
import com.zoho.crm.api.users.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, CustomizeInfo, Info, RequestWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, TabTheme, Territory, Theme, User, UsersOperations}
import com.zoho.crm.api.users.UsersOperations.GetUsersHeader
import com.zoho.crm.api.users.UsersOperations.GetUsersParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Users {
	/**
   *  Create Users 
   * This method is used to add a user to your organization and print the response.
   *
   * @throws Exception
   */
  @throws[Exception]
  def createUser(): Unit = {
    val usersOperations = new UsersOperations
    //Get instance of BodyWrapper Class that will contain the request body
    val request = new RequestWrapper
    //List of User instances
    val userList = new ArrayBuffer[User]
    //Get instance of User Class
    val user1 = new User
    val role = new Role
    role.setId(Option(3524026005l))
    user1.setRole(Option(role))
    user1.setFirstName(Option("TestUser"))
    user1.setEmail(Option("testuser112@zoho.com"))
    val profile = new Profile
    profile.setId(Option(352406011l))
    user1.setProfile(Option(profile))
    user1.setLastName(Option("TestUser LastName"))
    userList.addOne(user1)
    request.setUsers(userList)
    //Call createUser method that takes BodyWrapper class instance as parameter
    val responseOption = usersOperations.createUser(request)
    if (responseOption.isDefined) { //check response
      var response= responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (response.isExpected) {
        val actionHandler = response.getObject
        if (actionHandler.isInstanceOf[ActionWrapper]) { //Get the received ActionWrapper instance
          val responseWrapper = actionHandler.asInstanceOf[ActionWrapper]
          //Get the list of obtained ActionResponse instances
          val actionResponses = responseWrapper.getUsers
          for (actionResponse {
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + successResponse.getMessage.getValue)
            }
            else if (actionResponse.isInstanceOf[APIException]) {
              val exception = actionResponse.asInstanceOf[APIException]
              println("Status: " + exception.getStatus.getValue)
              println("Code: " + exception.getCode.getValue)
              println("Details: ")
              exception.getDetails.foreach(entry=>{
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + exception.getMessage.getValue)
            }
          }
        }
        else if (actionHandler.isInstanceOf[APIException]) {
          val exception = actionHandler.asInstanceOf[APIException]
          println("Status: " + exception.getStatus.getValue)
          println("Code: " + exception.getCode.getValue)
          println("Details: ")
          exception.getDetails.foreach(entry=>{
            println(entry._1 + ": " + entry._2)
          })
          println("Message: " + exception.getMessage.getValue)
        }
      }
      else {
        val responseObject = response.getModel
        val clas = responseObject.getClass
        val fields = clas.getDeclaredFields
        for (field 
Update Users
              
              
package com.zoho.crm.sample.users

import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.roles.Role
import com.zoho.crm.api.users.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, CustomizeInfo, Info, RequestWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, TabTheme, Territory, Theme, User, UsersOperations}
import com.zoho.crm.api.users.UsersOperations.GetUsersHeader
import com.zoho.crm.api.users.UsersOperations.GetUsersParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer

object Users {
	/**
   *  Update Users 
   * This method is used to update the details of multiple users of your organization and print the response.
   *
   * @throws Exception
   */
  @throws[Exception]
  def updateUsers(): Unit = {
    val usersOperations = new UsersOperations
    val request = new BodyWrapper
    val userList = new ArrayBuffer[User]
    var user1 = new User
    user1.setId(Option(35240391017l))
    var role = new Role
    role.setId(Option(352403326005l))
    user1.setRole(Option(role))
    user1.setCountryLocale(Option("en_US"))
    userList.addOne(user1)
    user1 = new User
    user1.setId(Option(3477061000005791024l))
    role = new Role
    role.setId(Option(3524033000000191017l))
    user1.setRole(Option(role))
    user1.setCountryLocale(Option("en_US"))
    //		user1.addKeyValue(apiName, value)
    userList.addOne(user1)
    request.setUsers(userList)
    //Call updateUsers method that takes BodyWrapper instance as parameter
    val responseOption = usersOperations.updateUsers(request)
    if (responseOption.isDefined) { //check response
      var response= responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (response.isExpected) {
        val actionHandler = response.getObject
        if (actionHandler.isInstanceOf[ActionWrapper]) {
          val responseWrapper = actionHandler.asInstanceOf[ActionWrapper]
          val actionResponses = responseWrapper.getUsers
          for (actionResponse {
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + successResponse.getMessage.getValue)
            }
            else if (actionResponse.isInstanceOf[APIException]) {
              val exception = actionResponse.asInstanceOf[APIException]
              println("Status: " + exception.getStatus.getValue)
              println("Code: " + exception.getCode.getValue)
              println("Details: ")
              exception.getDetails.foreach(entry=>{
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + exception.getMessage.getValue)
            }
          }
        }
        else if (actionHandler.isInstanceOf[APIException]) {
          val exception = actionHandler.asInstanceOf[APIException]
          println("Status: " + exception.getStatus.getValue)
          println("Code: " + exception.getCode.getValue)
          println("Details: ")
          exception.getDetails.foreach(entry=>{
            println(entry._1 + ": " + entry._2)
          })
          println("Message: " + exception.getMessage.getValue)
        }
      }
      else {
        val responseObject = response.getModel
        val clas = responseObject.getClass
        val fields = clas.getDeclaredFields
        for (field 
Get a User
              
              
package com.zoho.crm.sample.users

import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.roles.Role
import com.zoho.crm.api.users.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, CustomizeInfo, Info, RequestWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, TabTheme, Territory, Theme, User, UsersOperations}
import com.zoho.crm.api.users.UsersOperations.GetUsersHeader
import com.zoho.crm.api.users.UsersOperations.GetUsersParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Users {
	/**
   *  Get User 
   * This method is used to get the details of any specific user.
   * Specify the unique id of the user in your API request to get the data for that particular user.
   *
   * @param userId - The ID of the User to be obtained
   * @throws Exception
   */
  @throws[Exception]
  def getUser(userId: Long): Unit = { //example
    //Long userId = 3477065817002L
    val usersOperations = new UsersOperations
    val headerInstance = new HeaderMap
    val ifmodifiedsince = OffsetDateTime.of(2019, 1, 2, 1, 0, 1, 0, ZoneOffset.of("+05:30"))
    headerInstance.add(new GetUsersHeader().IfModifiedSince, ifmodifiedsince)
    //Call getUser method that takes userId as parameter
    val responseOption = usersOperations.getUser(userId,Option(headerInstance))
    if (responseOption.isDefined) { //check response
      var response= responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (util.Arrays.asList(204, 304).contains(response.getStatusCode)) {
        println(if (response.getStatusCode == 204) "No Content"
        else "Not Modified")
        return
      }
      if (response.isExpected) {
        val responseHandler = response.getObject
        if (responseHandler.isInstanceOf[ResponseWrapper]) {
          val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
          //Get the obtained User instance
          val users = responseWrapper.getUsers
          for (user {
            println(entry._1 + ": " + entry._2)
          })
          println("Message: " + exception.getMessage.getValue)
        }
      }
      else {
        val responseObject = response.getModel
        val clas = responseObject.getClass
        val fields = clas.getDeclaredFields
        for (field 
Update a User
              
              
package com.zoho.crm.sample.users

import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.roles.Role
import com.zoho.crm.api.users.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, CustomizeInfo, Info, RequestWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, TabTheme, Territory, Theme, User, UsersOperations}
import com.zoho.crm.api.users.UsersOperations.GetUsersHeader
import com.zoho.crm.api.users.UsersOperations.GetUsersParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Users {
	/**
   *  Update User 
   * This method is used to update the details of a user of your organization and print the response.
   *
   * @param userId - The ID of the User to be updated
   * @throws Exception
   */
  @throws[Exception]
  def updateUser(userId: Long): Unit = {
    val usersOperations = new UsersOperations
    val request = new BodyWrapper
    val userList = new ArrayBuffer[User]
    val user1 = new User
    val role = new Role
    role.setId(Option(352400026005l))
    user1.setRole(Option(role))
    user1.setCountryLocale(Option("en_US"))
    userList.addOne(user1)
    request.setUsers(userList)
    //Call updateUser method that takes BodyWrapper instance and userId as parameter
    val responseOption = usersOperations.updateUser(userId,request)
    if (responseOption.isDefined) { //check response
      var response= responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (response.isExpected) {
        val actionHandler = response.getObject
        if (actionHandler.isInstanceOf[ActionWrapper]) {
          val responseWrapper = actionHandler.asInstanceOf[ActionWrapper]
          val actionResponses = responseWrapper.getUsers
          for (actionResponse {
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + successResponse.getMessage.getValue)
            }
            else if (actionResponse.isInstanceOf[APIException]) {
              val exception = actionResponse.asInstanceOf[APIException]
              println("Status: " + exception.getStatus.getValue)
              println("Code: " + exception.getCode.getValue)
              println("Details: ")
              exception.getDetails.foreach(entry=>{
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + exception.getMessage.getValue)
            }
          }
        }
        else if (actionHandler.isInstanceOf[APIException]) {
          val exception = actionHandler.asInstanceOf[APIException]
          println("Status: " + exception.getStatus.getValue)
          println("Code: " + exception.getCode.getValue)
          println("Details: ")
          exception.getDetails.foreach(entry=>{
            println(entry._1 + ": " + entry._2)
          })
          println("Message: " + exception.getMessage.getValue)
        }
      }
      else {
        val responseObject = response.getModel
        val clas = responseObject.getClass
        val fields = clas.getDeclaredFields
        for (field 
Delete a User
              
              
package com.zoho.crm.sample.users

import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util

import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.roles.Role
import com.zoho.crm.api.users.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, CustomizeInfo, Info, RequestWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, TabTheme, Territory, Theme, User, UsersOperations}
import com.zoho.crm.api.users.UsersOperations.GetUsersHeader
import com.zoho.crm.api.users.UsersOperations.GetUsersParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model

import scala.collection.mutable.ArrayBuffer


object Users {
	/**
   *  Delete User 
   * This method is used to delete a user from your organization and print the response.
   *
   * @param userId - The ID of the User to be deleted
   * @throws Exception
   */
  @throws[Exception]
  def deleteUser(userId: Long): Unit = {
    val usersOperations = new UsersOperations
    //Call deleteUser method that takes userId as parameter
    val responseOption = usersOperations.deleteUser(userId)
    if (responseOption.isDefined) { //check response
      var response= responseOption.get
      println("Status Code: " + response.getStatusCode)
      if (response.isExpected) {
        val actionHandler = response.getObject
        if (actionHandler.isInstanceOf[ActionWrapper]) {
          val responseWrapper = actionHandler.asInstanceOf[ActionWrapper]
          val actionResponses = responseWrapper.getUsers
          for (actionResponse {
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + successResponse.getMessage.getValue)
            }
            else if (actionResponse.isInstanceOf[APIException]) {
              val exception = actionResponse.asInstanceOf[APIException]
              println("Status: " + exception.getStatus.getValue)
              println("Code: " + exception.getCode.getValue)
              println("Details: ")
              exception.getDetails.foreach(entry=>{
                println(entry._1 + ": " + entry._2)
              })
              println("Message: " + exception.getMessage.getValue)
            }
          }
        }
        else if (actionHandler.isInstanceOf[APIException]) {
          val exception = actionHandler.asInstanceOf[APIException]
          println("Status: " + exception.getStatus.getValue)
          println("Code: " + exception.getCode.getValue)
          println("Details: ")
          exception.getDetails.foreach(entry=>{
            println(entry._1 + ": " + entry._2)
          })
          println("Message: " + exception.getMessage.getValue)
        }
      }
      else {
        val responseObject = response.getModel
        val clas = responseObject.getClass
        val fields = clas.getDeclaredFields
        for (field