Skip to main content

Hello everyone,

I have the following problem, I have created a script to get all data about the shapes of each page from a Lucidchart document with the Lucid API. The Lucid document now has over 160 pages. The script worked as long as the Lucidchart document had fewer pages, now I get the status code 500 when requesting the contents (see the snippet of the code for the request)

....
headers <- httr::add_headers(
'Authorization' = paste('Bearer', token$credentials$access_token),
'Lucid-Api-Version' = '1'
)
.
.
.
.
response_document_content <- httr::GET(paste0("https://api.lucid.co/documents/", document_id, "/contents"), headers)

#test response
if (response_document_content$status_code == 200) {
content_document_content <- httr::content(response_document_content, type = "application/json")
} else {
cat("Request failed with status:", response_document_content$status_code, "\n")
cat(content(response_document_content, "text"), "\n")
}

To reduce the load of the request, I tried to reduce it with pagination, but without success, still receiving the status code 500 (see code below).

...
# Initialize variables for pagination
page_size <- 200 # Maximum number of records per page
page_token <- NULL # Start with no page token
all_content <- list() # To store all content

repeat {
# Build the URL with query parameters
url <- paste0("https://api.lucid.co/documents/", document_id, "/contents", "?pageSize=", page_size)
if (!is.null(page_token)) {
url <- paste0("https://api.lucid.co/documents/", document_id, "/contents", "?pageSize=", page_size, "&pageToken=", page_token)
}

# Make the request
response_document_content <- httr::GET(url, headers)

# Check response status
if (response_document_content$status_code == 200) {
content_document_content <- httr::content(response_document_content, type = "application/json")
all_content <- c(all_content, content_document_content) # Store the content

# Extract next page token from the Link header, if present
link_header <- httr::headers(response_document_content))["Link"]]
if (!is.null(link_header) && grepl("rel=\"next\"", link_header)) {
matches <- regexpr("<((^>]+)>; rel=\"next\"", link_header)
next_link <- regmatches(link_header, matches)
if (length(next_link) > 0) {
parsed_url <- httr::parse_url(next_link)
page_token <- parsed_url$query$pageToken
} else {
break # No more pages
}
} else {
break # No Link header with rel="next", end of pages
}
} else {
cat("Request failed with status:", response_document_content$status_code, "\n")
cat(httr::content(response_document_content, "text"), "\n")
break
}
}

 

Does anyone have an idea how I can solve the problem? Thanks in advance

Hi @AlexanderZ , thank you for posting in the Lucid for Developers Community and for reporting this error with your GET request to our Document Contents endpoint. As this endpoint does not support pagination, we expect this error would be resolved if the document size is reduced. I reported this to our Development team and they will investigate this issue and help identify a specific document size limit for this endpoint.

In the meantime, we recommend splitting your document with 160 pages into multiple smaller documents with fewer pages. I know it’s not ideal but I hope it allows you to continue your work. We apologize for any inconvenience caused by this issue!

Please let us know if you have any further questions or concerns, we’re here to help!


Reply