Skip to content

fix(apps-vtex): create Master Data documents with app credentials - #743

Merged
aka-sacci-ccr merged 1 commit into
mainfrom
fix/apps-vtex-masterdata-create-auth
Oct 21, 2026
Merged

aka-sacci-ccr merged 1 commit into
mainfrom
fix/apps-vtex-masterdata-create-auth

Conversation

@aka-sacci-ccr

@aka-sacci-ccr aka-sacci-ccr commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

vtex.masterdata.create now sends X-VTEX-API-AppKey / X-VTEX-API-AppToken whenever the client is configured with them, leaving the shopper's cookie out of that call.

Why

VTEX is rejecting anonymous writes to /api/dataentities. call() only attaches app credentials when no cookie is passed (so shopper-scoped calls like the orderForm never come back with unmasked profile data). A masterdata.create called with the shopper's cookie therefore went out without credentials and failed.

The create response is only Id / Href / DocumentId, so sending it as the app unmasks nothing. The "no credentials next to a cookie" rule still holds: when credentials are used, the cookie is dropped.

  • With credentials: create always goes out as the app.
  • Without credentials: unchanged, the cookie is forwarded as before.
  • masterdata.search is unchanged.

Equivalent fix in deco-cx/apps: deco-cx/apps#1688

Note for sites

Sites need appKey / appToken with a role that has Dynamic Storage → Insert or update document. A site route or server function that exposes masterdata.create to the browser should pin the entity and whitelist fields, since writes now carry store credentials.

Testing

  • New test in vtexClient.test.ts covering both cases (with and without credentials).
  • apps-vtex tests (66), typecheck and biome pass.
  • Not yet tested against a live VTEX account.

🤖 Generated with Claude Code


Summary by cubic

Fixes vtex.masterdata.create so documents are written with store app credentials whenever they're configured, since VTEX now rejects anonymous writes to /api/dataentities.

Passing the shopper's cookie had made the client skip credentials, so those writes failed. With credentials configured, the call now goes out as the app and leaves the cookie out — safe because the create response only returns document IDs, nothing to unmask. Without credentials the behavior is unchanged, and masterdata.search is untouched.

Sites need an appKey/appToken with the Dynamic Storage → Insert or update document role. Any route or server function exposing masterdata.create to the browser should pin the entity and whitelist fields, because writes now carry store credentials.

Written for commit c750bc1. Summary will update on new commits.

View guided diff Turn on auto-fix

VTEX now rejects anonymous writes to /api/dataentities. The client only
attaches App Key/Token when no shopper cookie is passed, so a create
called with the cookie went out anonymous and failed. masterdata.create
now leaves the cookie out whenever credentials are configured; its
response is just the document ids, so there is nothing to unmask.
Without credentials it still forwards the cookie.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@aka-sacci-ccr
aka-sacci-ccr requested a review from a team October 21, 2026 14:12
@aka-sacci-ccr
aka-sacci-ccr merged commit 96522c1 into main Oct 21, 2026
4 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 8.5.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants