zoho-crm-connector


Namezoho-crm-connector JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/timrichardson/zoho_crm_package
SummaryZoho CRM connector
upload_time2024-05-14 23:45:51
maintainerNone
docs_urlNone
authorTim Richardson
requires_python>=3.6
licenseMIT
keywords zoho crm
VCS
bugtrack_url
requirements setuptools requests Sphinx PySimpleGUI pytest
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Zoho CRM Connector for Python
==================

Zoho provides a Python SDK, but I found it a bit hard to use and it seems a bit complicated.
For instance, there is a dependency on mysql.
This module is a little more pragmatic and it returns pages of results with yield.
This code is in production use for some years, as of 2021. 


Install
=======

pip install zoho_crm_connector


Authenticating with Zoho CRM
============================

You need three things:

1. refresh token
2. client ID
3. client secret

These instructions are from the documentation from Zoho for the Python SDK

Step 1: Registering a Zoho Client
---------------------------------

Since Zoho CRM APIs are authenticated with OAuth2 standards, you should register your client app with Zoho. To register your app:

Visit this page https://api-console.zoho.com/
Click on “Add Client ID”.
Enter Client Name, Client Domain and Redirect URI.
Select the Client Type as "Web based".
Click “Create”
Your Client app would have been created and displayed by now.
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).

Note for Sandbox:
^^^^^^^^^^^^^^^^^

You can pass the sandbox url as the base url::

    zoho_crm = Zoho_crm(refresh_token=zoho_keys['refresh_token'],
        client_id=zoho_keys['client_id'],
        client_secret=zoho_keys['client_secret'],
        base_url='https://crmsandbox.zoho.com/crm/v2/',
        token_file_dir=tmp_path_factory.mktemp('zohocrm'))

Please note: Make a separate client ID for your sandbox testing.
Even though the process of getting a grant token and then a refresh token is exactly the same,
it seems to need a distinct client ID via the developer console.

Step 2: Generating self-authorized grant and refresh token
----------------------------------------------------------

Note
----

Zoho CRM can be hosted in different geographies. The URLs below assume you are using the .com version.
If, say, you are using .com.au (Australian hosting) then use the .com.au version of Zoho URLs.
For example, the Zoho Developer Console becomes https://accounts.zoho.com.au/developerconsole

When constructing the connector object, pass hosting = ".COM" or ".AU"
.COM is the default. 
The other geographies are not tested.


Read more about Multi DC: https://www.zoho.com/crm/developer/docs/api/v2/multi-dc.html
When using self-clients for Australia, make the request of accounts.zoho.com.au succeeds. This is contrary to Zoho's documentation

----

