Skip to content

Commit 77bd19c

Browse files
committed
Add new example of using AuthenticatedClient
1 parent 855adcc commit 77bd19c

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Example: Get My Organizations using AuthenticatedClient
3+
4+
This example shows how to:
5+
1. Set up an AuthenticatedClient with manual token configuration
6+
2. Get all organizations you have access to
7+
3. Display organization information
8+
9+
Usage:
10+
- Replace the access_token with your actual Field Manager API token
11+
- Run the script to see your organizations
12+
13+
Run this example:
14+
python ex_get_my_organizations_using_authenticatedclient.py
15+
"""
16+
17+
from field_manager_python_client import AuthenticatedClient
18+
from field_manager_python_client.api.organizations import (
19+
get_organizations_organizations_get,
20+
)
21+
from field_manager_python_client.models import Organization
22+
23+
# Configuration - Replace with your actual values
24+
base_url = (
25+
"https://app.fieldmanager.io/api/location" # Base URL for the Field Manager API
26+
)
27+
access_token = "eyJhxxx" # Replace with your actual access token. You can get your token from https://app.fieldmanager.io/developer
28+
29+
30+
def main():
31+
print("🚀 Getting my organizations using AuthenticatedClient...")
32+
print()
33+
34+
# Initialize the authenticated client
35+
client = AuthenticatedClient(base_url=base_url, token=access_token)
36+
37+
try:
38+
with client as client:
39+
# Get all organizations
40+
print("🏢 Fetching organizations...")
41+
organizations: list[Organization] = (
42+
get_organizations_organizations_get.sync(client=client)
43+
)
44+
45+
if not organizations:
46+
print("❌ No organizations found. Check your access token and permissions.")
47+
return
48+
49+
print(f"✅ Found {len(organizations)} organization(s)")
50+
print()
51+
52+
# Display organizations
53+
print("� YOUR ORGANIZATIONS:")
54+
for i, org in enumerate(organizations, 1):
55+
print(f"{i}. {org.name}")
56+
print(f" ID: {org.organization_id}")
57+
print()
58+
59+
print("✅ Done!")
60+
61+
except Exception as e:
62+
print(f"❌ Error connecting to API: {e}")
63+
print("💡 Check your access token and network connection.")
64+
65+
66+
if __name__ == "__main__":
67+
main()

0 commit comments

Comments
 (0)