Configuration

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

Mandatory KeysOptional Keys
userlogger
environmentstore
tokensdk_config
 proxy
 resource_path

Follow the below steps to configure the SDK.

  1. Create an instance of the Logger Class to log exception and API information.

    
    import {Levels,Logger} from "@zohocrm/typescript-sdk-2.0/routes/logger/logger"
    import {LogBuilder} from "@zohocrm/typescript-sdk-2.0/routes/logger/log_builder"
    /*
    * Create an instance of Logger Class that takes two parameters
    * 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.
    */
    let logger: Logger = new LogBuilder()
    .level(Levels.INFO)
    .filePath("/Users/user_name/Documents/node_sdk_logs.log")
    .build();
    
  2. Create an instance of UserSignature class that identifies the current user.

    
    import {UserSignature} from "@zohocrm/typescript-sdk-2.0/routes/user_signature"
    //Create an UserSignature instance that takes user Email as parameter
    let user: UserSignature = new UserSignature("abc@zoho.com");
    
  3. Configure the API environment which decides the domain and the URL to make API calls.

    
    import {USDataCenter} from "@zohocrm/typescript-sdk-2.0/routes/dc/us_data_center"
    /*
     * Configure the environment
     * which is of the pattern Domain.Environment
     * Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter
     * Available Environments: PRODUCTION(), DEVELOPER(), SANDBOX()
    */
    let environment: Environment = USDataCenter.PRODUCTION();
    
  4. Create an instance of OAuthToken with the information that you get after registering your Zoho client.

    
    import { OAuthToken } from "@zohocrm/typescript-sdk-2.0/models/authenticator/oauth_token"
    import { OAuthBuilder } from "@zohocrm/typescript-sdk-2.0/models/authenticator/oauth_builder"
    
    /*
    * Create a Token instance that requires the following
    * clientId -> OAuth client id.
    * clientSecret -> OAuth client secret.
    * refreshToken -> REFRESH token.
    * accessToken -> Access token.
    * grantToken -> GRANT token.
    * 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.
    let token: OAuthToken = new OAuthBuilder()
    .id("id")
    .build();
    
    // if grant token is available
    let token: OAuthToken = new OAuthBuilder()
    .clientId("clientId")
    .clientSecret("clientSecret")
    .grantToken("grantToken")
    .redirectURL("redirectURL")
    .build();
    
    // if ID (obtained from persistence) is available
    let token: OAuthToken = new OAuthBuilder()
    .clientId("clientId")
    .clientSecret("clientSecret")
    .refreshToken("refreshToken")
    .redirectURL("redirectURL")
    .build();
    
    // if access token is available
    let token: OAuthToken = new OAuthBuilder()
    .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 node_modules folder) to persist the tokens.

    
    import {DBStore} from "@zohocrm/typescript-sdk-2.0/models/authenticator/store/db_store"
    import {FileStore} from "@zohocrm/typescript-sdk-2.0/models/authenticator/store/file_store"
    import {DBBuilder} from "@zohocrm/typescript-sdk-2.0/models/authenticator/store/db_builder";
    
    /*
    * hostName -> DataBase host name. Default value "localhost"
    * databaseName -> DataBase name. Default  value "zohooauth"
    * userName -> DataBase user name. Default value "root"
    * password -> DataBase password. Default value ""
    * portNumber -> DataBase port number. Default value "3306"
    * tableName -> Table Name. Default value "oauthtoken"
    */
    let tokenstore: DBStore = new DBStore().build();
    
    let tokenstore: DBStore = new DBBuilder()
    .host("hostName")
    .databaseName("databaseName")
    .userName("userName")
    .portNumber("portNumber")
    .tableName("tableName")
    .password("password")
    .build();
    
    //let tokenstore: FileStore = new FileStore("/Users/userName/tssdk-tokens.txt")
    
  6. Create an instance of SDKConfig containing the SDK configuration.

    
    import {SDKConfig} from "@zohocrm/typescript-sdk-2.0/routes/sdk_config";
    import {SDKConfigBuilder} from "@zohocrm/typescript-sdk-2.0/routes/sdk_config_builder";
    
    /*
     * 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(utils/util/module_fields_handler.ts)
     *
     * 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.
     * if true - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
     * if false - the SDK does not validate the input and makes the API request with the user’s input to the pick list
     */
    let sdkConfig: SDKConfig = new SDKConfigBuilder().pickListValidation(false).autoRefreshFields(true).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 node_modules

    
    let resourcePath: string = "/Users/user_name/Documents/typescript-app";
    
  8. Create an instance of RequestProxy containing the proxy properties of the user.

    
    import { RequestProxy} from "@zohocrm/typescript-sdk-2.0/routes/request_proxy"
    import { ProxyBuilder} from "@zohocrm/typescript-sdk-2.0/routes/proxy_builder"
    
    /*
     * RequestProxy class takes the following parameters
     * host -> Host
     * port -> Port Number
     * user -> User Name. Default null.
     * password -> Password. Default null
     */
    let requestProxy: RequestProxy = new ProxyBuilder()
    .host("proxyHost")
    .port("proxyPort")
    .user("proxyUser")
    .password("password")
    .build();
      
  9. Initialize the SDK and make API calls.