Python Examples for FinAutCRM API¶
This section provides Python code examples for interacting with the FinAutCRM API.
Prerequisites¶
Install the requests library:
pip install requests
Credentials Setup¶
Create a client-data.json file in the userdocs/examples/ directory with your credentials:
{
"client_id": "your_client_id_here",
"client_secret": "your_client_secret_here"
}
Warning
Never commit your client-data.json file to version control!
Examples¶
1. Get Access Token¶
01_get_access_token.py - Authenticate and obtain an access token using OAuth2 client credentials flow.
--8<-- "userdocs/examples/python/01_get_access_token.py"
2. List Ordninger (Verify Token)¶
02_list_ordninger.py - Fetch ordninger (schemes) to verify your token works. Demonstrates authenticated API requests with pagination.
--8<-- "userdocs/examples/python/02_list_ordninger.py"
3. List Organization Units¶
03_list_orgunits.py - Fetch a paginated list of organization units with optional filtering by kind, active status, or search term.
--8<-- "userdocs/examples/python/03_list_orgunits.py"
4. Get Organization Unit Tree¶
04_get_orgunit_tree.py - Fetch a single organization unit with its full tree of descendants. Demonstrates hierarchical data traversal.
--8<-- "userdocs/examples/python/04_get_orgunit_tree.py"
5. Get Innmeldte (Enrolled Members)¶
05_get_innmeldte.py lists approved JAN and OCT reports,
then fetches each type’s latest report with counts per company and ordning.
Both /api/v1/innmeldte and /api/v1/innmeldte/invoices accept
report_type=JAN (the default) or report_type=OCT. The paths stay the same.
Use the same report type when listing invoices and fetching one by ID.
JAN is a year-end headcount (stock). OCT counts new enrollments in the report period (flow), normally January 1 through September 30, excluding candidates already enrolled on January 1. Full-year billing uses JAN + OCT; the reports are not interchangeable. The API exposes stored reports without recalculating them. A zero count means no candidates for JAN, or no new enrollments in the period for OCT, in that company’s ordning.
FinAut must approve a report in the finautfaktura UI before it becomes visible.
The latest report is selected by from_date, then generated, both descending.
This also determines the invoice-list order when reports share a start date.
Invalid report types return 422; a missing, unapproved, or mismatched invoice
returns 404. An empty invoice list means no approved report of that type exists.
Set CRM_API_BASE_URL to run the example against your development server.
Set CRM_CLIENT_DATA_FILE if your credentials file is stored elsewhere.
The script discovers invoice IDs and prints both report types without edits.
--8<-- "userdocs/examples/python/05_get_innmeldte.py"