Files
Brancheneinstufung2/connector-superoffice/final_env_test.py

50 lines
1.5 KiB
Python

import os
import requests
from dotenv import load_dotenv
load_dotenv(override=True)
# Config
SO_CLIENT_ID = os.getenv("SO_CLIENT_ID") or os.getenv("SO_SOD")
SO_CLIENT_SECRET = os.getenv("SO_CLIENT_SECRET")
SO_REFRESH_TOKEN = os.getenv("SO_REFRESH_TOKEN")
# Base URL for your tenant (Dev)
BASE_URL = "https://app-sod.superoffice.com/Cust55774/api/v1"
def get_token():
url = "https://sod.superoffice.com/login/common/oauth/tokens"
data = {
"grant_type": "refresh_token",
"client_id": SO_CLIENT_ID,
"client_secret": SO_CLIENT_SECRET,
"refresh_token": SO_REFRESH_TOKEN,
"redirect_uri": "http://localhost"
}
try:
resp = requests.post(url, data=data)
if resp.status_code == 200:
return resp.json().get("access_token")
else:
print(f"Token Error: {resp.text}")
return None
except Exception as e:
print(f"Connection Error: {e}")
return None
def check_contact(id):
token = get_token()
if not token: return
headers = {"Authorization": f"Bearer {token}", "Accept": "application/json"}
url = f"{BASE_URL}/Contact/{id}"
resp = requests.get(url, headers=headers)
if resp.status_code == 200:
c = resp.json()
print(f"✅ SUCCESS! Contact {id}: {c.get('Name')} (Category: {c.get('Category', {}).get('Value')})")
else:
print(f"❌ API Error {resp.status_code}: {resp.text}")
if __name__ == "__main__":
check_contact(2)