# File Uploads

Source: https://help.brandmachine.shop/api-file-uploads/

File uploads in Brandmachine use **REST endpoints** with `multipart/form-data`, separate from the GraphQL endpoint. Each kind of resource has its own upload endpoint (product studio inputs, batch images, wardrobe images, brand assets and so on) rather than one generic upload.

## Authentication

All upload endpoints accept the same API token as the GraphQL endpoint:

```
Authorization: Bearer YOUR_API_TOKEN
```

See [Authentication](https://help.brandmachine.shop/api-authentication/) for how to create a token. Which uploads a token may make depends on its role:

- **Member** or higher: product images (Product Studio, Campaign, Product Videos), batch images and looks sheets, and campaign guidance images.
- **Creator** or higher: uploads into the shared library: wardrobe images, brand assets, fashion model uploads, Designer resources, patterns and size chart imports.
- **Approver**: edited images.

A token whose role is too low gets HTTP status `403` with the reason `You do not have permission to do this.`

## Upload Endpoints

All endpoints take `POST` requests on `https://production.api.brandmachine.shop`. Replace the `:id` placeholders in the path with the UUID of the record. The **Form fields** column lists the multipart fields; fields in *italics* are optional.

### Product Studio

| Endpoint | Form fields | Purpose |
| --- | --- | --- |
| `/api/product-studios/:studioId/inputs/upload` | `file`, `viewType`, *`title`* | Add a product photo to a Product Studio session. `viewType` is `front`, `back`, `other` or `cropped`. A session holds at most 15 inputs. |
| `/api/product-studio/plates` | `perspectiveId`, `file`, *`kind`* | Upload a plate or guide image for a Product Studio perspective. `kind` is `plate` (the default) or `guide`. Returns `key` and `url`. |

### Campaigns and Batches

| Endpoint | Form fields | Purpose |
| --- | --- | --- |
| `/api/campaign-images/:campaignImageId/products/upload` | `file`, *`productTitle`*, *`productDescription`* | Add a product reference image to a campaign image |
| `/api/campaign-images/:campaignImageId/guidance/upload` | `file` | Set a guidance image on a campaign image |
| `/api/batches/:batchId/images/upload` | `file`, *`viewType`* | Add an input image to a batch. When `viewType` is missing or not a known value, the view is detected from the image. |
| `/api/batches/:batchId/reference-sheet/upload` | `file` | Upload a stylist's looks sheet for a batch. The looks read from it appear on the batch as `referenceSheetLooks`. |

Batch image uploads are refused once the batch is running or completed.

### Wardrobe

| Endpoint | Form fields | Purpose |
| --- | --- | --- |
| `/api/wardrobe-items/:wardrobeItemId/images/upload` | `file`, *`viewType`* | Add a photo to a wardrobe item. An item holds at most 8 images. |

### Brand Assets (Media Planner)

| Endpoint | Form fields | Purpose |
| --- | --- | --- |
| `/api/brand-assets/upload` | `file`, *`title`* | Upload a brand asset such as a logo. Must be a PNG. |
| `/api/brand-assets/:brandAssetId/dark-ground-version/upload` | `file` | Upload the version of a brand asset for dark backgrounds. Must be a PNG with the same aspect ratio as the original (within 1%). |

### Fashion Models

| Endpoint | Form fields | Purpose |
| --- | --- | --- |
| `/api/fashion-models/upload` | `file`, `gender` | Start a casting from a reference image. `gender` is `male`, `female` or `other`. |
| `/api/fashion-models/upload-existing` | `file`, `modelName`, `gender`, *`setCardFile`* | Add an existing model directly, without casting |

### Designer

| Endpoint | Form fields | Purpose |
| --- | --- | --- |
| `/api/designer-instances/resources` | `designerInstanceId`, *`file`*, *`text`*, *`label`* | Add an inspiration resource to a design. Send a `file`, a `text`, or both. A text-only resource needs a `label`; for an image the label is written automatically when you leave it out. |
| `/api/designer/annotation-overlays` | `sourceRevisionId`, `file` | Upload an annotation overlay drawn on a revision. Returns `imageKey` and `imageUrl`. |
| `/api/size-charts/import` | `file` | Import size charts from a JSON file in Brandmachine's size chart import format. Add `?dryRun=true` to the URL to check the file without importing anything. The format is described in [Importing Size Charts](https://help.brandmachine.shop/api-size-charts/). |

### Patterns

| Endpoint | Form fields | Purpose |
| --- | --- | --- |
| `/api/patterns/upload` | `file`, *`patternId`*, *`name`*, *`repeatHorizontal`*, *`repeatVertical`* | Upload a finished pattern image. Without `patternId` a new pattern is created, and `name` is required. |
| `/api/patterns/references` | `patternId`, `label`, `file` | Add an inspiration reference to a pattern |

### Product Video

| Endpoint | Form fields | Purpose |
| --- | --- | --- |
| `/api/product-videos/:videoId/upload` | `file`, *`productTitle`* | Upload the product image a product video is generated from |

### Edited Images

| Endpoint | Form fields | Purpose |
| --- | --- | --- |
| `/api/images/upload-edited` | `file`, `imageType`, `imageId` | Save an edited version of a generated image. `imageType` is `campaignImage`, `productStudio` or `groupShot` (case-sensitive), and `imageId` is the UUID of the campaign image result, product studio output or group shot result. Must be a PNG of at most 27 MiB. Returns `success`, `imageKey` and `imageUrl`. |

## Example: Upload a Product Studio Input

### cURL

```
curl -X POST \
  https://production.api.brandmachine.shop/api/product-studios/STUDIO_UUID/inputs/upload \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -F "file=@/path/to/product.jpg;type=image/jpeg" \
  -F "viewType=front"
```

### JavaScript (Node.js 18 or later)

```
import { readFile } from 'node:fs/promises';

async function uploadProductInput(studioId, path, viewType = 'front') {
  const formData = new FormData();
  formData.append('file', new Blob([await readFile(path)], { type: 'image/jpeg' }), 'product.jpg');
  formData.append('viewType', viewType);

  const response = await fetch(
    `https://production.api.brandmachine.shop/api/product-studios/${studioId}/inputs/upload`,
    {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${process.env.BRANDMACHINE_API_TOKEN}`,
      },
      body: formData,
    }
  );

  if (!response.ok) {
    const error = await response.json();
    throw new Error(`Upload failed (${response.status}): ${error.reason}`);
  }

  return response.json();
}
```

### Python

```
import os
import requests

url = 'https://production.api.brandmachine.shop/api/product-studios/STUDIO_UUID/inputs/upload'
headers = {'Authorization': f"Bearer {os.environ['BRANDMACHINE_API_TOKEN']}"}

with open('product.jpg', 'rb') as f:
    files = {'file': ('product.jpg', f, 'image/jpeg')}
    data = {'viewType': 'front'}
    response = requests.post(url, headers=headers, files=files, data=data)
    response.raise_for_status()
    print(response.json())
```

## Example: Upload a Designer Inspiration Resource

```
curl -X POST \
  https://production.api.brandmachine.shop/api/designer-instances/resources \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -F "designerInstanceId=DESIGN_UUID" \
  -F "label=bird chest" \
  -F "file=@/path/to/inspiration.jpg;type=image/jpeg"
```

## File Requirements

### Supported Image Types

- JPEG (`.jpg`, `.jpeg`)
- PNG (`.png`)
- WebP (`.webp`)

The file name must end in one of these extensions. If the multipart part has a `Content-Type`, it must be `image/jpeg`, `image/png` or `image/webp`; a generic type such as `application/octet-stream` is refused. Brand assets and edited images accept PNG only. The size chart import takes a JSON file.

### Size Limits

- A single image may be at most 15 MB. Edited images may be up to 27 MiB.
- The whole request body may be at most 32 MB.
- Images are stored as uploaded. They are not resized or converted.

Several uploads (product studio inputs, batch images and looks sheets, wardrobe images, fashion model uploads, Designer resources) analyse the image before they respond, so these requests can take several seconds.

## Response Format

A successful upload returns HTTP status `200` and the created or updated record as JSON, including its `id`. For example, a product studio input upload returns the new input with fields such as `id`, `viewType`, `productImage` and `createdAt`. The endpoints that return something other than a record are noted in the tables above.

The size chart import always returns HTTP status `200` with a report: problems in the file are listed in its `errors` array rather than returned as an HTTP error.

Errors return a non-2xx status and a JSON body with a `reason`:

```
{
  "error": true,
  "reason": "Only image files (JPG, PNG, WEBP) are allowed"
}
```

## Error Handling

| Status | Typical reason | What to do |
| --- | --- | --- |
| `400` | The file is too large, has the wrong type, or a required form field is missing or invalid | Check the file and the form fields against the tables above |
| `401` | Missing or invalid token | Check the `Authorization` header. See [Authentication](https://help.brandmachine.shop/api-authentication/#troubleshooting). |
| `403` or `404` | The record in the path or form does not exist or belongs to another team | Check the UUID |
| `413` | The request body is over 32 MB, or an edited image is over 27 MiB | Send a smaller file |
| `422` | No looks could be read from a looks sheet | Upload a clearer sheet |

### Retry Failed Uploads

Retry network failures and `5xx` responses. A `4xx` response fails the same way again, so fix the request instead of retrying it.

```
async function uploadWithRetry(url, formData, maxRetries = 3) {
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
    const response = await fetch(url, {
      method: 'POST',
      headers: { Authorization: `Bearer ${process.env.BRANDMACHINE_API_TOKEN}` },
      body: formData,
    }).catch((error) => {
      if (attempt === maxRetries) throw error;
      return null;
    });

    if (response?.ok) return response.json();
    if (response && response.status < 500) {
      const error = await response.json();
      throw new Error(`Upload failed (${response.status}): ${error.reason}`);
    }
    if (attempt === maxRetries) throw new Error(`Upload failed after ${maxRetries} attempts`);
    await new Promise((r) => setTimeout(r, 1000 * attempt));
  }
}
```

## Best Practices

- **Validate before uploading** (size, type, file extension) to avoid round trips on bad files.
- **Set the part's content type** explicitly, as in the examples above. Some HTTP clients send `application/octet-stream` by default, which is refused.
- **Use the right endpoint.** A campaign reference image goes through the campaign endpoint and a pattern reference through the pattern endpoint; the endpoints are not interchangeable.
- **Follow up with GraphQL.** Uploading adds the file to the record; starting a generation is a separate GraphQL mutation. Use `activeMediaGenerationTasks` to see which generations are still running.

## Need Help?

Contact [support@brandmachine.shop](mailto:support@brandmachine.shop) for upload-related issues, with the endpoint and the `reason` from the response.

---

## Other pages

Brandmachine documentation, one Markdown file per page. Index with descriptions: https://help.brandmachine.shop/llms.txt

### Start here

- [Getting Started](https://help.brandmachine.shop/getting-started.md)
- [Input Guidelines](https://help.brandmachine.shop/input-guidelines.md)
- [Billing & Credits](https://help.brandmachine.shop/billing-credits.md)
- [Team Members & Roles](https://help.brandmachine.shop/team-members-roles.md)
- [Shopify App & Web App](https://help.brandmachine.shop/shopify-and-web-app.md)
- [Brandmachine in ChatGPT](https://help.brandmachine.shop/chatgpt.md)

### Product Studio

- [Product Studio](https://help.brandmachine.shop/product-studio-getting-started.md)
- [Aspect Ratios & Custom Crops](https://help.brandmachine.shop/product-studio-aspect-ratios.md)
- [Framing per Garment](https://help.brandmachine.shop/product-studio-framing.md)
- [ZIP Upload](https://help.brandmachine.shop/zip-upload.md)
- [Breuninger Sets](https://help.brandmachine.shop/product-studio-breuninger.md)
- [Delivering to Breuninger](https://help.brandmachine.shop/product-studio-breuninger-delivery.md)
- [Workbench](https://help.brandmachine.shop/workbench.md)

### Campaigns

- [Campaigns](https://help.brandmachine.shop/campaign-composer-getting-started.md)
- [Group Shots](https://help.brandmachine.shop/group-shots.md)
- [Set Locations](https://help.brandmachine.shop/set-locations-getting-started.md)

### Designer

- [Designer](https://help.brandmachine.shop/designer.md)
- [Patterns](https://help.brandmachine.shop/patterns.md)

### Automations

- [Shot Planner](https://help.brandmachine.shop/shot-planner.md)

### Shared Resources

- [Fashion Models](https://help.brandmachine.shop/fashion-models-getting-started.md)
- [Poses](https://help.brandmachine.shop/poses.md)
- [Product Videos](https://help.brandmachine.shop/product-shorts-getting-started.md)
- [Brand Memory](https://help.brandmachine.shop/brand-identity-getting-started.md)
- [Writing a Good Brand Identity](https://help.brandmachine.shop/brand-identity-writing-guide.md)

### Output & Downloads

- [Downloading and Exporting](https://help.brandmachine.shop/downloading-and-exporting.md)
- [AI Metadata on Downloads](https://help.brandmachine.shop/ai-metadata.md)
- [Content Credentials and C2PA Conformance](https://help.brandmachine.shop/content-credentials.md)
- [Photo Editor](https://help.brandmachine.shop/photo-editor.md)

### Developers

- [API Reference](https://help.brandmachine.shop/api-reference.md)
- [Getting Started](https://help.brandmachine.shop/api-getting-started.md)
- [Authentication](https://help.brandmachine.shop/api-authentication.md)
- [Exporting Released Images](https://help.brandmachine.shop/api-exporting-images.md)
- [Importing Size Charts](https://help.brandmachine.shop/api-size-charts.md)
- [Queries](https://help.brandmachine.shop/api-queries.md)
- [Mutations](https://help.brandmachine.shop/api-mutations.md)
- [Types](https://help.brandmachine.shop/api-types.md)
- [Input Types](https://help.brandmachine.shop/api-input-types.md)
- [Enums](https://help.brandmachine.shop/api-enums.md)
- [Scalars](https://help.brandmachine.shop/api-scalars.md)
