Skip to content

Conversation

@bc-victor
Copy link
Contributor

@bc-victor bc-victor commented Oct 7, 2025

What/Why?

After the release of PROJECT-6952, developers using a BC store-level oauth token with the new B2B Edition oauth scope need to send additional headers for the endpoint to respond properly.

Adding env variable BIGCOMMERCE_ACCESS_TOKEN to differentiate from the type of headers we need to send to the B2B APIs

Testing

Login success ( only place where we use B2B APIs)

With B2B token

Screen.Recording.2025-10-08.at.11.20.59.a.m.mov

Without BC token

Screen.Recording.2025-10-08.at.11.22.03.a.m.mov

Migration

No migrations

@bc-victor bc-victor requested a review from a team as a code owner October 7, 2025 19:59
@changeset-bot
Copy link

changeset-bot bot commented Oct 7, 2025

⚠️ No Changeset found

Latest commit: 0027b89

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 7, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
catalyst-b2b Ready Ready Preview Comment Oct 16, 2025 7:24pm
catalyst-canary Ready Ready Preview Comment Oct 16, 2025 7:24pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
catalyst Ignored Ignored Oct 16, 2025 7:24pm

@bc-sylvialin
Copy link

Copy link

@bc-micah bc-micah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to see the docs updated + including tests for both the old and new tokens - comments have details.

