From b01d8eabb3abbfd8a65062158bc6a31bbd629662 Mon Sep 17 00:00:00 2001 From: Wanjohi Date: Sat, 19 Sep 2026 00:59:36 +0300 Subject: [PATCH] fix(billing): an organization token already names its organization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creating a product with one sends `organization_id` alongside a token that implies it, which is refused outright rather than ignored — so which kind of token is in hand has to be known before the call, not after. A personal token can see several organizations and still has to say which. --- packages/core/scripts/polar-product.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/core/scripts/polar-product.ts b/packages/core/scripts/polar-product.ts index cf942d7e..e3412071 100644 --- a/packages/core/scripts/polar-product.ts +++ b/packages/core/scripts/polar-product.ts @@ -54,6 +54,15 @@ if (!accessToken) { const polar = new Polar({ accessToken, server }); +/** + * An organization token already names its organization. + * + * Sending `organizationId` alongside one is refused outright rather than + * ignored, so which kind of token this is has to be known before the call. A + * personal token can see several organizations and must say which. + */ +const scopedToOrganization = accessToken.startsWith('polar_oat_'); + const organizations = await polar.organizations.listOrganizations({ limit: 2 }); const organization = organizations.result.items.at(0); if (!organization) { @@ -89,7 +98,7 @@ if (!apply) { } const created = await polar.products.create({ - organizationId: organization.id, + ...(scopedToOrganization ? {} : { organizationId: organization.id }), name: PRODUCT.name, description: PRODUCT.description, recurringInterval: PRODUCT.recurringInterval,