Upload, attach and download files

A Merchi file has an opaque string ID. Keep the ID for relationships and use the URL returned for a particular download. The URL may expire. Keep private file links in the integration that obtained them.

Use MERCHI_API for your integration environment’s HTTPS origin and MERCHI_SESSION_TOKEN for an authorized session. See the API quickstart for session setup.

Upload a file for a job or draft

POST /v6/files/ accepts multipart form data. The required fileDataIndex value identifies the part containing the binary file. In this example, the value and the binary part name are both 1. Curl sets the multipart boundary.

curl --fail-with-body "$MERCHI_API/v6/files/" \
  --cookie "session_token=$MERCHI_SESSION_TOKEN" \
  --form 'fileDataIndex=1' \
  --form '1=@artwork.png;type=image/png'

The response is HTTP 201 and wraps the new record under file. This example shows the fields used by an attachment flow.

{
  "file": {
    "id": "example-file-id",
    "name": "artwork.png",
    "mimetype": "image/png",
    "size": 12345,
    "viewUrl": "https://storage.example.invalid/example-view",
    "downloadUrl": "https://storage.example.invalid/example-download"
  }
}

Keep file.id for the next request. Attach an existing file to a job using the clientFiles relationship, or to a draft using images. When building the form directly, send the relationship count and indexed ID, for example clientFiles-count=1 and clientFiles-0-id=<file-id>. The target job or draft applies its own relationship permissions. See the job upload example and draft workflow.

If the index or binary part is missing, the API returns HTTP 400.

{"message":"No file supplied","statusCode":400,"errorCode":71}

For a domainless upload flow that expects POST /v6/public-upload-job-files/, send the file as multipart field 0. That route also returns HTTP 201 with file. A missing field 0 returns 400 with errorCode: 71 and the message No file was provided. Uploading creates a file record. Attaching it to a job requires a separate authorized operation.

File upload handler and multipart parser · Domainless upload handler

Read private file metadata and download

Request Access and response
GET /v6/files/user/ Lists files visible through the caller’s upload and managed-record access rules. Use the usual list filters and pagination.
GET /v6/files/<id>/ Superuser metadata access. Returns the file object when the file exists.
GET /v6/files/<id>/?download=1 Superuser attachment download with file bytes.
GET /v6/files/<id>/?view=1 Superuser inline file response.
GET /v6/files/<id>/?url=1 Superuser lookup returning the view URL as text.

For an ordinary staff integration, obtain file metadata through an authorized relationship or the scoped file list. Use an available downloadUrl for the binary request. Refresh the file metadata when a link has expired. A missing or empty link means the response offers no URL for that operation. Keep Merchi session credentials on Merchi requests when retrieving a signed link hosted by the file store.

A user who uploaded a file can delete it with DELETE /v6/files/<id>/, subject to server policy. A successful delete returns HTTP 204. The API tests show that a manager cannot delete a file uploaded by a different user solely because they are a manager.

File route permissions · Private file access tests

Download a public catalog file

Use GET /v6/public-files/<id>/download/ for a file listed on a public catalog product or a blank template belonging to a public catalog product. The route checks the association and returns HTTP 302 with a download location and Cache-Control: no-store. Follow the redirect for the bytes and retain the original catalog URL for later downloads.

curl --fail --location --output template.pdf \
  "$MERCHI_API/v6/public-files/$MERCHI_PUBLIC_FILE_ID/download/"

The route returns 404 for an unattached file, a private product’s template, an archived template or artwork attached to a job-specific template. For public product images and feature images, GET /v6/product-public-file/download/<id>.<extension> checks the public product association and the extension against the stored MIME type, then sends the image as an attachment. An incorrect extension returns 404.

Public download handlers · Public download and redirect tests