env: z.object({
B2B_API_TOKEN: z.string(),
BIGCOMMERCE_CHANNEL_ID: z.string(),
BIGCOMMERCE_STORE_HASH: z.string(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we update the docs that explain what a B2B_API_TOKEN is as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 43 to 44
'X-Store-Hash': BIGCOMMERCE_STORE_HASH,
'X-Auth-Token': B2B_API_TOKEN,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we include full tests of both tokens (old b2b only s2s token + bigcommerce api account token)?

I would like to see the full flow tested for both scenarios and include showing / setting the env var + verifying the login is working appropriately (including opening the buyer portal as that shows the storefront is logged in as well as the b2b functions)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review. After testing realized we can't just send authToken, X-Auth-Token and X-Store-Hash together, we need to know which token is being used. I added a new variable BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE to differntiatte from scopes

.env.example Outdated
Comment on lines 47 to 53
# BigCommerce API token with B2B Edition scopes used to authenticate requests to the B2B API
BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE=

# DEPRECATED - Please prefer using the above variable
# The B2B API Token is used to authenticate requests to the B2B API.
# It can be generated in the B2B control panel Settings > API Accounts > Create API Account.
B2B_API_TOKEN=
# B2B_API_TOKEN=
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe lets remove this entirely? also from the docs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do it directly?

maybe add a check, if B2B_API_TOKEN is present, throw and show an error message?

z.object({
  B2B_API_TOKEN: z.undefined({ message: 'This is deprecated in favour or B2B_API_TOKEN'}).optional(),
  BIGCOMMERCE_TOKEN: z.string()
})

@bc-victor bc-victor requested a review from bc-micah October 8, 2025 18:59
Copy link

@icatalina icatalina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre approving, I think I prefer a more generic token name and removing the old one. What do you all think?

.env.example Outdated
Comment on lines 47 to 53
# BigCommerce API token with B2B Edition scopes used to authenticate requests to the B2B API
BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE=

# DEPRECATED - Please prefer using the above variable
# The B2B API Token is used to authenticate requests to the B2B API.
# It can be generated in the B2B control panel Settings > API Accounts > Create API Account.
B2B_API_TOKEN=
# B2B_API_TOKEN=

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do it directly?

maybe add a check, if B2B_API_TOKEN is present, throw and show an error message?

z.object({
  B2B_API_TOKEN: z.undefined({ message: 'This is deprecated in favour or B2B_API_TOKEN'}).optional(),
  BIGCOMMERCE_TOKEN: z.string()
})

.env.example Outdated
B2B_API_HOST=https://api-b2b.bigcommerce.com

# BigCommerce API token with B2B Edition scopes used to authenticate requests to the B2B API
BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE=

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE=
BIGCOMMERCE_TOKEN=

if we require new scopes in the future, are we gonna rename the variable to:

BIGCOMMERCE_TOKEN_WITH_B2B_AND_SOME_OTHER_SCOPE=

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a good point, I'll add this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"With x scope" seems like an awkward naming convention in general to me.

Just for reference, the optional BigCommerce REST token that can be included in the environment config for, e.g., supporting the customer groups lookup in Makeswift, is called BIGCOMMERCE_ACCESS_TOKEN. We might want to conform the naming convention here to more closely match that.

Or is it possibly appropriate to just use BIGCOMMERCE_ACCESS_TOKEN and give clear instructions that the token provided there needs to have the B2B scope? I think that might make more sense than having separate BigCommerce REST tokens for separate operations.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's already being used in makeswift, let's stick to the existing name to reduce the number of things the user has to setup.

We can then just add that B2B scope is required in the setup docs.

.env.example Outdated
B2B_API_HOST=https://api-b2b.bigcommerce.com

# BigCommerce API token with B2B Edition scopes used to authenticate requests to the B2B API
BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE=
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"With x scope" seems like an awkward naming convention in general to me.

Just for reference, the optional BigCommerce REST token that can be included in the environment config for, e.g., supporting the customer groups lookup in Makeswift, is called BIGCOMMERCE_ACCESS_TOKEN. We might want to conform the naming convention here to more closely match that.

Or is it possibly appropriate to just use BIGCOMMERCE_ACCESS_TOKEN and give clear instructions that the token provided there needs to have the B2B scope? I think that might make more sense than having separate BigCommerce REST tokens for separate operations.

Comment on lines 40 to 47
if (B2B_API_TOKEN) {
headers['authToken'] = B2B_API_TOKEN;
}

if (BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE) {
headers['X-Auth-Token'] = BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE;
headers['X-Store-Hash'] = BIGCOMMERCE_STORE_HASH;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (B2B_API_TOKEN) {
headers['authToken'] = B2B_API_TOKEN;
}
if (BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE) {
headers['X-Auth-Token'] = BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE;
headers['X-Store-Hash'] = BIGCOMMERCE_STORE_HASH;
}
if (BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE) {
headers['X-Auth-Token'] = BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE;
headers['X-Store-Hash'] = BIGCOMMERCE_STORE_HASH;
} else if (B2B_API_TOKEN) {
headers['authToken'] = B2B_API_TOKEN;
}

They both should not be used at the same time, we should prefer the BIGCOMMERCE_TOKEN if possible.

.env.example Outdated
B2B_API_HOST=https://api-b2b.bigcommerce.com

# BigCommerce API token with B2B Edition scopes used to authenticate requests to the B2B API
BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE=

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's already being used in makeswift, let's stick to the existing name to reduce the number of things the user has to setup.

We can then just add that B2B scope is required in the setup docs.

@bc-victor
Copy link
Contributor Author

Updated this PR to use BIGCOMMERCE_ACCESS_TOKEN as defined here in the Makeswift integration.

Updating docs in this PR

Comment on lines 43 to 45
} else {
throw new Error(`No B2B API token or BigCommerce token found in environment variables.`);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only using the new BIGCOMMERCE_ACCESS_TOKEN, will break when existing customers upgrade to this version.

BIGCOMMERCE_CHANNEL_ID: z.string(),
BIGCOMMERCE_STORE_HASH: z.string(),
BIGCOMMERCE_ACCESS_TOKEN: z.string().optional(),
B2B_API_TOKEN: z.string().optional().describe('This is deprecated in favour or BIGCOMMERCE_ACCESS_TOKEN, read https://support.bigcommerce.com/s/article/Store-API-Accounts?language=en_US'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅 Not sure if we need the describe here.

We might want to define a union in this case:

z.union([
  z.object({
    BIGCOMMERCE_CHANNEL_ID: z.string(),
    B2B_API_TOKEN: z.string(),
  }),
  z.object({
    BIGCOMMERCE_CHANNEL_ID: z.string(),
    BIGCOMMERCE_STORE_HASH: z.string(),
    BIGCOMMERCE_ACCESS_TOKEN: z.string(),
  }),
])

The current approach makes BIGCOMMERCE_STORE_HASH mandatory, even for old consumers where it is not needed, and makes both B2B_API_TOKEN and BIGCOMMERCE_ACCESS_TOKEN which mean they can potentially be both missing.

@bc-victor bc-victor force-pushed the victor/b2b-makeswift branch from d8d8a48 to 0027b89 Compare October 16, 2025 19:22
@bc-victor bc-victor merged commit ab06c1b into integrations/b2b-makeswift Oct 16, 2025
11 checks passed
@bc-victor bc-victor deleted the victor/b2b-makeswift branch October 16, 2025 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants