---
title: "Attaches a file to a resource in a role."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.sherpo.io/llms.txt
> Use this file to discover all available pages before exploring further.

Path: Sherpo merchant API › file

`POST /v1/stores/{store}/{kind}/{id}/attachments`

## Authentication

- `bearer`, http, header `Authorization`, scopes: `file:write`

## Path parameters

- `store` (`attachAsset.path.store`; string, required) — The store's id.
- `kind` (`attachAsset.path.kind`; string, required) — The target's kind, in the plural.
  - minLength 1
- `id` (`attachAsset.path.id`; string, required)
  - minLength 1

## Header parameters

- `Idempotency-Key` (`attachAsset.header.Idempotency-Key`; string, optional) — Repeats within 24 hours answer the first result; the same key with other arguments is a conflict.
  - minLength 1; maxLength 255; pattern `^[\x21-\x7E]+$`

## Request body

_Required._

- `asset` (`attachAsset.asset`; object, required)
  - `id` (`attachAsset.asset.id`; string, required)
    - minLength 1; maxLength 512
- `role` (`attachAsset.role`; string, required) — A `poster` takes an image only, a `logo` an image and a `stylesheet` CSS; a poster, and an image a product binds as `embed`, at most 15 MB. The store's home takes only `body` and `stylesheet`, one of each; its body binds the files it names.
  - one of `"body"`, `"staged"`, `"staged_file"`, `"prose"`, `"teaser"`, `"embed"`, `"deliverable"`, `"poster"`, `"logo"`, `"prompt"`, `"stylesheet"`
- `delivery` (`attachAsset.delivery`; string, optional)
  - one of `"inline"`, `"download"`, `"stream"`
- `preview_only` (`attachAsset.preview_only`; boolean, optional)
- `position` (`attachAsset.position`; integer, optional)
  - min 0; max 1000000
- `if_none` (`attachAsset.if_none`; boolean, optional) — Refused when the target already holds one in this role.
- `if_none_of` (`attachAsset.if_none_of`; string, optional) — Refused while the target holds a file of this kind in the role that its body didn't bind; the asset must be one, or it refuses `conflict` on `mime` with the reason.
  - one of `"video"`, `"audio"`, `"pdf"`

## Example request

```json
{
  "asset": {
    "id": "string"
  },
  "role": "body",
  "delivery": "inline",
  "preview_only": true,
  "position": 1000000,
  "if_none": true,
  "if_none_of": "video"
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.sherpo.io/merchant/v1/stores/<store>/<kind>/<id>/attachments' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "asset": {
    "id": "string"
  },
  "role": "body",
  "delivery": "inline",
  "preview_only": true,
  "position": 1000000,
  "if_none": true,
  "if_none_of": "video"
}
'
```

### TypeScript

