Documents: Secretary of State filings, certificates of good standing,
UCC documents and other files Middesk retrieved for a business. A
document carries metadata and a signed, expiring download_url;
download-document fetches the bytes. The signed URL grants access
without a key: never log it. For the full report as a PDF, use
::middesk::businesses/get-pdf.
Functions
download-document
fn (document-id: Str): Bytes
fn (document-id: Str, options: Map): Bytes
Download a document's file as Bytes: asks Middesk for a fresh
signed URL, then fetches it without the API key.
Example
docs ::middesk::documents/list-documents("biz_...")
pdf ::middesk::documents/download-document(first(docs.data).id)
fetch-signed-url
fn (url: Any): Bytes
GET a signed URL with no credentials and return its Bytes. Only
https:// URLs are fetched; on failure the Err says only the HTTP
status, never the URL. Exposed for testing.
Example
link ::middesk::documents/get-download-url("doc_d4e5f6")
pdf ::middesk::documents/fetch-signed-url(link.data)
if(is-err(pdf), "download failed", length(pdf))
get-document
fn (document-id: Str): Map
fn (document-id: Str, options: Map): Map
GET /documents/{id} - Retrieve one document's metadata.
Example
doc ::middesk::documents/get-document("doc_d4e5f6")
doc.filename
get-download-url
fn (document-id: Str): Map
fn (document-id: Str, options: Map): Map
GET /documents/{id}/download_url - A fresh signed URL for the file
({data: "<url>"}). Treat it as a secret.
Example
link ::middesk::documents/get-download-url("doc_d4e5f6")
::middesk::documents/fetch-signed-url(link.data)
list-documents
fn (business-id: Str): Map
fn (business-id: Str, options: Map): Map
GET /businesses/{id}/documents - A business's documents: {object: "list", data: [{id, document_type, filename, content_type, size, filing_date, ...}]}.
Example
docs ::middesk::documents/list-documents("biz_a1b2c3")
map(docs.data, %.filename)
metadata
fn (document: Map): Map
A document's metadata without its signed URL: {id, document_type, filename, content_type, size, filing_date, created_at}. Safe to log or
hand to an LLM. Exposed for testing.
Example
::middesk::documents/metadata({id: "doc_1", filename: "cert.pdf", size: 1024, download_url: "https://files.example/signed"})
// {id: "doc_1", filename: "cert.pdf", size: 1024}