"""BizDocs upload client.""" import logging import httpx log = logging.getLogger(__name__) def upload_document( bizdocs_url: str, api_key: str, filename: str, data: bytes, entity_id: str | None = None, ) -> str: """ Upload *data* as *filename* to the BizDocs API. Returns the remote document ID string. Raises on HTTP errors. """ url = bizdocs_url.rstrip("/") + "/documents" headers = {"Authorization": f"Bearer {api_key}"} files = {"file": (filename, data)} params = {} if entity_id: params["entity_id"] = entity_id with httpx.Client(timeout=60) as client: resp = client.post(url, headers=headers, files=files, params=params) resp.raise_for_status() body = resp.json() return str(body.get("id") or body.get("document_id") or resp.text)