Zoho Automation to download the Day Book Entries
Posted: Thu May 23, 2024 2:09 am
Code: Select all
Gt = "https://accounts.zoho.in/oauth/v2/token?refresh_token=" + refresh_token + "&client_id="+ client_id + "&client_secret=" + client_secret + "&grant_type=refresh_token"
response1 = requests.post(Gt)
data1 = json.loads(response1.text)
access_token = data1['access_token']
print("access_token:", access_token)
##4 Actual Post/ Get request to books
#Variable ORgid = from organisation
import json
import pandas as pd
import http.client
conn = http.client.HTTPSConnection("www.zohoapis.in")
payload = json.dumps({"cash_based":"false","from_date":"2024-05-01","to_date":"2024-05-31","group_by":"none","show_sub_account":"false",})
#print (payload)
headers = {'Authorization': "Zoho-oauthtoken " + access_token, 'content-type': "application/json"}
conn.request("GET", "/books/v3/reports/accounttransaction?organization_id=" + organization_id , payload, headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))The above code runs after authentication
if you have not done any authentication earlier by generating the Grant, Refresh, Access token then you have to do that first.
Let me put a code stand alone for this below
Code: Select all
###1 Generating Client id, Secret, https://api-console.zoho.com/client/1000.53G2MOWLNZWSZAGKZJYTWOP5UEVZ9F
#https://www.zoho.com/books/api/v3/introduction/
import requests
import json
import pandas as pd
client_id = "1000.NH6E3JV1WF2AX2LGNKGQNGPD7OPP1C"
client_secret = "0754cfc0f7923723d8d78bedc52d8600b984ab6ea3"
organization_id = "60029233076"
#To be generated for every session
###2 Generating Grant token https://api-console.zoho.com/client/1000.53G2MOWLNZWSZAGKZJYTWOP5UEVZ9F
GrantToken = "1000.d81f6d165ab36406bfa076d8d26fb767.d060980770012a42693dceee6b5b422a"
scope = "ZohoBooks.FullAccess.all"
##3 Generating Refresh Token Apicall
GRTATurl = "https://accounts.zoho.in/oauth/v2/token?grant_type=authorization_code&code=" + GrantToken + "&client_id="+ client_id + "&client_secret=" + client_secret
print(GRTATurl)
response = requests.post(GRTATurl)
data = json.loads(response.text)
refresh_token = data['refresh_token']
print("refresh_token:", refresh_token)
##3 Generating Access Token Apicall
import http.client
Gt = "https://accounts.zoho.in/oauth/v2/token?refresh_token=" + refresh_token + "&client_id="+ client_id + "&client_secret=" + client_secret + "&grant_type=refresh_token"
response1 = requests.post(Gt)
data1 = json.loads(response1.text)
access_token = data1['access_token']
print("access_token:", access_token)
##4 Actual Post/ Get request to books
#Variable ORgid = from organisation
import json
import pandas as pd
import http.client
conn = http.client.HTTPSConnection("www.zohoapis.in")
payload = json.dumps({"cash_based":"false","from_date":"2024-05-01","to_date":"2024-05-31","group_by":"none","show_sub_account":"false",})
#print (payload)
headers = {'Authorization': "Zoho-oauthtoken " + access_token, 'content-type': "application/json"}
conn.request("GET", "/books/v3/reports/accounttransaction?organization_id=" + organization_id , payload, headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))You need to convert the json data to dataframe and then to excel / csv