Documents

Uploading a document

Send a document's bytes in one request, verify its checksum, and retry safely with an idempotency key.

One request

POST https://wellfriend.dev/api/v2/documents with the raw file as the request body (scope documents.write). The response contains the document and its first version. One request carries at most 100 MiB; for a larger file, or a resumable upload on an unreliable connection, use the chunked upload (POST /api/v2/uploads) described on /docs/developer-api/uploads. Either way, the file must fit your plan's per-file limit.

Request headers

HeaderRequiredRule
AuthorizationYesBearer <v2 key>
Content-TypeYesThe document's media type, for example application/pdf
Content-LengthYesThe exact byte length; at most 100 MiB in one request (details.maximumBytes and details.uploadsUrl on 413 DOCUMENT_SIZE_INVALID)
X-Wellfriend-FilenameYes1 to 255 characters
X-Wellfriend-TitleNoUp to 500 characters; defaults to the filename
X-Content-SHA256No64 hexadecimal characters; if the received bytes do not match, nothing is stored
Idempotency-KeyYes8–200 letters, digits, period, underscore, colon or hyphen

Responses

  • 201 with { document, created: true } when a new document was stored.
  • 200 with created false when the same idempotency key repeats an earlier upload; nothing new is stored or charged.
  • 400 DOCUMENT_ADMISSION_INVALID when a header is missing or malformed.
  • 413 DOCUMENT_SIZE_INVALID when Content-Length is missing or over the single-request limit; use POST /api/v2/uploads instead.
  • 413 UPLOAD_TOO_LARGE_FOR_PLAN when the file is above your plan's per-file limit (details.limitBytes, details.plan).

Recovering from failures

SituationWhat to do
Dropped connection or timeoutRepeat the identical request with the same idempotency key
500 DOCUMENT_CREATE_FAILEDRetry with the same idempotency key; it is retryable
Repeated 500 with X-Content-SHA256 setA checksum mismatch also fails as DOCUMENT_CREATE_FAILED: recompute the SHA-256 of the exact bytes you send, then retry
Wrong file or metadataUpload the correct file as a new request with a new idempotency key

Security

  • Check that your user may send the file before you read or forward it.
  • Never expose the API key to the browser.
  • Sanitize filenames before you display them, and treat the declared content type as a claim, not a fact.
  • Do not write document bytes to logs or error reports.