feat: Build complete POC for Butler model (client, matrix, daemon)
This commit is contained in:
@@ -2,24 +2,48 @@ import os
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv() # Lädt .env aus dem aktuellen Verzeichnis
|
||||
load_dotenv(override=True)
|
||||
|
||||
client_id = os.getenv("SO_CLIENT_ID") or os.getenv("SO_SOD")
|
||||
client_secret = os.getenv("SO_CLIENT_SECRET")
|
||||
refresh_token = os.getenv("SO_REFRESH_TOKEN")
|
||||
# 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"
|
||||
|
||||
print(f"ID: {client_id}")
|
||||
print(f"Secret: {client_secret[:5]}...")
|
||||
print(f"Token: {refresh_token[:5]}...")
|
||||
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
|
||||
|
||||
url = "https://sod.superoffice.com/login/common/oauth/tokens"
|
||||
payload = {
|
||||
"grant_type": "refresh_token",
|
||||
"client_id": client_id,
|
||||
"client_secret": client_secret,
|
||||
"refresh_token": refresh_token
|
||||
}
|
||||
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}")
|
||||
|
||||
resp = requests.post(url, data=payload)
|
||||
print(f"Status: {resp.status_code}")
|
||||
print(resp.text)
|
||||
if __name__ == "__main__":
|
||||
check_contact(2)
|
||||
|
||||
Reference in New Issue
Block a user