Is it possible to create accounts, groups and sub-accounts in chart of accounts using the API ?
It should be possible,
The following image shows how we can create Profit and Loss account via api2.
1 Like
Thanks I will give it a go.
I tried below code and got an error:
import requests
import json
url = "https://xxxx.manager.io/api2/balance-sheet-account-form"
headers = {
"accept": "application/json",
"X-API-KEY": "ChVaYW13ZXIgR3JvdXA......."
}
response = requests.get(url, headers=headers)
payload = { "Name": "NewAccount",
"Code": "1555",
"Group": "3de9d313-29a3-4451-89b4-43db9badf38c", }
response = requests.post(url, json=payload, headers=headers)
print(response.text)
This is the error I got:
"error": "System.FormatException: Unrecognized Guid format.\n
at System.Guid.GuidResult.SetFailure(ParseFailure failureKind)\n
at System.Guid.TryParseGuid(ReadOnlySpan`1 guidString, GuidResult& result)\n
at System.Guid..ctor(String g)\n
at ManagerServer.HttpHandlers.Api2.Api2.ProcessRequest() in
/home/runner/work/Manager/Manager/ManagerServer/HttpHandlers/Api2/Api2.cs:line 334"
Also how does it know if I’m creating a Grouping or an Account ?
I don’t understand your question, but this code work well
import requests
import json
# API URL and headers
base_url = "https://xxxxxxxxxxxxxxxxx.manager.io/api2"
headers = {
"accept": "*/*",
"X-API-KEY": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json"
}
# Balance Sheet Groups data
balance_sheet_groups = [
{
"Group": "9275ff4c-4cff-41d0-b7b5-f31c783f03d8",
"Name": "Group On Equity",
"Key": "a6c00b3f-9964-4a48-a465-1c867093a18b"
},
{
"Group": "ed5a19f6-12c5-45cc-b4b7-4e79f7ef50bc",
"Name": "Group On Liability",
"Key": "3a595080-c98d-4484-a881-843f44727c25"
},
{
"Group": "4c05c221-ca57-4c7c-be62-115669302ed4",
"Name": "Group On Asset",
"Key": "e5f3775d-40f6-4f45-a182-94140c3219c1"
}
]
# Balance Sheet Accounts data
balance_sheet_accounts = [
{
"Group": "e5f3775d-40f6-4f45-a182-94140c3219c1",
"Name": "Account in Group on Asset"
},
{
"Group": "3a595080-c98d-4484-a881-843f44727c25",
"Name": "Account in Group On Liability"
},
{
"Group": "a6c00b3f-9964-4a48-a465-1c867093a18b",
"Name": "Account in Group On Equity"
}
]
# Function to create balance sheet groups
def create_balance_sheet_group(group_data):
url = f"{base_url}/balance-sheet-group-form"
response = requests.post(url, json=group_data, headers=headers)
return response.json()
# Function to create balance sheet accounts
def create_balance_sheet_account(account_data):
url = f"{base_url}/balance-sheet-account-form"
response = requests.post(url, json=account_data, headers=headers)
return response.json()
# Create Balance Sheet Groups
for group in balance_sheet_groups:
result = create_balance_sheet_group(group)
print("Group Creation Response:", result)
# Create Balance Sheet Accounts
for account in balance_sheet_accounts:
result = create_balance_sheet_account(account)
print("Account Creation Response:", result)