Skip to main content
Solved

404 error when trying to import a drawio file to LucidChart via API


Forum|alt.badge.img+3

I try to use the import feature via API : https://lucid.readme.io/reference/createorcopyorimportdocument

But I received this error message: {
  "code": "operationRestricted",
  "message": "You are restricted from performing this operation at this time",
  "requestId": "c8ff1705c3bf7bb8",
  "details": {
    "reason": "Unable to create document from the provided template ID"
  }
}

Best answer by Michael B

Actually, immediately after sending that I found a working solution.  Ran from the same folder as the “example.drawio” file:

 

#!python
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)  # prints the entire header as a dictionary
        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


# Execution starts here
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']}")

 

View original
Did this topic help you find an answer to your question?

Richard U
Forum|alt.badge.img+8
  • Lucid support team
  • April 7, 2025

Hi ​@lnguyenduc ,  can you share the full curl request or request details you're using? Including the URL, headers, and how you're uploading the file will help me pinpoint where things might be going wrong. I’m happy to test on my end once I’ve got that info to see where the issue might be.


Forum|alt.badge.img+3
import requests
import os

# Replace with your OAuth 2.0 authentication token
API_TOKEN = "My_API_Key"

# Path to the .drawio file to import
file_path = r'My_Path'

# URL of the Lucidchart API
url = "https://api.lucid.app/documents"

# Check if the file exists
if not os.path.isfile(file_path):
    print(f"Error: The file {file_path} does not exist.")
else:
    # Request data
    files = {
        'file': (os.path.basename(file_path), open(file_path, 'rb'), 'x-application/vnd.lucid.drawio'),
    }

    data = {
        'product': 'lucidchart',  # Indicate that we are importing a file for Lucidchart
        'title': 'Imported Document',  # Title of the imported document
        'parent': '1234'  # Parent ID if you want to attach this document to a specific folder (optional)
    }

    # Request headers
    headers = {
        'Authorization': f'Bearer {API_TOKEN}',
        'Lucid-Api-Version': '1'
    }

    # Send the POST request to import the file
    response = requests.post(url, headers=headers, files=files, data=data)

    # Check the response
    if response.status_code == 200:
        print("File successfully imported into Lucidchart.")
        print("API response:", response.json())
    elif response.status_code == 403:
        print("Error: Access to this resource is forbidden. Please check your API token and permissions.")
    else:
        print(f"Error importing the file: {response.status_code}")
        print(response.text)

 


Michael B
Forum|alt.badge.img+4
  • Lucid product team
  • April 7, 2025

Thank you Inguyenduc,

In the logs, I see the following error: `Failed to find a document account: 3fa85f64-5717-4562-b3fc-2c963f66afa6`.  I am investigating further what is causing this error, but does the document mean anything to you?  Can you try accessing the document with that ID and see if you have access.


Forum|alt.badge.img+3

I'm just trying to simply import a drawio file from my local workstation to LucidChart using the script. It works if I do it manually but not with the script. I just attached the drawio file.


Michael B
Forum|alt.badge.img+4
  • Lucid product team
  • April 7, 2025

Any request to the Lucid Public API includes a `requestId` or `flowId` in the response headers. For the original post, that value is `c8ff1705c3bf7bb8`.

For that request, the request didn’t have the correct format such that file type was read correctly. It erroneously believed that the request was a basic “create document”. Given how odd our “import document” request requirements are, this is not unusual. If the request was made via our documentation, I don’t think it supported at all. We hope to provide an alternative easier to use version in the future.

For subsequent requests made via python, can you capture the `x-lucid-flow-id` header from the response and provide it?  I am currently testing the draw.io import via API as well.

 


Michael B
Forum|alt.badge.img+4
  • Lucid product team
  • April 7, 2025

Actually, immediately after sending that I found a working solution.  Ran from the same folder as the “example.drawio” file:

 

#!python
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)  # prints the entire header as a dictionary
        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


# Execution starts here
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']}")

 


Reply