```typescript
const url = 'https://api.sherpo.io/merchant/v1/stores/<store>/<kind>/<id>/attachments';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    asset: {id: 'string'},
    role: 'body',
    delivery: 'inline',
    preview_only: true,
    position: 1000000,
    if_none: true,
    if_none_of: 'video'
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.sherpo.io/merchant/v1/stores/<store>/<kind>/<id>/attachments"

payload = {
    "asset": { "id": "string" },
    "role": "body",
    "delivery": "inline",
    "preview_only": True,
    "position": 1000000,
    "if_none": True,
    "if_none_of": "video"
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

Attaches a file to a resource in a role.

#### Example

```json
{
  "id": "string",
  "target": {
    "kind": "string",
    "id": "string"
  },
  "role": "string",
  "delivery": "string",
  "preview_only": true,
  "from_body": true,
  "release_file": true,
  "position": 0,
  "asset": {
    "id": "string",
    "locator": "string",
    "origin": "string",
    "custodian": "string",
    "enforcement": "string",
    "mime": "string",
    "bytes": 0,
    "quota_bytes": 0,
    "name": "string",
    "title": "string",
    "ext": "string",
    "status": "string",
    "optimized": true,
    "parent_id": "string",
    "redacted": true,
    "security": "string",
    "description": "string",
    "processed_at": "string",
    "metadata": {
      "width": 0,
      "height": 0,
      "duration": 0,
      "pages": 0,
      "waveform": "string",
      "transcript": {
        "language": "string",
        "confidence": 0
      },
      "arguments": [
        {
          "name": "string",
          "description": "string",
          "required": true,
          "default": "string",
          "match": "string",
          "flags": "string",
          "message": "string",
          "lenient": true
        }
      ],
      "property1": true,
      "property2": true
    },
    "created_at": "string"
  }
}
```

- `id` (`attachAsset.response.200.id`; string, required)
- `target` (`attachAsset.response.200.target`; object, required)
  - `kind` (`attachAsset.response.200.target.kind`; string, required)
  - `id` (`attachAsset.response.200.target.id`; string, required)
- `role` (`attachAsset.response.200.role`; string, required)
- `delivery` (`attachAsset.response.200.delivery`; string, required)
- `preview_only` (`attachAsset.response.200.preview_only`; boolean, required)
- `from_body` (`attachAsset.response.200.from_body`; boolean, required)
- `release_file` (`attachAsset.response.200.release_file`; boolean, required) — A file a software release ships, which its release edits and the product's own list leaves out.
- `position` (`attachAsset.response.200.position`; number, required)
- `asset` (`attachAsset.response.200.asset`; object, required)
  - `id` (`attachAsset.response.200.asset.id`; string, required)
  - `locator` (`attachAsset.response.200.asset.locator`; any of, required)
    - any of: `string`, `null`
  - `origin` (`attachAsset.response.200.asset.origin`; string, required)
  - `custodian` (`attachAsset.response.200.asset.custodian`; string, required)
  - `enforcement` (`attachAsset.response.200.asset.enforcement`; string, required)
  - `mime` (`attachAsset.response.200.asset.mime`; any of, required)
    - any of: `string`, `null`
  - `bytes` (`attachAsset.response.200.asset.bytes`; any of, required) — The file's size in bytes; null when it is charged nothing.
    - any of: `number`, `null`
  - `quota_bytes` (`attachAsset.response.200.asset.quota_bytes`; number, required) — The file's size in bytes; zero when it is charged nothing.
  - `name` (`attachAsset.response.200.asset.name`; string, required)
  - `title` (`attachAsset.response.200.asset.title`; any of, required)
    - any of: `string`, `null`
  - `ext` (`attachAsset.response.200.asset.ext`; any of, required)
    - any of: `string`, `null`
  - `status` (`attachAsset.response.200.asset.status`; string, required)
  - `optimized` (`attachAsset.response.200.asset.optimized`; boolean, required)
  - `parent_id` (`attachAsset.response.200.asset.parent_id`; any of, required)
    - any of: `string`, `null`
  - `redacted` (`attachAsset.response.200.asset.redacted`; boolean, required)
  - `security` (`attachAsset.response.200.asset.security`; any of, required)
    - any of: `string`, `null`
  - `description` (`attachAsset.response.200.asset.description`; any of, required)
    - any of: `string`, `null`
  - `processed_at` (`attachAsset.response.200.asset.processed_at`; any of, required)
    - any of: `string`, `null`
  - `metadata` (`attachAsset.response.200.asset.metadata`; object, required)
    - `width` (`attachAsset.response.200.asset.metadata.width`; integer, optional)
      - min 0
    - `height` (`attachAsset.response.200.asset.metadata.height`; integer, optional)
      - min 0
    - `duration` (`attachAsset.response.200.asset.metadata.duration`; number, optional) — Seconds, measured, so rarely whole.
    - `pages` (`attachAsset.response.200.asset.metadata.pages`; integer, optional)
      - min 0
    - `waveform` (`attachAsset.response.200.asset.metadata.waveform`; any of, optional) — An audio file's waveform: 256 levels from 0 to 255, base64; null when it can't be drawn.
      - any of: `string`, `null`
    - `transcript` (`attachAsset.response.200.asset.metadata.transcript`; object, optional)
      - `language` (`attachAsset.response.200.asset.metadata.transcript.language`; string, optional)
      - `confidence` (`attachAsset.response.200.asset.metadata.transcript.confidence`; number, optional)
    - `arguments` (`attachAsset.response.200.asset.metadata.arguments`; array<object>, optional) — What an MCP prompt asks for; only an authored prompt carries it.
      - `name` (`attachAsset.response.200.asset.metadata.arguments.name`; string, required)
      - `description` (`attachAsset.response.200.asset.metadata.arguments.description`; any of, required)
        - any of: `string`, `null`
      - `required` (`attachAsset.response.200.asset.metadata.arguments.required`; boolean, required)
      - `default` (`attachAsset.response.200.asset.metadata.arguments.default`; any of, required)
        - any of: `string`, `null`
      - `match` (`attachAsset.response.200.asset.metadata.arguments.match`; any of, required) — Pattern the whole value must match, diacritic-insensitive.
        - any of: `string`, `null`
      - `flags` (`attachAsset.response.200.asset.metadata.arguments.flags`; any of, required) — Flags among `i`, `s` and `u` the pattern runs with; null for `i` alone.
        - any of: `string`, `null`
      - `message` (`attachAsset.response.200.asset.metadata.arguments.message`; any of, required) — What a refused value is told instead of the default reason.
        - any of: `string`, `null`
      - `lenient` (`attachAsset.response.200.asset.metadata.arguments.lenient`; boolean, required)
  - `created_at` (`attachAsset.response.200.asset.created_at`; any of, required)
    - any of: `string`, `null`

### default

A problem; see https://api.sherpo.io/merchant/docs/errors.

#### Example

```json
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "string",
  "context": {},
  "reached_core": true,
  "core_answer": "string"
}
```

- `type` (`attachAsset.response.default.type`; string, required)
  - format `uri`
- `title` (`attachAsset.response.default.title`; string, required)
- `status` (`attachAsset.response.default.status`; integer, required)
- `detail` (`attachAsset.response.default.detail`; string, required)
- `code` (`attachAsset.response.default.code`; string, optional)
- `context` (`attachAsset.response.default.context`; object, optional)
- `reached_core` (`attachAsset.response.default.reached_core`; boolean, optional)
- `core_answer` (`attachAsset.response.default.core_answer`; string, optional)


Source: https://docs.sherpo.io/merchant-api/reference/attach-asset/index.md
