# API Reference

Source: https://help.brandmachine.shop/api-reference/

The Brandmachine GraphQL API gives you programmatic access to the same data you work with in the app: Product Studio sessions, campaigns and campaign images, group shots, batches, fashion models, shooting locations, wardrobe items, the Designer (collections, designs, revisions, size charts), the Media Planner, brand assets, and billing. File uploads go through a set of REST endpoints next to the GraphQL endpoint.

## Getting Started

New to the API? Start here:

1. **[Authentication](https://help.brandmachine.shop/api-authentication/)**: generate an API token and authenticate requests
2. **[Getting Started Guide](https://help.brandmachine.shop/api-getting-started/)**: make your first API call
3. **[Exporting Released Images](https://help.brandmachine.shop/api-exporting-images/)**: pick up released images automatically, for a DAM, PIM or shop
4. **[Queries](https://help.brandmachine.shop/api-queries/)**: explore the read operations
5. **[Mutations](https://help.brandmachine.shop/api-mutations/)**: create, change and delete data

## API Endpoint

All GraphQL requests go to:

```
https://production.api.brandmachine.shop/graphql
```

File uploads use REST endpoints on the same host (for example `https://production.api.brandmachine.shop/api/product-studios/:studioId/inputs/upload`). See [File Uploads](https://help.brandmachine.shop/api-file-uploads/) for the full list.

## GraphQL Resources

### Core Operations

- **[Queries](https://help.brandmachine.shop/api-queries/)**: read data
- **[Mutations](https://help.brandmachine.shop/api-mutations/)**: write data

### Type Definitions

- **[Types](https://help.brandmachine.shop/api-types/)**: object types and their fields
- **[Input Types](https://help.brandmachine.shop/api-input-types/)**: input objects that operations take as arguments
- **[Enums](https://help.brandmachine.shop/api-enums/)**: enumeration types
- **[Scalars](https://help.brandmachine.shop/api-scalars/)**: custom scalars (`Date`, `UUID`)

These pages are generated from the schema. Every type name in a signature links to its definition.

## Additional Resources

- **[File Uploads](https://help.brandmachine.shop/api-file-uploads/)**: REST endpoints for product images, batch images and looks sheets, wardrobe images, brand assets, fashion model uploads, Designer resources, patterns, size chart imports, and edited images

## What a Token May Do

Every API token has a role, from Viewer up to Approver, and can do what that role allows: read with any role, start paid generations from Creator, release results and delete work from Approver. Topping up credits is for account Owners in the app, so no token can do it. [Authentication](https://help.brandmachine.shop/api-authentication/#roles) has the details and the error a token gets when its role is too low.

## Error Handling

### GraphQL errors

Errors raised while an operation runs come back with HTTP status `200` and an `errors` array. The HTTP status of the underlying failure is part of the message, in the form `Abort.<status>: <reason>`:

```
{
  "errors": [
    {
      "message": "Abort.404: Batch not found",
      "locations": [{ "line": 1, "column": 3 }],
      "path": ["batch"]
    }
  ]
}
```

Apart from permission errors (below), the API does not set `extensions.code` on errors, so read the status from the start of the message. Common cases:

- `Abort.400`: invalid input, for example a value outside the allowed range or a combination of arguments the operation does not accept
- `Abort.402: Top up credits to continue.`: the operation would start a paid generation and your team's credit balance is too low (see [Billing & Credits](https://help.brandmachine.shop/billing-credits/))
- `Abort.403`: the operation is not allowed for this caller. When the token's role is too low, the message is `You do not have permission to do this.` and `extensions.code` is `FORBIDDEN` (see [Authentication](https://help.brandmachine.shop/api-authentication/#roles))
- `Abort.404`: the requested record was not found for your team

A request that fails GraphQL validation (an unknown field, a wrong argument type) also returns HTTP status `200` and an `errors` array. Its message is the validation message, without the `Abort` prefix.

### Authentication errors

Authentication is checked before the GraphQL request runs. A missing, invalid or revoked token returns HTTP status `401` with a plain JSON body instead of a GraphQL response:

```
{
  "error": true,
  "reason": "Invalid API token"
}
```

[Authentication](https://help.brandmachine.shop/api-authentication/#troubleshooting) lists the possible reasons.

## Billing-Related Queries

Brandmachine runs on pay-as-you-go credits. These queries are useful for billing integrations, and all of them work with an API token:

- `currentTeam`: your team's identity and whether it is billed pay-as-you-go (`isPAYG`)
- `creditBalance`: current balance in cents
- `creditBalanceDigest`: a timestamp that changes whenever the balance changes; poll it and refetch `creditBalance` when it moves
- `billingLedger`: paginated transaction history, newest first
- `billingCostSummary`: aggregated costs over a date range
- `pricelist`: the current price list, with a `label` and `tier` for each charge

Topping up credits (`createTopUpCheckoutSession`, `createShopifyTopUpCharge`, `createTopUpIntent`) and opening the billing portal (`createBillingPortalSession`) need the Owner role, which no API token can have. Top up in the app instead.

## Support

Need help with the API? Email [support@brandmachine.shop](mailto:support@brandmachine.shop) with the request you sent and the response you got back.

---

## 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

- [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)
- [File Uploads](https://help.brandmachine.shop/api-file-uploads.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)
