# zoho-client-django
A modest Zoho CRM API client which will do the oAuth2 for you.
## Usage
```python
from zoho_client.zoho import ZohoClient
client = ZohoClient()
# GET all Sales_Orders
res = client.make_request(api_endpoint="Sales_Orders")
# res is an instance of requests.Response
for sales_order in res.json()['data']:
print(f"sales order #{sales_order['id']}")
# find the first record
sales_order_id = res.json()['data'][0]['id']
# update the sales order's subject
payload = {'data': [ {'Subject': 'CHANGED'}]}
# the make_request accpet any kwargs which the requests.request() method accpets
res = client.make_request(method='PUT', api_endpoint=f"Sales_Orders/{sales_order_id}", json=payload)
print(res.json()['data'][0]['status'])
# => success
# search for a record. the params are automatically encoded
res = client.make_request("GET", "Accounts/search", params= {"criteria": "(Account_Name:equals:Guy Moller)"})
print(f"found {resp.json()['info']['count']} records")
# create a record
account_data={'Account_Name': 'John Doe', 'Email': 'joe@example.com'}
res = client.make_request(method='POST', api_endpoint='Accounts',json={'data':[account_data]})
print(res.json()['data'][0]['details']['id'])
# => 5599334000006242002
```
# Setup
## ENV
the package expects to have it's configuration in the settings.py:
```python
# read it from .env
ZOHO_CLIENT_ID = env("ZOHO_CLIENT_ID")
ZOHO_CLIENT_SECRET = env("ZOHO_CLIENT_SECRET")
ZOHO_API_VERSION = "v2.1"
# sandbox
ZOHO_BASE_URL = "https://crmsandbox.zoho.com"
# production
# ZOHO_BASE_URL = "https://zohoapis.com"
```
and naturally, don't forget to include the app in your INSALLED_APS:
```python
INSTALLED_APPS = [
...
"zoho_client",
]
```
## Initilization of the client (one off)
goto https://api-console.zoho.com/ :
copy the client id and secret and save them in your django settings. the recommended way would be to save them as ENV variables.

generate an authorization code
scope:
ZohoCRM.modules.ALL,ZohoCRM.settings.ALL,ZohoCRM.users.ALL,ZohoCRM.bulk.ALL,ZohoCRM.notifications.ALL

choose either production or sandbox

press generate and copy the code and run this from the django console:

go to django admin to zoho_client/zoho_token and press the regenerate zoho oauth tokens

paste the authorization code you have copied before

