Skip to content

Code Snippets

These examples show how to call the RealityConnect API from Python using the Client Credentials flow. Each snippet is self-contained: copy it into a .py file, set your credentials and resource IDs, then run it with python your_script.py.


Every snippet below starts from this block. It authenticates with client credentials, resolves your regional API URL, and defines thin HTTP helpers.

import base64
import json
import math
import os
import requests
CLIENT_ID = "your-client-id"
CLIENT_SECRET = "your-client-secret"
CLOUD_API_BASE = "https://cloud-api.prevu3d.com"
credentials = base64.b64encode(f"{CLIENT_ID}:{CLIENT_SECRET}".encode()).decode()
token_response = requests.post(
f"{CLOUD_API_BASE}/oauth/token",
data={"grant_type": "client_credentials"},
headers={"Authorization": f"Basic {credentials}"},
)
token_response.raise_for_status()
access_token = token_response.json()["access_token"]
api_info_response = requests.get(
f"{CLOUD_API_BASE}/oauth/api-info",
headers={"Authorization": f"Bearer {access_token}"},
)
api_info_response.raise_for_status()
api_info = api_info_response.json()
API_URL = api_info["apiUrl"].rstrip("/")
ORGANIZATION_ID = api_info["organization"]["id"]
HEADERS = {"Authorization": f"Bearer {access_token}"}
def api_get(path: str, params: dict | None = None) -> dict:
response = requests.get(f"{API_URL}{path}", headers=HEADERS, params=params)
response.raise_for_status()
return response.json()
def api_post(path: str, body: dict) -> dict | None:
response = requests.post(f"{API_URL}{path}", json=body, headers=HEADERS)
response.raise_for_status()
if response.status_code == 204:
return None
return response.json()
def api_patch(path: str, body: dict) -> dict:
response = requests.patch(f"{API_URL}{path}", json=body, headers=HEADERS)
response.raise_for_status()
return response.json()
def api_delete(path: str) -> None:
response = requests.delete(f"{API_URL}{path}", headers=HEADERS)
response.raise_for_status()