Upstorr provides typed input APIs for shopper-owned Customer, Order and Draft order metafields. Your theme supplies the form and its success/error presentation. Enabling a field does not automatically insert an input into Casa or checkout.
Permission and ownership
The merchant enables Customer input on the relevant definition in Settings → Custom data. This is default-off and separate from Storefront API access, which permits public reading but never writing. Keep personal information private.
Signed-in shoppers can access only their own Customer record and their own existing orders or draft orders. The server derives customer identity from its httpOnly session cookie; do not pass another customer ID or use Admin credentials. Guests can supply enabled Order inputs during checkout, not write shared product or store data.
Checkout inputs
import {
fetchThemeCheckout,
fetchThemeCheckoutMetafieldFields,
createThemeCheckoutDraft,
saveThemeCheckoutDraft,
} from '@upstorr/theme-sdk/v1';
const fields = await fetchThemeCheckoutMetafieldFields();
const giftMessage = fields.find(field => field.namespace === 'custom' && field.key === 'gift_message');
if (!giftMessage) throw new Error('Gift message is not enabled.');
const checkout = await fetchThemeCheckout('checkout');
const draft = createThemeCheckoutDraft(checkout);
const otherInputs = (draft.metafieldInputs ?? []).filter(input =>
input.namespace !== giftMessage.namespace || input.key !== giftMessage.key);
const updated = await saveThemeCheckoutDraft('checkout', {
...draft,
metafieldInputs: [...otherInputs, {
namespace: giftMessage.namespace,
key: giftMessage.key,
value: 'Happy birthday!',
}],
});
// Render updated state, then continue the normal checkout submission flow.
metafieldInputs replaces the complete desired list: preserve other fields when changing one. Send [] to remove all inputs; omit it to leave them unchanged. Use the latest draft version and reload on a conflict rather than silently overwriting another tab.
Inputs are validated on save, before payment preparation and during order creation. Values are saved atomically with the order, not separately before payment. A completed checkout retry must resolve the same order rather than creating duplicate values. Checkout inputs target Order definitions; they are not a new cart-metafield owner or a way to write a draft order.
Existing account, order and draft inputs
import { fetchThemeCustomerMetafields, saveThemeCustomerMetafields } from '@upstorr/theme-sdk/v1';
const owner = { ownerType: 'CUSTOMER' } as const;
const { fields, values } = await fetchThemeCustomerMetafields(owner);
const field = fields.find(item => item.namespace === 'custom' && item.key === 'contact_preference');
if (!field) throw new Error('Contact preference is not enabled.');
const saved = values.find(item => item.fieldDefinitionId === field.id);
await saveThemeCustomerMetafields(owner, [{
fieldDefinitionId: field.id,
operation: 'set',
expectedRevision: saved?.revision ?? null,
value: 'Email only',
}]);
Use { ownerType: 'ORDER', resourceId: orderId } or { ownerType: 'DRAFT_ORDER', resourceId: draftOrderId } for owned records. Read again after saving for current revisions. To clear a value, send operation: 'clear', the current revision and no value. Null revision means no saved value may already exist. A batch is atomic.
Validation, limits and errors
Use the definition's actual type and validation rules, including lists and reference restrictions. References must be valid for this store and shopper. Files must be ready public media; metaobject references need active, publicly accessible entries. These APIs neither upload files nor create entries.
Requests are limited to 25 distinct fields and 256 KiB of input, plus existing per-type limits. Preserve list order. Handle SDK error status and payload: 400 for invalid or disabled input, 401 for sign-in, 404 for unavailable ownership, 409 for stale revisions and 413 for excessive size. Keep entered form data while explaining the error; do not automatically replay a stale write.
Use normal SDK cookies and CSRF handling through the storefront proxy. Never add direct API requests, access tokens or Admin credentials to a theme. Treat shopper input as untrusted and render it with typed, escaped helpers.