Page 1 of 1

Ledger Creation Automation

Posted: Tue Mar 25, 2025 4:49 am
by admin

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
x = 1

while x < 4:

    Acc = "Sample in zoho asd " + str(x)
    conn = http.client.HTTPSConnection("www.zohoapis.in")
    payload = json.dumps({
        "account_name": Acc,
        "account_code": 45741741145 + x,
        "account_type": "other_current_liability",
        #"currency_id": currency_id_inr,
        "description": "Testing. V 2.0 ",
      })

#print (payload)
    headers = {'Authorization': "Zoho-oauthtoken " + access_token, 'content-type': "application/json"}

    conn.request("POST", "/books/v3/chartofaccounts?organization_id=" + organization_id , payload, headers=headers)

    res = conn.getresponse()
    data = res.read()

    print(data.decode("utf-8"))
    x += 1