> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.tradeguardins.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.tradeguardins.com/_mcp/server.

# Upload a document (multipart)

POST https://api.tradeguardins.com/v1/subcontractors/{subcontractorId}/documents
Content-Type: multipart/form-data

Upload path 1 of 3: send the file as `multipart/form-data`.

Accepted categories: `insurance`, `license`, `background_check`,
`training_cert`, `tax_form`, `agreement`, `endorsement`,
`workers_compensation_exemption`, `safety_policy` (`business_registration`,
`notice_of_cancellation` and `certificate` are rejected with `400`).

**Other documents (W-9, OSHA card, First Aid, …).** Every category but
`insurance`, `endorsement`, `license` and `background_check` is read by AI, which checks the file really
is that kind of document and reads who it is issued to, its dates and its
key fields (a W-9's TIN is kept as its last 4 digits only). Name the kind
in `documentType` (see `DocumentType`). It is required for
`training_cert` (`osha_card`, `first_aid_cpr`, `lift_safety`) and
defaults for the rest. `license` and `background_check` files are
stored only: kept on file, never read by AI, and the document stays
`lifecycleStatus: uploaded`. Licenses are checked against state records
by a license report requirement (`reportSource: tradesapi_license`);
background checks will run through the background check API. For a
`background_check` file, `documentType` may be left out; the former
values `level_2_screening` and `background_check` are still accepted
and kept as a label. A new document replaces the active one of the same kind only, so an
OSHA card and a First Aid card can both be on file. A document that
doesn't look like the kind it was uploaded as, or that the AI reads with
low confidence, is held for TradeGuard review instead of counting.
Use `endorsement` for endorsement pages sent separately from the
certificate (CG 20 10, CG 24 04, IL 80 01 and so on): they are read like
pages attached to a certificate, count toward the subcontractor's
endorsement and notice-of-cancellation requirements alongside its
certificate, and those requirements are re-checked once the file is read.
Allowed file types: `application/pdf`, `image/png`, `image/jpeg`,
`image/jpg`, `image/webp`, `image/heic`, `image/heif`, `image/tiff`; at
most 25 MiB; not empty. The file's contents must match its declared
type (a PDF must start with `%PDF-`, a PNG with the PNG signature, and
so on), or the upload is rejected with `400`. A file containing the
EICAR anti-malware test string is rejected with `422`. The file name is
kept on the document as sent but is reduced to safe characters in the
storage key.

By default the document becomes `active`, and the validation +
extraction workflow starts in the background — the response does not
wait for it. A `document.uploaded` event is published on the
organization's event stream.

The document replaces (`superseded`) the earlier active document of the
same category for this subcontractor and organization only **once it
has been read**: validation and extraction passed (for a certificate,
when its coverage is written; a certificate held for review replaces it
once the review approves it). An upload that fails validation or
extraction never replaces anything: when another document of its
category is active it becomes `inactive`, and the earlier document
stays the one judged. Until then both documents are `active`. A
replaced document's open review is closed: its pending review is
dismissed, the coverages it held for review become `inactive`, and its
`coverage_flag` issue closes with the reason "Replaced by a newer
document". `license` and `background_check` files are never read, so
they replace the earlier one right away.

Send `activate=false` to stage the document instead: it is stored as
`inactive`, nothing is superseded and **no** validation or extraction runs
(activating it later does not start one either — use
[Extract](https://docs.tradeguardins.com/api-reference/documents/extract-document)).

Bytes identical to a document already on file for this subcontractor
under your organization (in any status, including a staged one) return
**200** with the existing document and `duplicate: true`, and create
nothing. There is no option to upload the same bytes twice; to
re-process the existing document, call
[Extract](https://docs.tradeguardins.com/api-reference/documents/extract-document).
One exception: if that document had been read and was later replaced
by uploads that couldn't be read (no newer document of its category
has been read since), it becomes `active` again, those unread uploads
become `inactive`, its requirements are re-checked, and the response
also carries `restored: true`.
Another: if the existing document's last read failed
(`lifecycleStatus` `validation_failed` or `extraction_failed`), the
re-upload starts reading it again, the same as
[Extract](https://docs.tradeguardins.com/api-reference/documents/extract-document)
(and counted against the same re-extraction limit), and the response
also carries `rereading: true`.

**Project certificates.** Send `projectId` (or your own job number as
`projectExternalId`) to file the upload as the subcontractor's
project-specific COI for that project instead of a baseline document.
It must be an `insurance` certificate and the subcontractor must have a
live assignment on the project (`409` otherwise). The document is created
with `scope: project` and filed to the assignment's `project_coi` slot,
returned as `projectDocument` (status `received_pending_review`).
A project certificate is evidence for that job only: it never becomes the
subcontractor's baseline coverage, never supersedes the baseline COI and is
never sent to the broker for verification. Duplicate detection is per
project.

Requires scope `documents:write`.

Reference: https://docs.tradeguardins.com/api-reference/documents/upload-document

## Authentication

- `Authorization` header (bearer token, required) — Session JWT or API key (`ak_...`)

## Request

### Path parameters

- `subcontractorId` (string, required)

### Body (multipart/form-data)

This endpoint expects a multipart form containing a file.

- `file` (file, required) — The file to upload
- `documentCategory` (enum, required) — Accepted categories: `insurance`, `license`, `background_check`, `training_cert`, `tax_form`, `agreement`, `endorsement`, `workers_compensation_exemption`, `safety_policy` (`business_registration`, `notice_of_cancellation` and `certificate` are rejected with `400`).
- `documentType` (enum, optional)
- `documentLabel` (string, optional)
- `metadata` (string, optional) — JSON object of at most 16 KB, as a string (`400` if it is not valid JSON, not an object, or too large).
- `activate` (enum, optional) — Only the exact string `"false"` stages the document (`status: inactive`, no processing).
- `projectId` (string, optional) — File this certificate to the subcontractor's assignment on this project (a project-specific COI). Not with `projectExternalId`.
- `projectExternalId` (string, optional) — Same as `projectId`, identifying the project by its `externalId` (your job number).
- `submittedByEmail` (string, optional) — The email address that sent you this document, when it came from someone else (for example the broker who emailed it to you). When it is the subcontractor's broker on file, its policies count as verified by the broker (`verifiedBy: broker_sent_coi`) and no verification call is placed. An address that isn't on file yet (including one that only matches the producer printed on this certificate) goes to TradeGuard staff to confirm.

## Response

### 200

Byte-identical document already on file; nothing created

- `data` (DuplicateDocumentResponseData, required)
- `message` (string, required)

### 201

Document uploaded

- `data` (V1SubcontractorsSubcontractorIdDocumentsPostResponsesContentApplicationJsonSchemaData, optional)

## Errors

### 400 Bad Request Error

Malformed request (`bad_request`, `invalid_identifier`)

- `error` (string, required) — Human-readable message. Wording may change; do not parse it.
- `code` (enum, required) — Stable, machine-readable error code. Status-level codes: `bad_request` (400), `unauthenticated` (401), `forbidden` (403), `not_found` (404), `method_not_allowed` (405, with an `Allow` header), `conflict` (409), `gone` (410), `payload_too_large` (413), `unprocessable` (422), `rate_limited` (429), `internal_error` (500), `bad_gateway` (502), `service_unavailable` (503). Specific codes: `validation_failed` and `invalid_identifier` (400); `reextraction_limit_reached` and `llm_budget_exhausted` (429, document re-extraction only); `sandbox_unavailable` (503, a sandbox key used where the sandbox is not provisioned); `assignment_exists` (409, a live assignment for this subcontractor and project already exists — its id is in `details`), `project_not_ready` (409, the project's setup is not Ready), `project_document` (409, a baseline-only action on a project certificate) and `subcontractor_match` (409, a new subcontractor's email or phone matches one already on TradeGuard — its id is in `details`); `portal_link_expired` and `portal_link_used` (410, sub portal links only).
  - Allowed values: `bad_request`, `unauthenticated`, `forbidden`, `not_found`, `method_not_allowed`, `conflict`, `gone`, `payload_too_large`, `unprocessable`, `rate_limited`, `internal_error`, `bad_gateway`, `service_unavailable`, `validation_failed`, `invalid_identifier`, `reextraction_limit_reached`, `llm_budget_exhausted`, `sandbox_unavailable`, `assignment_exists`, `project_not_ready`, `project_document`, `subcontractor_match`, `portal_link_expired`, `portal_link_used`
- `requestId` (string, optional) — Same value as the `x-request-id` response header.
- `details` (list of ErrorDetailsItems, optional) — Present when `code` is `validation_failed`.

### 401 Unauthorized Error

Missing, malformed, expired or revoked credential (`unauthenticated`)

- `error` (string, required) — Human-readable message. Wording may change; do not parse it.
- `code` (enum, required) — Stable, machine-readable error code. Status-level codes: `bad_request` (400), `unauthenticated` (401), `forbidden` (403), `not_found` (404), `method_not_allowed` (405, with an `Allow` header), `conflict` (409), `gone` (410), `payload_too_large` (413), `unprocessable` (422), `rate_limited` (429), `internal_error` (500), `bad_gateway` (502), `service_unavailable` (503). Specific codes: `validation_failed` and `invalid_identifier` (400); `reextraction_limit_reached` and `llm_budget_exhausted` (429, document re-extraction only); `sandbox_unavailable` (503, a sandbox key used where the sandbox is not provisioned); `assignment_exists` (409, a live assignment for this subcontractor and project already exists — its id is in `details`), `project_not_ready` (409, the project's setup is not Ready), `project_document` (409, a baseline-only action on a project certificate) and `subcontractor_match` (409, a new subcontractor's email or phone matches one already on TradeGuard — its id is in `details`); `portal_link_expired` and `portal_link_used` (410, sub portal links only).
  - Allowed values: `bad_request`, `unauthenticated`, `forbidden`, `not_found`, `method_not_allowed`, `conflict`, `gone`, `payload_too_large`, `unprocessable`, `rate_limited`, `internal_error`, `bad_gateway`, `service_unavailable`, `validation_failed`, `invalid_identifier`, `reextraction_limit_reached`, `llm_budget_exhausted`, `sandbox_unavailable`, `assignment_exists`, `project_not_ready`, `project_document`, `subcontractor_match`, `portal_link_expired`, `portal_link_used`
- `requestId` (string, optional) — Same value as the `x-request-id` response header.
- `details` (list of ErrorDetailsItems, optional) — Present when `code` is `validation_failed`.

### 403 Forbidden Error

The credential lacks the scope or role for this action (`forbidden`)

- `error` (string, required) — Human-readable message. Wording may change; do not parse it.
- `code` (enum, required) — Stable, machine-readable error code. Status-level codes: `bad_request` (400), `unauthenticated` (401), `forbidden` (403), `not_found` (404), `method_not_allowed` (405, with an `Allow` header), `conflict` (409), `gone` (410), `payload_too_large` (413), `unprocessable` (422), `rate_limited` (429), `internal_error` (500), `bad_gateway` (502), `service_unavailable` (503). Specific codes: `validation_failed` and `invalid_identifier` (400); `reextraction_limit_reached` and `llm_budget_exhausted` (429, document re-extraction only); `sandbox_unavailable` (503, a sandbox key used where the sandbox is not provisioned); `assignment_exists` (409, a live assignment for this subcontractor and project already exists — its id is in `details`), `project_not_ready` (409, the project's setup is not Ready), `project_document` (409, a baseline-only action on a project certificate) and `subcontractor_match` (409, a new subcontractor's email or phone matches one already on TradeGuard — its id is in `details`); `portal_link_expired` and `portal_link_used` (410, sub portal links only).
  - Allowed values: `bad_request`, `unauthenticated`, `forbidden`, `not_found`, `method_not_allowed`, `conflict`, `gone`, `payload_too_large`, `unprocessable`, `rate_limited`, `internal_error`, `bad_gateway`, `service_unavailable`, `validation_failed`, `invalid_identifier`, `reextraction_limit_reached`, `llm_budget_exhausted`, `sandbox_unavailable`, `assignment_exists`, `project_not_ready`, `project_document`, `subcontractor_match`, `portal_link_expired`, `portal_link_used`
- `requestId` (string, optional) — Same value as the `x-request-id` response header.
- `details` (list of ErrorDetailsItems, optional) — Present when `code` is `validation_failed`.

### 404 Not Found Error

Resource not found, or not visible to the caller's organization (`not_found`)

- `error` (string, required) — Human-readable message. Wording may change; do not parse it.
- `code` (enum, required) — Stable, machine-readable error code. Status-level codes: `bad_request` (400), `unauthenticated` (401), `forbidden` (403), `not_found` (404), `method_not_allowed` (405, with an `Allow` header), `conflict` (409), `gone` (410), `payload_too_large` (413), `unprocessable` (422), `rate_limited` (429), `internal_error` (500), `bad_gateway` (502), `service_unavailable` (503). Specific codes: `validation_failed` and `invalid_identifier` (400); `reextraction_limit_reached` and `llm_budget_exhausted` (429, document re-extraction only); `sandbox_unavailable` (503, a sandbox key used where the sandbox is not provisioned); `assignment_exists` (409, a live assignment for this subcontractor and project already exists — its id is in `details`), `project_not_ready` (409, the project's setup is not Ready), `project_document` (409, a baseline-only action on a project certificate) and `subcontractor_match` (409, a new subcontractor's email or phone matches one already on TradeGuard — its id is in `details`); `portal_link_expired` and `portal_link_used` (410, sub portal links only).
  - Allowed values: `bad_request`, `unauthenticated`, `forbidden`, `not_found`, `method_not_allowed`, `conflict`, `gone`, `payload_too_large`, `unprocessable`, `rate_limited`, `internal_error`, `bad_gateway`, `service_unavailable`, `validation_failed`, `invalid_identifier`, `reextraction_limit_reached`, `llm_budget_exhausted`, `sandbox_unavailable`, `assignment_exists`, `project_not_ready`, `project_document`, `subcontractor_match`, `portal_link_expired`, `portal_link_used`
- `requestId` (string, optional) — Same value as the `x-request-id` response header.
- `details` (list of ErrorDetailsItems, optional) — Present when `code` is `validation_failed`.

### 409 Conflict Error

Conflicts with the resource's current state (`conflict`)

- `error` (string, required) — Human-readable message. Wording may change; do not parse it.
- `code` (enum, required) — Stable, machine-readable error code. Status-level codes: `bad_request` (400), `unauthenticated` (401), `forbidden` (403), `not_found` (404), `method_not_allowed` (405, with an `Allow` header), `conflict` (409), `gone` (410), `payload_too_large` (413), `unprocessable` (422), `rate_limited` (429), `internal_error` (500), `bad_gateway` (502), `service_unavailable` (503). Specific codes: `validation_failed` and `invalid_identifier` (400); `reextraction_limit_reached` and `llm_budget_exhausted` (429, document re-extraction only); `sandbox_unavailable` (503, a sandbox key used where the sandbox is not provisioned); `assignment_exists` (409, a live assignment for this subcontractor and project already exists — its id is in `details`), `project_not_ready` (409, the project's setup is not Ready), `project_document` (409, a baseline-only action on a project certificate) and `subcontractor_match` (409, a new subcontractor's email or phone matches one already on TradeGuard — its id is in `details`); `portal_link_expired` and `portal_link_used` (410, sub portal links only).
  - Allowed values: `bad_request`, `unauthenticated`, `forbidden`, `not_found`, `method_not_allowed`, `conflict`, `gone`, `payload_too_large`, `unprocessable`, `rate_limited`, `internal_error`, `bad_gateway`, `service_unavailable`, `validation_failed`, `invalid_identifier`, `reextraction_limit_reached`, `llm_budget_exhausted`, `sandbox_unavailable`, `assignment_exists`, `project_not_ready`, `project_document`, `subcontractor_match`, `portal_link_expired`, `portal_link_used`
- `requestId` (string, optional) — Same value as the `x-request-id` response header.
- `details` (list of ErrorDetailsItems, optional) — Present when `code` is `validation_failed`.

### 413 Content Too Large Error

The file exceeds the 25 MiB (26,214,400-byte) limit (`payload_too_large`)

- `error` (string, required) — Human-readable message. Wording may change; do not parse it.
- `code` (enum, required) — Stable, machine-readable error code. Status-level codes: `bad_request` (400), `unauthenticated` (401), `forbidden` (403), `not_found` (404), `method_not_allowed` (405, with an `Allow` header), `conflict` (409), `gone` (410), `payload_too_large` (413), `unprocessable` (422), `rate_limited` (429), `internal_error` (500), `bad_gateway` (502), `service_unavailable` (503). Specific codes: `validation_failed` and `invalid_identifier` (400); `reextraction_limit_reached` and `llm_budget_exhausted` (429, document re-extraction only); `sandbox_unavailable` (503, a sandbox key used where the sandbox is not provisioned); `assignment_exists` (409, a live assignment for this subcontractor and project already exists — its id is in `details`), `project_not_ready` (409, the project's setup is not Ready), `project_document` (409, a baseline-only action on a project certificate) and `subcontractor_match` (409, a new subcontractor's email or phone matches one already on TradeGuard — its id is in `details`); `portal_link_expired` and `portal_link_used` (410, sub portal links only).
  - Allowed values: `bad_request`, `unauthenticated`, `forbidden`, `not_found`, `method_not_allowed`, `conflict`, `gone`, `payload_too_large`, `unprocessable`, `rate_limited`, `internal_error`, `bad_gateway`, `service_unavailable`, `validation_failed`, `invalid_identifier`, `reextraction_limit_reached`, `llm_budget_exhausted`, `sandbox_unavailable`, `assignment_exists`, `project_not_ready`, `project_document`, `subcontractor_match`, `portal_link_expired`, `portal_link_used`
- `requestId` (string, optional) — Same value as the `x-request-id` response header.
- `details` (list of ErrorDetailsItems, optional) — Present when `code` is `validation_failed`.

### 422 Unprocessable Entity Error

Well-formed but rejected by a business rule (`unprocessable`)

- `error` (string, required) — Human-readable message. Wording may change; do not parse it.
- `code` (enum, required) — Stable, machine-readable error code. Status-level codes: `bad_request` (400), `unauthenticated` (401), `forbidden` (403), `not_found` (404), `method_not_allowed` (405, with an `Allow` header), `conflict` (409), `gone` (410), `payload_too_large` (413), `unprocessable` (422), `rate_limited` (429), `internal_error` (500), `bad_gateway` (502), `service_unavailable` (503). Specific codes: `validation_failed` and `invalid_identifier` (400); `reextraction_limit_reached` and `llm_budget_exhausted` (429, document re-extraction only); `sandbox_unavailable` (503, a sandbox key used where the sandbox is not provisioned); `assignment_exists` (409, a live assignment for this subcontractor and project already exists — its id is in `details`), `project_not_ready` (409, the project's setup is not Ready), `project_document` (409, a baseline-only action on a project certificate) and `subcontractor_match` (409, a new subcontractor's email or phone matches one already on TradeGuard — its id is in `details`); `portal_link_expired` and `portal_link_used` (410, sub portal links only).
  - Allowed values: `bad_request`, `unauthenticated`, `forbidden`, `not_found`, `method_not_allowed`, `conflict`, `gone`, `payload_too_large`, `unprocessable`, `rate_limited`, `internal_error`, `bad_gateway`, `service_unavailable`, `validation_failed`, `invalid_identifier`, `reextraction_limit_reached`, `llm_budget_exhausted`, `sandbox_unavailable`, `assignment_exists`, `project_not_ready`, `project_document`, `subcontractor_match`, `portal_link_expired`, `portal_link_used`
- `requestId` (string, optional) — Same value as the `x-request-id` response header.
- `details` (list of ErrorDetailsItems, optional) — Present when `code` is `validation_failed`.

### 429 Too Many Requests Error

Rate limit exceeded (`rate_limited`); retry after `Retry-After` seconds

- `error` (string, required) — Human-readable message. Wording may change; do not parse it.
- `code` (enum, required) — Stable, machine-readable error code. Status-level codes: `bad_request` (400), `unauthenticated` (401), `forbidden` (403), `not_found` (404), `method_not_allowed` (405, with an `Allow` header), `conflict` (409), `gone` (410), `payload_too_large` (413), `unprocessable` (422), `rate_limited` (429), `internal_error` (500), `bad_gateway` (502), `service_unavailable` (503). Specific codes: `validation_failed` and `invalid_identifier` (400); `reextraction_limit_reached` and `llm_budget_exhausted` (429, document re-extraction only); `sandbox_unavailable` (503, a sandbox key used where the sandbox is not provisioned); `assignment_exists` (409, a live assignment for this subcontractor and project already exists — its id is in `details`), `project_not_ready` (409, the project's setup is not Ready), `project_document` (409, a baseline-only action on a project certificate) and `subcontractor_match` (409, a new subcontractor's email or phone matches one already on TradeGuard — its id is in `details`); `portal_link_expired` and `portal_link_used` (410, sub portal links only).
  - Allowed values: `bad_request`, `unauthenticated`, `forbidden`, `not_found`, `method_not_allowed`, `conflict`, `gone`, `payload_too_large`, `unprocessable`, `rate_limited`, `internal_error`, `bad_gateway`, `service_unavailable`, `validation_failed`, `invalid_identifier`, `reextraction_limit_reached`, `llm_budget_exhausted`, `sandbox_unavailable`, `assignment_exists`, `project_not_ready`, `project_document`, `subcontractor_match`, `portal_link_expired`, `portal_link_used`
- `requestId` (string, optional) — Same value as the `x-request-id` response header.
- `details` (list of ErrorDetailsItems, optional) — Present when `code` is `validation_failed`.

### 500 Internal Server Error

Unexpected server error (`internal_error`); safe to retry idempotent requests

- `error` (string, required) — Human-readable message. Wording may change; do not parse it.
- `code` (enum, required) — Stable, machine-readable error code. Status-level codes: `bad_request` (400), `unauthenticated` (401), `forbidden` (403), `not_found` (404), `method_not_allowed` (405, with an `Allow` header), `conflict` (409), `gone` (410), `payload_too_large` (413), `unprocessable` (422), `rate_limited` (429), `internal_error` (500), `bad_gateway` (502), `service_unavailable` (503). Specific codes: `validation_failed` and `invalid_identifier` (400); `reextraction_limit_reached` and `llm_budget_exhausted` (429, document re-extraction only); `sandbox_unavailable` (503, a sandbox key used where the sandbox is not provisioned); `assignment_exists` (409, a live assignment for this subcontractor and project already exists — its id is in `details`), `project_not_ready` (409, the project's setup is not Ready), `project_document` (409, a baseline-only action on a project certificate) and `subcontractor_match` (409, a new subcontractor's email or phone matches one already on TradeGuard — its id is in `details`); `portal_link_expired` and `portal_link_used` (410, sub portal links only).
  - Allowed values: `bad_request`, `unauthenticated`, `forbidden`, `not_found`, `method_not_allowed`, `conflict`, `gone`, `payload_too_large`, `unprocessable`, `rate_limited`, `internal_error`, `bad_gateway`, `service_unavailable`, `validation_failed`, `invalid_identifier`, `reextraction_limit_reached`, `llm_budget_exhausted`, `sandbox_unavailable`, `assignment_exists`, `project_not_ready`, `project_document`, `subcontractor_match`, `portal_link_expired`, `portal_link_used`
- `requestId` (string, optional) — Same value as the `x-request-id` response header.
- `details` (list of ErrorDetailsItems, optional) — Present when `code` is `validation_failed`.

## Types

### DuplicateDocumentResponseData

- `duplicate` (boolean, required)
- `documentId` (string, required, deprecated) — Same as `id`. Kept for older clients.
- `id` (string, optional)
- `subcontractorId` (string, optional)
- `organizationId` (string, optional, nullable)
- `fileName` (string, optional)
- `mimeType` (string, optional)
- `fileSize` (integer, optional) — Bytes. 0 until a presigned upload is confirmed.
- `sourceUrl` (string, optional, nullable)
- `status` (enum, optional)
  - Allowed values: `inactive`, `active`, `superseded`, `archived`
- `lifecycleStatus` (enum, optional) — `needs_review` = held for human review by TradeGuard's operations team (low extraction confidence or a name mismatch; there is no API call to resolve it); `review_rejected` = the review was rejected and processing stopped (the document is archived). An approved document returns to `extracted` and continues.
  - Allowed values: `uploaded`, `validating`, `validation_failed`, `extracting`, `extraction_failed`, `extracted`, `verifying`, `verified`, `verification_failed`, `needs_review`, `review_rejected`
- `documentCategory` (enum, optional) — Category of a document or of the evidence a requirement asks for. The three upload paths accept every value except `business_registration` (used by report requirements), `notice_of_cancellation` and `certificate` (the profile's "Certificate checks" requirement, which reads the insurance certificate).
  - Allowed values: `insurance`, `business_registration`, `license`, `background_check`, `training_cert`, `tax_form`, `agreement`, `endorsement`, `notice_of_cancellation`, `workers_compensation_exemption`, `certificate`, `safety_policy`
- `documentLabel` (string, optional, nullable)
- `uploadedBy` (string, optional, nullable) — Clerk user id or API key subject.
- `insuredName` (string, optional, nullable) — Insured name from the extracted certificate.
- `contentSha256` (string, optional, nullable) — Hex SHA-256 of the file bytes; null on an unconfirmed presign placeholder.
- `scope` (enum, optional) — `baseline`: evidence for the subcontractor's roster compliance. `project`: a project-specific certificate filed to a project slot — never baseline coverage.
  - Allowed values: `baseline`, `project`
- `projectId` (string, optional, nullable) — The project a `project`-scope certificate belongs to; null for baseline documents.
- `metadata` (DuplicateDocumentResponseDataMetadata, optional) — Free-form. May carry `presignPending` (unconfirmed presign placeholder) and `crossOrgDuplicateOfDocumentId`.
- `createdAt` (datetime, optional)
- `updatedAt` (datetime, optional)
- `restored` (boolean, optional) — Present when the existing document had been replaced by uploads that couldn't be read and this re-upload made it `active` again (its requirements are re-checked).
- `rereading` (boolean, optional) — Present when the existing document's last read failed (`validation_failed` or `extraction_failed`) and this re-upload started reading it again. Results land on the document record as with a new upload.

### V1SubcontractorsSubcontractorIdDocumentsPostResponsesContentApplicationJsonSchemaData

- `id` (string, optional)
- `subcontractorId` (string, optional)
- `organizationId` (string, optional, nullable)
- `fileName` (string, optional)
- `mimeType` (string, optional)
- `fileSize` (integer, optional) — Bytes. 0 until a presigned upload is confirmed.
- `sourceUrl` (string, optional, nullable)
- `status` (enum, optional)
  - Allowed values: `inactive`, `active`, `superseded`, `archived`
- `lifecycleStatus` (enum, optional) — `needs_review` = held for human review by TradeGuard's operations team (low extraction confidence or a name mismatch; there is no API call to resolve it); `review_rejected` = the review was rejected and processing stopped (the document is archived). An approved document returns to `extracted` and continues.
  - Allowed values: `uploaded`, `validating`, `validation_failed`, `extracting`, `extraction_failed`, `extracted`, `verifying`, `verified`, `verification_failed`, `needs_review`, `review_rejected`
- `documentCategory` (enum, optional) — Category of a document or of the evidence a requirement asks for. The three upload paths accept every value except `business_registration` (used by report requirements), `notice_of_cancellation` and `certificate` (the profile's "Certificate checks" requirement, which reads the insurance certificate).
  - Allowed values: `insurance`, `business_registration`, `license`, `background_check`, `training_cert`, `tax_form`, `agreement`, `endorsement`, `notice_of_cancellation`, `workers_compensation_exemption`, `certificate`, `safety_policy`
- `documentLabel` (string, optional, nullable)
- `uploadedBy` (string, optional, nullable) — Clerk user id or API key subject.
- `insuredName` (string, optional, nullable) — Insured name from the extracted certificate.
- `contentSha256` (string, optional, nullable) — Hex SHA-256 of the file bytes; null on an unconfirmed presign placeholder.
- `scope` (enum, optional) — `baseline`: evidence for the subcontractor's roster compliance. `project`: a project-specific certificate filed to a project slot — never baseline coverage.
  - Allowed values: `baseline`, `project`
- `projectId` (string, optional, nullable) — The project a `project`-scope certificate belongs to; null for baseline documents.
- `metadata` (V1SubcontractorsSubcontractorIdDocumentsPostResponsesContentApplicationJsonSchemaDataMetadata, optional) — Free-form. May carry `presignPending` (unconfirmed presign placeholder) and `crossOrgDuplicateOfDocumentId`.
- `createdAt` (datetime, optional)
- `updatedAt` (datetime, optional)
- `projectDocument` (V1SubcontractorsSubcontractorIdDocumentsPostResponsesContentApplicationJsonSchemaDataProjectDocument, optional) — Present for a project certificate — the slot it was filed to.

### ErrorDetailsItems

- `path` (string, optional)
- `message` (string, optional)

### DuplicateDocumentResponseDataMetadata

Free-form. May carry `presignPending` (unconfirmed presign placeholder) and `crossOrgDuplicateOfDocumentId`.

### V1SubcontractorsSubcontractorIdDocumentsPostResponsesContentApplicationJsonSchemaDataMetadata

Free-form. May carry `presignPending` (unconfirmed presign placeholder) and `crossOrgDuplicateOfDocumentId`.

### V1SubcontractorsSubcontractorIdDocumentsPostResponsesContentApplicationJsonSchemaDataProjectDocument

Present for a project certificate — the slot it was filed to.

- `id` (string, optional)
- `assignmentId` (string, optional, nullable)
- `documentType` (enum, optional) — `project_contract` is reserved for a later release and never returned today.
  - Allowed values: `project_coi`, `endorsement`, `other_exhibit`, `project_contract`
- `status` (enum, optional) — Blocking: `requested`, `non_compliant`, `expired`. Satisfied: `compliant`, `waived` (the GC accepted the gap).
  - Allowed values: `requested`, `received_pending_review`, `compliant`, `non_compliant`, `expired`, `superseded`, `waived`

## Examples

### Example 1

**Request**

```json
{
  "documentCategory": "insurance",
  "file": "<file: string>"
}
```

**Response**

```json
{
  "data": {
    "duplicate": true,
    "documentId": "string",
    "id": "string",
    "subcontractorId": "string",
    "organizationId": "string",
    "fileName": "string",
    "mimeType": "string",
    "fileSize": 1,
    "sourceUrl": "string",
    "status": "inactive",
    "lifecycleStatus": "uploaded",
    "documentCategory": "insurance",
    "documentLabel": "string",
    "uploadedBy": "string",
    "insuredName": "string",
    "contentSha256": "string",
    "scope": "baseline",
    "projectId": "string",
    "metadata": {},
    "createdAt": "2024-01-15T09:30:00Z",
    "updatedAt": "2024-01-15T09:30:00Z",
    "restored": true,
    "rereading": true
  },
  "message": "This exact document was already uploaded for this subcontractor; the existing document is returned. To re-process it, call POST /v1/subcontractors/{subcontractorId}/documents/{documentId}/extract."
}
```

**SDK Code**

```python
import requests

url = "https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents"

files = { "file": "open('string', 'rb')" }
payload = {
    "activate": ,
    "documentCategory": "insurance",
    "documentLabel": ,
    "documentType": ,
    "metadata": ,
    "projectExternalId": ,
    "projectId": ,
    "submittedByEmail": 
}
headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, data=payload, files=files, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents';
const form = new FormData();
form.append('activate', '');
form.append('documentCategory', 'insurance');
form.append('documentLabel', '');
form.append('documentType', '');
form.append('file', 'string');
form.append('metadata', '');
form.append('projectExternalId', '');
form.append('projectId', '');
form.append('submittedByEmail', '');

const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

options.body = form;

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"activate\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentCategory\"\r\n\r\ninsurance\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentLabel\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentType\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectExternalId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"submittedByEmail\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"activate\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentCategory\"\r\n\r\ninsurance\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentLabel\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentType\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectExternalId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"submittedByEmail\"\r\n\r\n\r\n-----011000010111000001101001--\r\n"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents")
  .header("Authorization", "Bearer <token>")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"activate\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentCategory\"\r\n\r\ninsurance\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentLabel\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentType\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectExternalId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"submittedByEmail\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents', [
  'multipart' => [
    [
        'name' => 'documentCategory',
        'contents' => 'insurance'
    ],
    [
        'name' => 'file',
        'filename' => 'string',
        'contents' => null
    ]
  ]
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"activate\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentCategory\"\r\n\r\ninsurance\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentLabel\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentType\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectExternalId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"submittedByEmail\"\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]
let parameters = [
  [
    "name": "activate",
    "value": 
  ],
  [
    "name": "documentCategory",
    "value": "insurance"
  ],
  [
    "name": "documentLabel",
    "value": 
  ],
  [
    "name": "documentType",
    "value": 
  ],
  [
    "name": "file",
    "fileName": "string"
  ],
  [
    "name": "metadata",
    "value": 
  ],
  [
    "name": "projectExternalId",
    "value": 
  ],
  [
    "name": "projectId",
    "value": 
  ],
  [
    "name": "submittedByEmail",
    "value": 
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Example 2

**Request**

```json
{
  "documentCategory": "insurance",
  "file": "<file: string>"
}
```

**Response**

```json
{
  "data": {
    "id": "string",
    "subcontractorId": "string",
    "organizationId": "string",
    "fileName": "string",
    "mimeType": "string",
    "fileSize": 1,
    "sourceUrl": "string",
    "status": "inactive",
    "lifecycleStatus": "uploaded",
    "documentCategory": "insurance",
    "documentLabel": "string",
    "uploadedBy": "string",
    "insuredName": "string",
    "contentSha256": "string",
    "scope": "baseline",
    "projectId": "string",
    "metadata": {},
    "createdAt": "2024-01-15T09:30:00Z",
    "updatedAt": "2024-01-15T09:30:00Z",
    "projectDocument": {
      "assignmentId": "string",
      "documentType": "project_coi",
      "id": "string",
      "status": "requested"
    }
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents"

files = { "file": "open('string', 'rb')" }
payload = {
    "activate": ,
    "documentCategory": "insurance",
    "documentLabel": ,
    "documentType": ,
    "metadata": ,
    "projectExternalId": ,
    "projectId": ,
    "submittedByEmail": 
}
headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, data=payload, files=files, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents';
const form = new FormData();
form.append('activate', '');
form.append('documentCategory', 'insurance');
form.append('documentLabel', '');
form.append('documentType', '');
form.append('file', 'string');
form.append('metadata', '');
form.append('projectExternalId', '');
form.append('projectId', '');
form.append('submittedByEmail', '');

const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

options.body = form;

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"activate\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentCategory\"\r\n\r\ninsurance\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentLabel\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentType\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectExternalId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"submittedByEmail\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"activate\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentCategory\"\r\n\r\ninsurance\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentLabel\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentType\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectExternalId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"submittedByEmail\"\r\n\r\n\r\n-----011000010111000001101001--\r\n"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents")
  .header("Authorization", "Bearer <token>")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"activate\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentCategory\"\r\n\r\ninsurance\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentLabel\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentType\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectExternalId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"submittedByEmail\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents', [
  'multipart' => [
    [
        'name' => 'documentCategory',
        'contents' => 'insurance'
    ],
    [
        'name' => 'file',
        'filename' => 'string',
        'contents' => null
    ]
  ]
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"activate\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentCategory\"\r\n\r\ninsurance\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentLabel\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"documentType\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectExternalId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"projectId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"submittedByEmail\"\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]
let parameters = [
  [
    "name": "activate",
    "value": 
  ],
  [
    "name": "documentCategory",
    "value": "insurance"
  ],
  [
    "name": "documentLabel",
    "value": 
  ],
  [
    "name": "documentType",
    "value": 
  ],
  [
    "name": "file",
    "fileName": "string"
  ],
  [
    "name": "metadata",
    "value": 
  ],
  [
    "name": "projectExternalId",
    "value": 
  ],
  [
    "name": "projectId",
    "value": 
  ],
  [
    "name": "submittedByEmail",
    "value": 
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "https://api.tradeguardins.com/v1/subcontractors/subcontractorId/documents")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```