# Generate attachment upload URL

> Generates a secure upload URL for attachment files

`POST https://api.light.inc/v1/attachments/upload-url`

## Note

Step one of three; see Files (/docs/getting-started/pagination-filtering-errors files). The URL is valid for five minutes . When you PUT the bytes to it, set Content-Type to the contentType you asked for and send every entry of the returned metadata as a request header — they are signed into the URL and the upload is rejected without them. Then register the file with POST /v1/attachments , passing the returned key as documentKey . fileName must be unique per resourceId ; reusing one fails with ATTACHMENT_FILE_NAME_FOR_RESOURCE_ALREADY_EXISTS . contentType must be one of the PDF, image ( image/ ), text or Office document types; anything else fails with UNSUPPORTED_FILE_MIME_TYPE . The key is generated by Light; you cannot choose it. There is no resourceType in this API: resourceId is the id of the record (an invoice, a purchase order, ...) and it is not checked against anything, so a typo produces an attachment nothing will ever show.

## Authorization

- API key
- Bearer token

See https://light.inc/docs/getting-started/authentication.

## Request body

`application/json;charset=UTF-8`


```json
{
  "resourceId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "fileName": "string",
  "contentType": "string"
}
```

Values above are generated from the schema: the shapes and types are real, the values are placeholders, and fields that exclude each other are all shown. Do not send it unchanged.

## Response

- `key` — Pass this as `documentKey` to `POST /v1/attachments` once the upload is done.
- `metadata` — Send every entry as a request header on the `PUT` to `uploadUrl`, exactly as returned. They are signed into the URL; the upload is rejected without them.

```json
{
  "uploadUrl": "https://example.com",
  "key": "string",
  "metadata": null
}
```

Values above are generated from the schema: the shapes and types are real, the values are placeholders.

## Code

```bash
curl -X POST "https://api.light.inc/v1/attachments/upload-url" \
  -H "Authorization: Basic YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "resourceId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "fileName": "string",
  "contentType": "string"
}'
```

---

Full page: https://light.inc/docs/api-reference/v1--attachments/generate-attachment-upload-url · Index: https://light.inc/docs/llms.txt
