Businesses: the core Middesk object. Creating one starts the orders you ask for (a Business Verification report by default); the report fills in asynchronously and Middesk sends business.updated when the status changes.

Statuses: open, pending (orders running), in_audit (Middesk analysts are checking), in_review (ready for your decision), approved, rejected. Approve or reject with set-status.

Values

DONE_STATUSES

DONE_STATUSES: Vec [
  "in_review",
  "approved",
  "rejected"
]

SETTABLE_STATUSES

SETTABLE_STATUSES: Vec [
  "in_review",
  "approved",
  "rejected"
]

Functions

collect-businesses

fn (params: Map, limit: Int): Vec
fn (params: Map, limit: Int, options: Map): Vec

Up to limit businesses matching params (see list-businesses), following has_more.

Example

in-review ::middesk::businesses/collect-businesses({status: "in_review"}, 200)
map(in-review, %.id)

create-business

fn (params: Map): Map
fn (params: Map, options: Map): Map

POST /businesses - Create a business and start its orders. params:

  • name (required) and addresses (required): [{address_line1, address_line2, city, state, postal_code}] or [{full_address}] (use address_line1, not address_line_1, which Middesk ignores)
  • tin: {tin: "123410000"} (9 digits, no dash)
  • website: {url}; phone_numbers: [{phone_number}]
  • people: [{name}] or [{first_name, last_name, title}]; for KYC also dob, ssn, address fields (PII: sent in the body only)
  • external_id, unique_external_id (Middesk refuses a duplicate, so a retried create can't make a second business), tags
  • orders: [{product: "business_verification_verify"}, {product: "liens"}, ...]; omitted means a Business Verification report

Missing name or addresses is an Err and nothing is sent.

Example

biz ::middesk::businesses/create-business({
  name: "Acme Robotics LLC",
  tin: {tin: "123410000"},
  addresses: [{address_line1: "123 Main St", city: "Austin", state: "TX", postal_code: "78701"}],
  people: [{name: "Jane Doe", title: "CEO"}],
  unique_external_id: "acct-42",
  orders: [{product: "business_verification_verify"}, {product: "website"}]
})
biz.status  // "pending"

find-by-external-id

fn (external-id: Str): Map?
fn (external-id: Str, options: Map): Map?

The business (list item) with this external_id, or null. Fetch the full report with get-business.

Example

hit ::middesk::businesses/find-by-external-id("acct-42")
if(is-null(hit), "not onboarded", ::middesk::businesses/get-business(hit.id))

get-business

fn (business-id: Str): Map
fn (business-id: Str, options: Map): Map

GET /businesses/{id} - The full business report: status, review (with tasks), registrations, tin, watchlist, liens, litigations, bankruptcies, people, names, addresses, website, formation, industry_classification, orders, documents, policy_results and more. Summarize it with ::middesk::decisions/summarize.

Example

report ::middesk::businesses/get-business("biz_a1b2c3")
report.status
map(report.review.tasks, %.key)

get-latest-risk-assessment

fn (business-id: Str): Map
fn (business-id: Str, options: Map): Map

GET /businesses/{id}/risk_assessments/latest - The newest risk assessment (requires the risk product).

Example

assessment ::middesk::businesses/get-latest-risk-assessment("biz_a1b2c3")
assessment

get-pdf

fn (business-id: Str): Bytes
fn (business-id: Str, options: Map): Bytes

GET /businesses/{id}/pdf - The business report as a PDF (Bytes). It can contain TINs and people's details: store it like the report, never log it.

Example

pdf ::middesk::businesses/get-pdf("biz_a1b2c3")
if(is-err(pdf), ::middesk::api/error-status(pdf), length(pdf))

get-policy-results

fn (business-id: Str): Map
fn (business-id: Str, options: Map): Map

GET /businesses/{id}/policy_results - Results of your enabled Middesk policies for this business.

Example

results ::middesk::businesses/get-policy-results("biz_a1b2c3")
results

get-review

fn (business-id: Str): Map
fn (business-id: Str, options: Map): Map

GET /businesses/{id}/review - The review: tasks ({key, category, label, sub_label, status: success|failure|warning|neutral, message, sources}), completed_at, assignee.

Example

review ::middesk::businesses/get-review("biz_a1b2c3")
filter(review.tasks, eq(%.status, "failure"))

get-timeline

fn (business-id: Str, params: Map): Map
fn (business-id: Str, params: Map, options: Map): Map

GET /businesses/{id}/timeline - The business's audit timeline. params: page, per_page (max 100), start_date, end_date, event_types.

Example

timeline ::middesk::businesses/get-timeline("biz_a1b2c3", {per_page: 100})
timeline

is-done

fn (business: Any): Bool

True when the report is complete: status in_review, approved or rejected. Use it from a webhook handler or a schedule instead of waiting in a run.

Example

::middesk::businesses/is-done({status: "in_review"})  // true
::middesk::businesses/is-done({status: "pending"})  // false

list-businesses

fn (params: Map): Map
fn (params: Map, options: Map): Map

GET /businesses - One page of businesses (slim items, not full reports). params: page (from 1), per_page, and filters such as status, external_id, unique_external_id, tags (Vec, comma joined), start_date, end_date. Middesk's current spec lists no filters, so treat them as best effort.

Example

::middesk::businesses/list-businesses({per_page: 10, status: "in_review"})

set-status

fn (business-id: Str, status: Str): Map
fn (business-id: Str, status: Str, options: Map): Map

Record your decision on a business: "approved", "rejected", or "in_review" to reopen it. Any other value is an Err and nothing is sent.

Example

::middesk::businesses/set-status("biz_...", "approved")

update-business

fn (business-id: Str, params: Map): Map
fn (business-id: Str, params: Map, options: Map): Map

PATCH /businesses/{id} - Update name, tin, addresses, website, phone_numbers, people, external_id, unique_external_id, tags or status. Middesk allows 5 updates per 15 seconds per business.

Example

::middesk::businesses/update-business("biz_a1b2c3", {website: {url: "https://acme.example"}, tags: ["priority"]})

validate-create

fn (params: Map): Map

params (compacted) when it has a name and at least one address, otherwise an Err naming the missing fields (never their values). Exposed for testing.

Example

::middesk::businesses/validate-create({name: "Acme", addresses: [{full_address: "123 Main St, Austin, TX"}], tags: null})
// {name: "Acme", addresses: [{full_address: "123 Main St, Austin, TX"}]}

is-err(::middesk::businesses/validate-create({name: "Acme"}))  // true

verify-tin

fn (name: Str, tin: Str, address: Map): Map
fn (name: Str, tin: Str, address: Map, options: Map): Map

Create a business that runs only a TIN match (orders: [{product: "tin"}]): the IRS name/TIN check. address is required by Middesk; pass {full_address: ...} or the line fields. Read the result from tin on the business once the business.updated webhook arrives.

Example

biz ::middesk::businesses/verify-tin("Acme Robotics LLC", "12-3410000", {
  address_line1: "123 Main St", city: "Austin", state: "TX", postal_code: "78701"
})

// After the business.updated webhook
report ::middesk::businesses/get-business(biz.id)
report.tin.verified