Actually, immediately after sending that I found a working solution. Ran from the same folder as the “example.drawio” file:
import requests
from dotenv import load_dotenv
from os import getenv
import os
def send_lucid_import_request(filename: str):
print("Sending request to create Lucid document...")
url = "https://api.lucid.app/documents"
headers = {
"Authorization": f'Bearer {getenv("LUCID_API_KEY")}',
"Lucid-Api-Version": f"{1}",
}
files = {
"file": (
os.path.basename(filename),
open(filename, "rb"),
"x-application/vnd.lucid.drawio",
),
}
data = {"title": "lucid drawio import example", "product": "Lucidchart"}
try:
response = requests.post(url=url, headers=headers, data=data, files=files)
print(response.headers)
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError as err:
print(f"-- Failure: Lucid create document request failed. Error: '{err}'")
return None
load_dotenv()
response_json = send_lucid_import_request("example.drawio")
if response_json is not None:
print(f"-- Success! Access the Lucid document at: {response_json['editUrl']}")