brandmachine.shop

Authentication

Every request to the Brandmachine API, GraphQL and file uploads alike, needs a bearer token. For programmatic (machine-to-machine) access, create an API token in the Brandmachine app.

Authentication Methods#

Brandmachine accepts:

  1. API tokens: the method for server-to-server and script integrations. This page covers them.
  2. Auth0 session tokens: used by the Brandmachine web app for signed-in users.
  3. Shopify session tokens: used by the Brandmachine app inside Shopify Admin.

The session tokens are handled by the apps themselves and are not meant for direct use.

About API Tokens#

  • An API token is a signed JSON Web Token (JWT). It is a long string that starts with eyJ. There is no fixed prefix to check for.
  • An account can have several tokens. Give each integration its own, with a name that says what it is for.
  • Each token has a role, just like a person on your account, and can do exactly what that role allows. The highest role a token can have is Approver, so a token can never manage members or tokens, or top up credits. See Roles and Tokens below.
  • Tokens do not expire. A token stays valid until you revoke it.
  • The full token is shown only once, when it is created. Brandmachine stores only a fingerprint of it, so it cannot show it to you again.

Creating a Token#

You need the Admin or Owner role to manage tokens. See Team Members & Roles.

  1. Sign in to Brandmachine.
  2. Open Settings, find the API Access tile and click Manage API tokens.
  3. Under Create a token, enter a Name (for example "PIM sync") and choose a Role. Pick the lowest role the integration needs. Roles go up to Approver, and never above your own role.
  4. Click Create token.
  5. Click Copy, store the token somewhere safe, such as your secrets manager, then click I have saved it.

The Tokens list shows each token's name, role, the last characters of the token, when it was created and by whom, and when it was last used.

Making Authenticated Requests#

Send the token in the Authorization header of every request:

Authorization: Bearer YOUR_API_TOKEN

Using cURL#

curl -X POST https://production.api.brandmachine.shop/graphql \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "{ currentTeam { teamDomain } }"
  }'

Using JavaScript (fetch)#

const response = await fetch('https://production.api.brandmachine.shop/graphql', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.BRANDMACHINE_API_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    query: `
      query {
        currentTeam {
          teamDomain
        }
      }
    `,
  }),
});

const data = await response.json();

Using Python (requests)#

import os
import requests

url = 'https://production.api.brandmachine.shop/graphql'
headers = {
    'Authorization': f"Bearer {os.environ['BRANDMACHINE_API_TOKEN']}",
    'Content-Type': 'application/json',
}
query = '''
  query {
    currentTeam {
      teamDomain
    }
  }
'''

response = requests.post(url, json={'query': query}, headers=headers)
data = response.json()

The same header works for the File Uploads endpoints.

Roles and Tokens #

A token can do what its role allows, the same as a person with that role in the app:

Token roleWhat it can do
ViewerRead everything, change nothing.
MemberAlso upload, edit and organise work.
CreatorAlso start generations, which spend credits, and change the shared library (fashion models, set locations, patterns, wardrobe, perspectives).
ApproverAlso release results for export and delete content.

The main operations by the role they need. The Mutations reference marks every operation that needs more than Member:

AreaOperationsLowest role
Starting generationsstartProductStudioFlow, generateCampaignImages, generateGroupShot, generateProductVideo, executeBatch, startWorkflowRunCreator
LibrariesaddFashionModelToLibrary, createShootingLocation, duplicateProductStudioPerspectiveCreator
Releasing resultsreleaseProductStudioOutput, releaseCampaignImageResult, releaseGroupShotResult, releaseProductVideo, releaseDesignerRevision, releasePatternRevisionApprover
Deleting workdeleteProductStudio, deleteCampaign, deleteCampaignImage, deleteGroupShot, deleteProductVideo, deleteBatch, deleteFashionModel, deleteDesignerInstance, deletePattern, deleteWardrobeItem, deleteShootingLocationApprover
Team and tokensauditEntries, inviteTeamMember, updateTeamMemberRole, removeTeamMember, createApiToken, revokeApiTokenAdmin, so no token
BillingcreateTopUpCheckoutSession, createShopifyTopUpCharge, createTopUpIntent, createBillingPortalSessionOwner, so no token

An operation the token's role doesn't allow fails for that field only, with the message You do not have permission to do this. and extensions.code set to FORBIDDEN. extensions.capability names what was missing, for example START_GENERATION:

{
  "errors": [
    {
      "message": "You do not have permission to do this.",
      "path": ["startProductStudioFlow"],
      "extensions": { "code": "FORBIDDEN", "capability": "START_GENERATION" }
    }
  ]
}

To fix it, create a token with a higher role, up to Approver.

Token Management#

Replacing a Token#

There is no regenerate button. To replace a token, for example on a schedule or after someone who knew it leaves, create a new one first, update the application to use it, check that it works, then revoke the old one. Because an account can have several tokens, the integration keeps working throughout.

Revoking a Token#

If a token is compromised or no longer needed, click Revoke next to it in the Tokens list and confirm. Anything using it stops working on its next request. This can't be undone.

When a person is removed from the account, the tokens they created are revoked too. Create replacements for any integrations that still need them.

Activity#

Actions made with a token appear in Settings → Activity as API token "name", so you can see what each integration did. See Team Members & Roles.

Security Best Practices#

Never Commit Tokens to Version Control#

Store tokens in environment variables or a secrets manager:

# .env file (add to .gitignore)
BRANDMACHINE_API_TOKEN=YOUR_API_TOKEN
const token = process.env.BRANDMACHINE_API_TOKEN;

Keep the Token on the Server#

Every token, whatever its role, can read your account's work through the API. Use it from your own backend or scripts, never from code that runs in a browser or a mobile app.

Give Each Integration the Lowest Role It Needs#

A token that only reads data, for example to export released images, needs no more than Viewer. Only give Creator or Approver to integrations that start generations or release results.

Watch the Last Used Time#

The Tokens list shows when each token was last used. If it shows use you do not expect, revoke the token and create a new one.

Troubleshooting #

Authentication fails before the request reaches GraphQL. The response has HTTP status 401 and a JSON body with a reason:

{
  "error": true,
  "reason": "API token revoked or not found"
}
ReasonCauseSolution
Shopify Auth header missingNo Authorization: Bearer ... header was sent. The reason names Shopify because that is the last method checked.Send the header exactly as Authorization: Bearer YOUR_API_TOKEN, with one space after Bearer.
Invalid API tokenThe token's signature does not verify, usually because it was copied incompletely or changed.Copy the full token again, without extra whitespace or line breaks.
API token revoked or not foundThe token was revoked, or the person who created it was removed from the account.Create a new token.
UnauthorizedThe value sent is not an API token at all (for example a truncated string or a token from another system).Check that the header contains the token you copied when you created it.

If authentication succeeds but an operation returns You do not have permission to do this., the token's role doesn't allow that operation. See Roles and Tokens.

Next Steps#