For self client apps, the self authorized grant token should be generated from the Zoho Developer Console (https://accounts.zoho.com/developerconsole)

Visit https://accounts.zoho.com/developerconsole
Click Options → Self Client of the client for which you wish to authorize.
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.
scope can be::

    ZohoCRM.modules.all,ZohoCRM.users.all,ZohoCRM.org.all,ZohoCRM.settings.all,aaaserver.profile.READ

Copy the grant token for backup. It expires soon, so use it to make a refresh_token

Generate refresh_token from grant token by making a POST request with the URL below
You can't do POST requests by entering  in the browser:

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

this works with curl:

``curl -d "code=1000.2f...68&redirect_uri=https://www.growthpath.com.au/callback&client_id=1000.ZZZZ...99&client_secret=bzz...123&grant_type=authorization_code" -X POST https://accounts.zoho.com/oauth/v2/token``

Copy the refresh token ... this doesn't expire, and it's how access is granted

### Experimental helper script

There is a little python script to help get teh refresh token from a self client. 

`python get_token.py`

Usage
=====
See test_zoho_crm_connector.py in tests for some examples.
Note when searching, parentheses must be escaped. See the code.


    @pytest.fixture(scope='session')
    def zoho_crm(tmp_path_factory)->Zoho_crm:
        zoho_keys = {
            'refresh_token': os.getenv('ZOHOCRM_REFRESH_TOKEN'),
            'client_id': os.getenv('ZOHOCRM_CLIENT_ID'),
            'client_secret': os.getenv('ZOHOCRM_CLIENT_SECRET'),
            'user_id': os.getenv('ZOHOCRM_DEFAULT_USERID')
        }
        if not os.getenv("ZOHO_SANDBOX") or os.getenv("ZOHO_SANDBOX") == "True":
            zoho_crm = Zoho_crm(refresh_token=zoho_keys['refresh_token'],
                                client_id=zoho_keys['client_id'],
                                client_secret=zoho_keys['client_secret'],
                                base_url='https://crmsandbox.zoho.com/crm/v2/',
                                default_zoho_user_id=zoho_keys['user_id'],
                                hosting=".COM",
                                token_file_dir=tmp_path_factory.mktemp('zohocrm'))
        else:
            zoho_crm = Zoho_crm(refresh_token=zoho_keys['refresh_token'],
                                client_id=zoho_keys['client_id'],
                                client_secret=zoho_keys['client_secret'],
                                base_url="https://www.zohoapis.com/crm/v2/", 
                                default_zoho_user_id=zoho_keys['user_id'],
                                hosting=".COM",
                                token_file_dir=tmp_path_factory.mktemp('zohocrm'))

    return zoho_crm



Testing
=======
pytest needs to be installed.

Warning: testing writes an access token to a temporary directory provided by pytest, on linux this is a subdirectory of /tmp.
testing needs a connection to zoho. Set three environment variables, because this is what the tests look for::

    refresh_token': os.getenv('ZOHOCRM_REFRESH_TOKEN'),
    client_id': os.getenv('ZOHOCRM_CLIENT_ID'),
    client_secret': os.getenv('ZOHOCRM_CLIENT_SECRET')

    and also set a Zoho user id as the default user (ZOHOCRM_DEFAULT_USERID). This is an internal Zoho id value, not a user name.


Uploading
=========
```
python3 setup.py sdist bdist_wheel
python3 -m twine upload --skip-existing dist/*python3 -m twine upload --skip-existing dist/*
```

Changes
========

v1.0.3 added examples.py in case it is helpful

v1.0.2 Metadata updates in the package, promote to Production/Stable

v1.0.1 Fixed bug with get_users(): now all pages are returned, and the usertype filter works.

v1.0.0 It works well enough to be v1

v0.4.6. Add a message to Quota Exceeded exception

v0.4.5. Raise Runtime exception if token refresh fails to return a valid token

v0.4.4 Merge new feature for kdodia (Karan Dodia): yield_deleted_records_from_module, update_zoho_module, and fixes for 204 response get_related_records

v0.4.3 Handle updating errors such as duplicate value violation

v0.4.2 Fix a potential date bug with modified-since header

v0.4.1: small changes to readme. Also, v.0.4.0 has a test case using the IN criteria which may be interesting.

v 0.4.0: No longer retry when API limit is reached, raise an exception instead. 
Reason: the Zoho CRM API rate limit is 24 hour rolling, and it can take minutes to get credits back. Too long to wait.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/timrichardson/zoho_crm_package",
    "name": "zoho-crm-connector",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "zoho crm",
    "author": "Tim Richardson",
    "author_email": "tim@growthpath.com.au",
    "download_url": "https://files.pythonhosted.org/packages/71/f5/7ddabbb3982b4fe56b03f71e820ff7244fc12722e3bfe299043a76e00ce8/zoho_crm_connector-1.0.3.tar.gz",
    "platform": null,
    "description": "Zoho CRM Connector for Python\n==================\n\nZoho provides a Python SDK, but I found it a bit hard to use and it seems a bit complicated.\nFor instance, there is a dependency on mysql.\nThis module is a little more pragmatic and it returns pages of results with yield.\nThis code is in production use for some years, as of 2021. \n\n\nInstall\n=======\n\npip install zoho_crm_connector\n\n\nAuthenticating with Zoho CRM\n============================\n\nYou need three things:\n\n1. refresh token\n2. client ID\n3. client secret\n\nThese instructions are from the documentation from Zoho for the Python SDK\n\nStep 1: Registering a Zoho Client\n---------------------------------\n\nSince Zoho CRM APIs are authenticated with OAuth2 standards, you should register your client app with Zoho. To register your app:\n\nVisit this page https://api-console.zoho.com/\nClick on \u201cAdd Client ID\u201d.\nEnter Client Name, Client Domain and Redirect URI.\nSelect the Client Type as \"Web based\".\nClick \u201cCreate\u201d\nYour Client app would have been created and displayed by now.\nThe newly registered app's Client ID and Client Secret can be found by clicking Options \u2192 Edit.\n(Options is the three dot icon at the right corner).\n\nNote for Sandbox:\n^^^^^^^^^^^^^^^^^\n\nYou can pass the sandbox url as the base url::\n\n    zoho_crm = Zoho_crm(refresh_token=zoho_keys['refresh_token'],\n        client_id=zoho_keys['client_id'],\n        client_secret=zoho_keys['client_secret'],\n        base_url='https://crmsandbox.zoho.com/crm/v2/',\n        token_file_dir=tmp_path_factory.mktemp('zohocrm'))\n\nPlease note: Make a separate client ID for your sandbox testing.\nEven though the process of getting a grant token and then a refresh token is exactly the same,\nit seems to need a distinct client ID via the developer console.\n\nStep 2: Generating self-authorized grant and refresh token\n----------------------------------------------------------\n\nNote\n----\n\nZoho CRM can be hosted in different geographies. The URLs below assume you are using the .com version.\nIf, say, you are using .com.au (Australian hosting) then use the .com.au version of Zoho URLs.\nFor example, the Zoho Developer Console becomes https://accounts.zoho.com.au/developerconsole\n\nWhen constructing the connector object, pass hosting = \".COM\" or \".AU\"\n.COM is the default. \nThe other geographies are not tested.\n\n\nRead more about Multi DC: https://www.zoho.com/crm/developer/docs/api/v2/multi-dc.html\nWhen using self-clients for Australia, make the request of accounts.zoho.com.au succeeds. This is contrary to Zoho's documentation\n\n----\n\nFor self client apps, the self authorized grant token should be generated from the Zoho Developer Console (https://accounts.zoho.com/developerconsole)\n\nVisit https://accounts.zoho.com/developerconsole\nClick Options \u2192 Self Client of the client for which you wish to authorize.\nEnter one or more (comma separated) valid Zoho CRM scopes that you wish to authorize in the \u201cScope\u201d field and choose the time of expiry. Provide \u201caaaserver.profile.READ\u201d scope along with Zoho CRM scopes.\nscope can be::\n\n    ZohoCRM.modules.all,ZohoCRM.users.all,ZohoCRM.org.all,ZohoCRM.settings.all,aaaserver.profile.READ\n\nCopy the grant token for backup. It expires soon, so use it to make a refresh_token\n\nGenerate refresh_token from grant token by making a POST request with the URL below\nYou can't do POST requests by entering  in the browser:\n\nhttps://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\nthis works with curl:\n\n``curl -d \"code=1000.2f...68&redirect_uri=https://www.growthpath.com.au/callback&client_id=1000.ZZZZ...99&client_secret=bzz...123&grant_type=authorization_code\" -X POST https://accounts.zoho.com/oauth/v2/token``\n\nCopy the refresh token ... this doesn't expire, and it's how access is granted\n\n### Experimental helper script\n\nThere is a little python script to help get teh refresh token from a self client. \n\n`python get_token.py`\n\nUsage\n=====\nSee test_zoho_crm_connector.py in tests for some examples.\nNote when searching, parentheses must be escaped. See the code.\n\n\n    @pytest.fixture(scope='session')\n    def zoho_crm(tmp_path_factory)->Zoho_crm:\n        zoho_keys = {\n            'refresh_token': os.getenv('ZOHOCRM_REFRESH_TOKEN'),\n            'client_id': os.getenv('ZOHOCRM_CLIENT_ID'),\n            'client_secret': os.getenv('ZOHOCRM_CLIENT_SECRET'),\n            'user_id': os.getenv('ZOHOCRM_DEFAULT_USERID')\n        }\n        if not os.getenv(\"ZOHO_SANDBOX\") or os.getenv(\"ZOHO_SANDBOX\") == \"True\":\n            zoho_crm = Zoho_crm(refresh_token=zoho_keys['refresh_token'],\n                                client_id=zoho_keys['client_id'],\n                                client_secret=zoho_keys['client_secret'],\n                                base_url='https://crmsandbox.zoho.com/crm/v2/',\n                                default_zoho_user_id=zoho_keys['user_id'],\n                                hosting=\".COM\",\n                                token_file_dir=tmp_path_factory.mktemp('zohocrm'))\n        else:\n            zoho_crm = Zoho_crm(refresh_token=zoho_keys['refresh_token'],\n                                client_id=zoho_keys['client_id'],\n                                client_secret=zoho_keys['client_secret'],\n                                base_url=\"https://www.zohoapis.com/crm/v2/\", \n                                default_zoho_user_id=zoho_keys['user_id'],\n                                hosting=\".COM\",\n                                token_file_dir=tmp_path_factory.mktemp('zohocrm'))\n\n    return zoho_crm\n\n\n\nTesting\n=======\npytest needs to be installed.\n\nWarning: testing writes an access token to a temporary directory provided by pytest, on linux this is a subdirectory of /tmp.\ntesting needs a connection to zoho. Set three environment variables, because this is what the tests look for::\n\n    refresh_token': os.getenv('ZOHOCRM_REFRESH_TOKEN'),\n    client_id': os.getenv('ZOHOCRM_CLIENT_ID'),\n    client_secret': os.getenv('ZOHOCRM_CLIENT_SECRET')\n\n    and also set a Zoho user id as the default user (ZOHOCRM_DEFAULT_USERID). This is an internal Zoho id value, not a user name.\n\n\nUploading\n=========\n```\npython3 setup.py sdist bdist_wheel\npython3 -m twine upload --skip-existing dist/*python3 -m twine upload --skip-existing dist/*\n```\n\nChanges\n========\n\nv1.0.3 added examples.py in case it is helpful\n\nv1.0.2 Metadata updates in the package, promote to Production/Stable\n\nv1.0.1 Fixed bug with get_users(): now all pages are returned, and the usertype filter works.\n\nv1.0.0 It works well enough to be v1\n\nv0.4.6. Add a message to Quota Exceeded exception\n\nv0.4.5. Raise Runtime exception if token refresh fails to return a valid token\n\nv0.4.4 Merge new feature for kdodia (Karan Dodia): yield_deleted_records_from_module, update_zoho_module, and fixes for 204 response get_related_records\n\nv0.4.3 Handle updating errors such as duplicate value violation\n\nv0.4.2 Fix a potential date bug with modified-since header\n\nv0.4.1: small changes to readme. Also, v.0.4.0 has a test case using the IN criteria which may be interesting.\n\nv 0.4.0: No longer retry when API limit is reached, raise an exception instead. \nReason: the Zoho CRM API rate limit is 24 hour rolling, and it can take minutes to get credits back. Too long to wait.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Zoho CRM connector",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/timrichardson/zoho_crm_package"
    },
    "split_keywords": [
        "zoho",
        "crm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bfbc4eb155d794473541880a7bd4a1fe7dc792d7d675ebec499bba029dc7a6d4",
                "md5": "0ac3a14b10d4d8fbb69b0eb04c79adda",
                "sha256": "d1f9b2fde07ff4894415fabb30ad1e8da26d1d793fa744911905cc4631570dca"
            },
            "downloads": -1,
            "filename": "zoho_crm_connector-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0ac3a14b10d4d8fbb69b0eb04c79adda",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 11225,
            "upload_time": "2024-05-14T23:45:49",
            "upload_time_iso_8601": "2024-05-14T23:45:49.788081Z",
            "url": "https://files.pythonhosted.org/packages/bf/bc/4eb155d794473541880a7bd4a1fe7dc792d7d675ebec499bba029dc7a6d4/zoho_crm_connector-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "71f57ddabbb3982b4fe56b03f71e820ff7244fc12722e3bfe299043a76e00ce8",
                "md5": "31bbae1b6110adde8b624b764dcca7fd",
                "sha256": "1a0eb85a80d4bf92859982230d4b27d3d2ca53aba3ca31bb91a9be9e6150b0c4"
            },
            "downloads": -1,
            "filename": "zoho_crm_connector-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "31bbae1b6110adde8b624b764dcca7fd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 13403,
            "upload_time": "2024-05-14T23:45:51",
            "upload_time_iso_8601": "2024-05-14T23:45:51.803011Z",
            "url": "https://files.pythonhosted.org/packages/71/f5/7ddabbb3982b4fe56b03f71e820ff7244fc12722e3bfe299043a76e00ce8/zoho_crm_connector-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-14 23:45:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "timrichardson",
    "github_project": "zoho_crm_package",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "setuptools",
            "specs": []
        },
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "Sphinx",
            "specs": [
                [
                    "==",
                    "4.4.0"
                ]
            ]
        },
        {
            "name": "PySimpleGUI",
            "specs": [
                [
                    "~=",
                    "4.45.0"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": []
        }
    ],
    "lcname": "zoho-crm-connector"
}
        
Elapsed time: 0.75062s