you are good to go!
### Programmatically:
```python
from zoho_client.zoho import ZohoClient
# the code you have just copied
code = "1000.12c557408797e20c8432216dca0bbb5f.f1896d4f9e2329136806637798859a99"
ZohoClient().fetch_tokens(code)
# -> '1000.03b32b6490d8573e242664710bbc4f2c.e009198b6ab4b89013485657409e4913'
```
Raw data
{
"_id": null,
"home_page": "https://github.com/gosourcellc/zoho-client-django",
"name": "zoho-client-django",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Guy Moller",
"author_email": "guy.moller@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/a3/4e/c8ca84026fb6471828251700d5f77209b0010350e619104a0886de863bab/zoho-client-django-1.2.2.tar.gz",
"platform": null,
"description": "# zoho-client-django\n\nA modest Zoho CRM API client which will do the oAuth2 for you.\n\n## Usage\n\n```python\n from zoho_client.zoho import ZohoClient\n client = ZohoClient()\n # GET all Sales_Orders\n res = client.make_request(api_endpoint=\"Sales_Orders\")\n # res is an instance of requests.Response\n for sales_order in res.json()['data']:\n print(f\"sales order #{sales_order['id']}\")\n\n # find the first record\n sales_order_id = res.json()['data'][0]['id']\n\n # update the sales order's subject\n payload = {'data': [ {'Subject': 'CHANGED'}]}\n # the make_request accpet any kwargs which the requests.request() method accpets\n res = client.make_request(method='PUT', api_endpoint=f\"Sales_Orders/{sales_order_id}\", json=payload)\n print(res.json()['data'][0]['status'])\n # => success\n\n # search for a record. the params are automatically encoded\n res = client.make_request(\"GET\", \"Accounts/search\", params= {\"criteria\": \"(Account_Name:equals:Guy Moller)\"})\n print(f\"found {resp.json()['info']['count']} records\")\n\n # create a record\n account_data={'Account_Name': 'John Doe', 'Email': 'joe@example.com'}\n res = client.make_request(method='POST', api_endpoint='Accounts',json={'data':[account_data]})\n print(res.json()['data'][0]['details']['id'])\n # => 5599334000006242002\n```\n\n# Setup\n\n## ENV\n\nthe package expects to have it's configuration in the settings.py:\n\n```python\n# read it from .env\nZOHO_CLIENT_ID = env(\"ZOHO_CLIENT_ID\")\nZOHO_CLIENT_SECRET = env(\"ZOHO_CLIENT_SECRET\")\nZOHO_API_VERSION = \"v2.1\"\n# sandbox\nZOHO_BASE_URL = \"https://crmsandbox.zoho.com\"\n# production\n# ZOHO_BASE_URL = \"https://zohoapis.com\"\n```\n\nand naturally, don't forget to include the app in your INSALLED_APS:\n\n```python\nINSTALLED_APPS = [\n ...\n \"zoho_client\",\n]\n\n```\n\n## Initilization of the client (one off)\n\ngoto https://api-console.zoho.com/ :\n\ncopy the client id and secret and save them in your django settings. the recommended way would be to save them as ENV variables.\n\n\n\ngenerate an authorization code\n\nscope:\nZohoCRM.modules.ALL,ZohoCRM.settings.ALL,ZohoCRM.users.ALL,ZohoCRM.bulk.ALL,ZohoCRM.notifications.ALL\n\n\n\nchoose either production or sandbox\n\n\n\npress generate and copy the code and run this from the django console:\n\n\ngo to django admin to zoho_client/zoho_token and press the regenerate zoho oauth tokens\n\n\n\npaste the authorization code you have copied before\n\n\n\nyou are good to go!\n\n### Programmatically:\n\n```python\nfrom zoho_client.zoho import ZohoClient\n# the code you have just copied\ncode = \"1000.12c557408797e20c8432216dca0bbb5f.f1896d4f9e2329136806637798859a99\"\nZohoClient().fetch_tokens(code)\n# -> '1000.03b32b6490d8573e242664710bbc4f2c.e009198b6ab4b89013485657409e4913'\n```\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Django app which is a client for the Zoho CRM API",
"version": "1.2.2",
"project_urls": {
"Homepage": "https://github.com/gosourcellc/zoho-client-django"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a34ec8ca84026fb6471828251700d5f77209b0010350e619104a0886de863bab",
"md5": "5616ed550f6b3a9be74ada320bd95ac1",
"sha256": "d2971ee33cb413629ab36b4c37f9f6ae95dfc62ec0f2eadbf8ca9bc9833420f4"
},
"downloads": -1,
"filename": "zoho-client-django-1.2.2.tar.gz",
"has_sig": false,
"md5_digest": "5616ed550f6b3a9be74ada320bd95ac1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9404,
"upload_time": "2023-07-19T10:40:28",
"upload_time_iso_8601": "2023-07-19T10:40:28.840863Z",
"url": "https://files.pythonhosted.org/packages/a3/4e/c8ca84026fb6471828251700d5f77209b0010350e619104a0886de863bab/zoho-client-django-1.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-19 10:40:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gosourcellc",
"github_project": "zoho-client-django",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "appnope",
"specs": [
[
"==",
"0.1.3"
]
]
},
{
"name": "asgiref",
"specs": [
[
"==",
"3.7.2"
]
]
},
{
"name": "asttokens",
"specs": [
[
"==",
"2.2.1"
]
]
},
{
"name": "backcall",
"specs": [
[
"==",
"0.2.0"
]
]
},
{
"name": "bleach",
"specs": [
[
"==",
"6.0.0"
]
]
},
{
"name": "certifi",
"specs": [
[
"==",
"2023.5.7"
]
]
},
{
"name": "charset-normalizer",
"specs": [
[
"==",
"3.2.0"
]
]
},
{
"name": "decorator",
"specs": [
[
"==",
"5.1.1"
]
]
},
{
"name": "Django",
"specs": [
[
"==",
"4.2.3"
]
]
},
{
"name": "django-environ",
"specs": [
[
"==",
"0.10.0"
]
]
},
{
"name": "django-extensions",
"specs": [
[
"==",
"3.2.3"
]
]
},
{
"name": "docutils",
"specs": [
[
"==",
"0.20.1"
]
]
},
{
"name": "executing",
"specs": [
[
"==",
"1.2.0"
]
]
},
{
"name": "idna",
"specs": [
[
"==",
"3.4"
]
]
},
{
"name": "importlib-metadata",
"specs": [
[
"==",
"6.8.0"
]
]
},
{
"name": "ipython",
"specs": [
[
"==",
"8.14.0"
]
]
},
{
"name": "jaraco.classes",
"specs": [
[
"==",
"3.3.0"
]
]
},
{
"name": "jedi",
"specs": [
[
"==",
"0.18.2"
]
]
},
{
"name": "keyring",
"specs": [
[
"==",
"24.2.0"
]
]
},
{
"name": "markdown-it-py",
"specs": [
[
"==",
"3.0.0"
]
]
},
{
"name": "matplotlib-inline",
"specs": [
[
"==",
"0.1.6"
]
]
},
{
"name": "mdurl",
"specs": [
[
"==",
"0.1.2"
]
]
},
{
"name": "more-itertools",
"specs": [
[
"==",
"9.1.0"
]
]
},
{
"name": "parso",
"specs": [
[
"==",
"0.8.3"
]
]
},
{
"name": "pexpect",
"specs": [
[
"==",
"4.8.0"
]
]
},
{
"name": "pickleshare",
"specs": [
[
"==",
"0.7.5"
]
]
},
{
"name": "pkginfo",
"specs": [
[
"==",
"1.9.6"
]
]
},
{
"name": "prompt-toolkit",
"specs": [
[
"==",
"3.0.39"
]
]
},
{
"name": "ptyprocess",
"specs": [
[
"==",
"0.7.0"
]
]
},
{
"name": "pure-eval",
"specs": [
[
"==",
"0.2.2"
]
]
},
{
"name": "Pygments",
"specs": [
[
"==",
"2.15.1"
]
]
},
{
"name": "readme-renderer",
"specs": [
[
"==",
"40.0"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.31.0"
]
]
},
{
"name": "requests-toolbelt",
"specs": [
[
"==",
"1.0.0"
]
]
},
{
"name": "rfc3986",
"specs": [
[
"==",
"2.0.0"
]
]
},
{
"name": "rich",
"specs": [
[
"==",
"13.4.2"
]
]
},
{
"name": "six",
"specs": [
[
"==",
"1.16.0"
]
]
},
{
"name": "sqlparse",
"specs": [
[
"==",
"0.4.4"
]
]
},
{
"name": "stack-data",
"specs": [
[
"==",
"0.6.2"
]
]
},
{
"name": "traitlets",
"specs": [
[
"==",
"5.9.0"
]
]
},
{
"name": "twine",
"specs": [
[
"==",
"4.0.2"
]
]
},
{
"name": "typing_extensions",
"specs": [
[
"==",
"4.7.1"
]
]
},
{
"name": "urllib3",
"specs": [
[
"==",
"2.0.3"
]
]
},
{
"name": "wcwidth",
"specs": [
[
"==",
"0.2.6"
]
]
},
{
"name": "webencodings",
"specs": [
[
"==",
"0.5.1"
]
]
},
{
"name": "zipp",
"specs": [
[
"==",
"3.16.2"
]
]
}
],
"lcname": "zoho-client-django"
}