{"_id":"@camfolio/zcrmsdk","_rev":"1-0a9c5a76f9713627eb5065e6793d103f","name":"@camfolio/zcrmsdk","dist-tags":{"latest":"0.0.20"},"versions":{"0.0.20":{"name":"@camfolio/zcrmsdk","version":"0.0.20","description":"Node SDK for Zoho CRM","main":"lib/js/ZCRMRestClient","dependencies":{"fs":"0.0.1-security","mysql":"^2.18.1","properties-reader":"0.0.16","querystring":"^0.2.0","request":"^2.88.2"},"keywords":["Node","Zoho","CRM","OAuth2","API"],"author":{"name":"Zoho CRM API Team","url":"support@zohocrm.com"},"gitHead":"4dbe84bda2f3c5e11a15d9a90a1cf7153e2913b8","_id":"@camfolio/zcrmsdk@0.0.20","_nodeVersion":"10.16.1","_npmVersion":"6.14.5","dist":{"integrity":"sha512-Pt/S/RH60Jg49TMUMXhf+0YiaDDef7sEYaopzNnHNnP9AnczXeYmw25LxkYJIlmiWSadaSj6Cz11Vn+21O5UWw==","shasum":"398582f4553e1974c136693aa2860108c31e1bd3","tarball":"https://registry.npmjs.org/@camfolio/zcrmsdk/-/zcrmsdk-0.0.20.tgz","fileCount":14,"unpackedSize":37654,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfq+SjCRA9TVsSAnZWagAAT+cP/1xDx+Ufx40dsBTqmEXG\n/t+l2DjwLml3uksCY2/3rxedKUYAwcNAJCqaYVDUzrlJC0flcHCq2PbqGgLi\nZY47M50xCYg1HBNADFfxrJZgGKsqAcUgEwpRV6Tub3QXZ7fxXprzHb+c+5Nh\nz9nq2H0+7V+fPZCFJZXcBgMzcnMrpfkaOqK8PjoBNpFMINyLSaj8BvSsbmgu\ncnsSvtd9N0N2WKkep8T9n1W4wHAuSIOOcNYo9lIwylc+VBNctsHGQTmb+kn9\n8aeVYA78P8hlAlRTIFJI4aWKnxs23SPdx5+V9igwxQrvy5dBVqWVpa0jVGjS\nEiUSSzpu2GxFUS0za3JXkjNOSUSseWqwxs9r/fVK9V3P8Akv8mYMoQGx8h6p\nFHheQFVjU7F2HZLDe+gmkmpGmDOZ/fGI0qhe9vgVbUoTE0gCenq4+Hgh104K\nCk7Y9funSQZhwW7JAvxfqeTA86gd2jMb4x5zk0XsIWluPDO2xP2E2KOEoL0J\ngZsbfqHs0N/Zy4Z9DvHcP1dV2HUOGlbaJKFaLR/r2ayncJry0ft5us3D9q3g\nqbQd/t9Rwc3pvKVfQXJeLTZWyeudSp0NCKq93zL1yHyrjQwrFnO5m5+gpHEw\nJartpGpl2yTZmM7SaaOvgaedX5WirhnjiZNn+NM6UODyyb42C1o1foKH05TK\nQSld\r\n=43Uq\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICJC2Xzf8q5GMgowlPdSUEFWDJk/AfpZ54fiFu4hkCN8AiAYJBKH9k+hT4nIxSmatwtLBiuO9BtBDmjxClP1NCKdtA=="}]},"_npmUser":{"name":"camfolio","email":"hello@camfolio.co.uk"},"directories":{},"maintainers":[{"name":"camfolio","email":"hello@camfolio.co.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/zcrmsdk_0.0.20_1605100706941_0.8458442373999269"},"_hasShrinkwrap":false}},"time":{"created":"2020-11-11T13:18:26.901Z","0.0.20":"2020-11-11T13:18:27.147Z","modified":"2022-04-04T21:34:12.926Z"},"maintainers":[{"name":"camfolio","email":"hello@camfolio.co.uk"}],"description":"Node SDK for Zoho CRM","keywords":["Node","Zoho","CRM","OAuth2","API"],"author":{"name":"Zoho CRM API Team","url":"support@zohocrm.com"},"readme":"##Node JS SDK for Zoho CRM\n\n##Abstract\n\nNode SDK is a wrapper for Zoho CRM APIs. Hence invoking a Zoho CRM API from your Node application is just a function call which provide the most appropriate response.\n\nThis SDK supports both single user as well as multi user authentication.\n\n##Registering a Zoho Client\n\nSince Zoho CRM APIs are authenticated with OAuth2 standards, you should register your client app with Zoho. To register your app:\n\n\t- Visit this page https://accounts.zoho.com/developerconsole.\n\n\t- Click on “Add Client ID”.\n\n\t- Enter Client Name, Client Domain and Redirect URI.\n\n\t- Select the Client Type as \"Web based\".\n\n\t- Click “Create”.\n\n\t- Your Client app would have been created and displayed by now.\n\n\t- The newly registered app's Client ID and Client Secret can be found by clicking Options → Edit. (Options is the three dot icon at the right corner).\n\n##Installation of Node CRM SDK\n\nNode JS SDK will be installed and a package named 'zcrmsdk' will be created in the installation directory.\n\n>npm install zcrmsdk\n\nOnce installed it can be used in the code as below,\n\n>var ZCRMRestClient = require('zcrmsdk')\n\n##API Usage\n\n##Configurations\n\nYour OAuth Client details should be given to the SDK as a property file. In the SDK, you need to configure a file named oauth_configuration.properties. Please place the respective values in that file. You can place it under resources/ package from where the SDK is used.\n\n\nzcrmsdk will try reading file from **'resources/oauth_configuration.properties'** \n\n\nPlease fill the values for the following keys alone.\nBased on your domain(EU,CN), please change the value of crm.iamurl. Default value set as US domain.\n\n\n```\n\n[zoho]\ncrm.iamurl=                                                     \ncrm.clientid=                                                    \ncrm.clientsecret=                                         \ncrm.redirecturl=                                   \n\n```\n\ncrm.clientid, crm.clientsecret and crm.redirecturl are your OAuth client’s configurations that you get after registering your Zoho client.\ncrm.iamurl is the accounts URL. It may be accounts.zoho.com or accounts.zoho.eu. If the crm.iamurl is not specified, by default the URL will be accounts.zoho.com.\n\nIn configuration.properties file:\n\n```\n[crm]\napi.url=                              \napi.user_identifier=                            \napi.tokenmanagement=      \n\n[mysql]\nusername=\npassword=                 \n\n```\napi.url is the URL used to call APIs. By default, the URL is www.zohoapis.com.\napi.user_identifier will be empty by default. For single user authentication, this key can be filled with the respective email id, so that all calls happens by using this user's authentication.\napi.tokenmanagement is given as a measure to manage and maintain tokens. If tokenmanagement is not provided, then sdk's default implementation(mysql) will be followed.\nusername and password can be given here if you already have one created for your MySQL.\nThe above keys specified in configuration.properties file are all optional.\n\nuser_identifier can be set in two ways .\n1.Mentioning it in api.user_identifier in configuration.properties file \n2.Can be set via code using set setUserIdentifier.\n\nIf user_identifier is not set via both the ways then default value 'zcrm_default_user' will be set by the sdk itself . \n\n\n##Token Storage Mechanism\n\nTo use the default token storage provided by the SDK, the following are to be done:\n\n**Mysql should be running in default port in localhost.**\n\nDatabase with name **zohooauth** should be created and a table with below configurations should be present in the database. Table, named **\"oauthtokens\"**, should have the columns **\"useridentifier\" (varchar) \"accesstoken\" (varchar), \"refreshtoken\" (varchar) and \"expirytime\" (bigint)**.\n\nOnce the configuration is set, storage and retrieval of tokens will be handled by the SDK.\nIf the user wants to utilize their own mechanism, they can mention it in configuration.properties by providing the respective module in api.tokenmanagement.\n\nThis module should contain the below methods,\n\t**saveOAuthTokens(token_obj)**\n\t**updateOAuthTokens(token_obj)**\n\t\tIrrespective of response, the next execution happens. So care should be taken by the user in handling their module.\n\t**getOAuthTokens()**\n\t\tThe expected response for this method : JSON array containing json response with expirytime, refreshtoken and accesstoken fields.\n\n\n##Generating self-authorized grant and refresh token\n\nFor self client apps, the self authorized grant token should be generated from the Zoho Developer Console (https://accounts.zoho.com/developerconsole)\n\n\n\t- Visit https://accounts.zoho.com/developerconsole\n\n\t- Click Options → Self Client of the client for which you wish to authorize.\n\n\t- Enter one or more (comma separated) valid Zoho CRM scopes that you wish to authorize in the “Scope” field and choose the time of expiry. Provide “aaaserver.profile.READ” scope along with Zoho CRM scopes.\n\t        - Copy the grant token for backup.\n\n\t        - Generate refresh_token from grant token by making a POST request with the URL below https://accounts.zoho.com/oauth/v2/token?code={grant_token}&redirect_uri={redirect_uri}&client_id={client_id}&client_secret={client_secret}&grant_type=authorization_code\n\n\t        - Copy the refresh token for backup.\n\nPlease note that the generated grant token is valid only for the stipulated time you chose while generating it. Hence, the access and refresh tokens should be generated within that time.\n\nEach time server is restarted, this function has to be called and both the configuration files should be populated with proper values before calling this function, else exception will be thrown.\n\n**All functions return promises in zcrm node sdk.**\n\n\n##Initialize \n\nBelow snippet has to be called before starting the app\n\n```\nvar ZCRMRestClient = require('zcrmsdk');\n\nZCRMRestClient.initialize().then(function(){\n\n    ...\n\n});\n\n```\n\n##Generating access and refresh token from granttoken\n\n```\n\nZCRMRestClient.generateAuthTokens(user_identifier,grant_token).then(function(auth_response){\n\n    console.log(\"access token :\"+auth_response.access_token);\n    console.log(\"refresh token :\"+auth_response.refresh_token);\n    console.log(\"expires in :\"+auth_response.expires_in);\n\n});\n\n```\n\n##Generating access token from refresh token\n\nThis will be handled by sdk itself if the access and refresh token is generated by sdk.Developer need not call this explicitly.\n\n```\nZCRMRestClient.generateAuthTokenfromRefreshToken(user_identifier,refresh_token).then(function(auth_response){\n\n    console.log(\"access token :\"+auth_response.access_token);\n    console.log(\"refresh token :\"+auth_response.refresh_token);\n    console.log(\"expires in :\"+auth_response.expires_in);\n\n});\n\n```\n\n##Sample API Calls \n\n```\nvar input ={};\ninput.module = \"Leads\";\n\nvar params = {};\nparams.page = 0;\nparams.per_page = 5;\ninput.params = params;\n\ncrmclient.API.MODULES.get(input).then(function(response){\n\n    var result = \"<html><body><b> Top 5 Leads</b>\";\n    var data = response.body;\n    data = JSON.parse(data);\n    data = data.data;\n    for (i in data){\n\n        var record = data[i];\n        var name = record.Full_Name;\n        \n        result+=\"<br><span>\"+name+\"</span>\";\n\n    }\n\n    result+=\"</body></html>\";\n\n})\n```\n\n\n\n##Hierarchy\nzcrmsdk\n\n ```\n   API\n     ORG\n       get\n     MODULES\n       get\n       post\n       put\n       delete\n       getAllDeletedRecords\n       getRecycleBinRecords\n       getPermanentlyDeletedRecords\n       search\n     SETTINGS\n       getFields\n       getLayouts\n       getCustomViews\n       updateCustomViews\n       getModules\n       getRoles\n       getProfiles\n       getRelatedLists\n     ACTIONS\n       convert\n     USERS\n       get\n     ATTACHMENTS\n       uploadFile\n       deleteFile\n       downloadFile\n       uploadLink\n       uploadPhoto\n       downloadPhoto\n       deletePhoto\n     FUNCTIONS\n       executeFunctionsInGet\n       executeFunctionsInPost\n ```\n\n\nAs appearing in the hierarchy, zcrmsdk entity class has instance variables to fetch its own properties and to fetch data of its immediate child entities through an API call.\n\nFor example, to call an API to get module data, the request should be zcrmsdk.API.MODULES.{operation_type}. The operation types can be GET, POST, PUT, DELETE or CREATE.\n\n\n\n##Response Handling\nAll API calls will give the actual API response given by Zoho APIs, except file download.\n\nFor file download, the response will contain an extra field filename.\n\n##Error Handling:\nAll errors will be thrown explicitly and care should be taken in catching the same.\n\n\n\n","readmeFilename":"README.md"}