Skip to main content

Configuration

Before you get started with creating your C# application, you need to register your client and authenticate the app with Zoho.

Mandatory KeysOptional Keys
UserLogger
Environmentstore
TokenSDKConfig
 RequestProxy
 ResourcePath

Follow the below steps to configure the SDK.

  1. Create an instance of the Logger Class to log exception and API information. By default, the SDK constructs a Logger instance with level - INFO and file_path - (sdk_logs.log parallel to bin/(Debug or Release) folder )

    
    /*
    * Create an instance of Logger Class that requires the following
    * Level -> Level of the log messages to be logged. Can be configured by typing Levels "." and choose any level from the list displayed.
    * FilePath -> Absolute file path, where messages need to be logged.
    */
    Logger logger = new Logger.Builder()
    .Level(Logger.Levels.ALL)
    .FilePath("/Users/user_name/Documents/csharp_sdk_log.log")
    .Build();
    
  2. Create an instance of UserSignature that identifies the current user.

    
    //Create an UserSignature instance that takes user Email as parameter
    UserSignature user = new UserSignature("abc@zoho.com");
    
  3. Configure the API environment which decides the domain and the URL to make API calls.

    
    /*
    * Configure the environment
    * which is of the pattern Domain.Environment
    * Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter
    * Available Environments: PRODUCTION, DEVELOPER, SANDBOX
    */
    Environment environment = USDataCenter.PRODUCTION;
    
  4. Create an instance of OAuthToken with the information that you get after registering your Zoho client.

    
    /*
    * Create a Token instance
    * ClientId -> OAuth client id.
    * ClientSecret -> OAuth client secret.
    * GrantToken -> GRANT token.
    * RefreshToken -> REFRESH token.
    * RedirectURL -> OAuth redirect URL.
    * Id -> User unique id.
    * RedirectURL -> OAuth redirect URL.
    */
    //Create a Token instance
    // if refresh token is available
    // The SDK throws an exception, if the given id is invalid.
    Token token = new OAuthToken.Builder()
    .Id("userID")
    .Build();
    
    // if grant token is available
    Token token = new OAuthToken.Builder()
    .ClientId("clientId")
    .ClientSecret("clientSecret")
    .GrantToken("grantToken")
    .RedirectURL("redirectURL")
    .Build();
    
    // if ID (obtained from persistence) is available
    Token token = new OAuthToken.Builder()
    .ClientId("clientId")
    .ClientSecret("clientSecret")
    .RefreshToken("refreshToken")
    .RedirectURL("redirectURL")
    .Build();
    
    // if access token is available
    Token token = new OAuthToken.Builder()
    .AccessToken("accessToken")
    .Build();
    
  5. Create an instance of TokenStore to persist tokens used for authenticating all the requests. By default, the SDK creates the sdk_tokens.txt file (parallel to to bin/(Debug or Release) folder) to persist the tokens.

    
    /*
    * Create an instance of DBStore that requires the following
    * Host -> DataBase host name. Default "localhost"
    * DatabaseName -> DataBase name. Default "zohooauth"
    * UserName -> DataBase user name. Default "root"
    * Password -> DataBase password. Default ""
    * PortNumber -> DataBase port number. Default "3306"
    * TableName -> Table Name. Default value "oauthtoken"
    */
    //TokenStore tokenstore = new DBStore.Builder().Build();
    
    TokenStore tokenstore = new DBStore.Builder()
    .Host("hostName")
    .DatabaseName("dataBaseName")
    .TableName("tableName")
    .UserName("userName")
    .Password("password")
    .PortNumber("portNumber")
    .Build();
    
    //TokenStore tokenstore = new FileStore("absolute_file_path");
    
    //TokenStore tokenStore = new CustomStore();
    
  6. Create an instance of SDKConfig containing the SDK configuration.

    
    /*
    * By default, the SDK creates the SDKConfig instance
    * autoRefreshFields (default - false)
    * 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 file(s) or refresh the fields using methods from ModuleFieldsHandler(com.zoho.crm.api.util.ModuleFieldsHandler)
    *
    * pickListValidation (default - true)
    * 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
    */
    SDKConfig config = new SDKConfig.Builder()
    .AutoRefreshFields(false)
    .PickListValidation(true)
    .Timeout(10)
    .Build();
    
  7. The path containing the absolute directory path to store user specific files containing module fields information. By default, the SDK stores the user-specific files in a folder parallel to bin/(Debug or Release)

    
    string resourcePath = "/Users/user_name/Documents/csharpsdk-application";
    
  8. Create an instance of RequestProxy containing the proxy properties of the user.

    
    /*
    * Create an instance of RequestProxy
    * host -> proxyHost
    * port -> proxyPort
    * user -> proxyUser
    * password -> password
    * userDomain -> userDomain
    */
    RequestProxy requestProxy = new RequestProxy.Builder()
    .Host("proxyHost")
    .Port(proxyPort)
    .User("proxyUser")
    .Password("password")
    .UserDomain("userDomain")
    .Build();
    
  9. Initialize the SDK and make API calls.