Skip to main content

Metafields

Methods for handling metafields.

warning

Metafields may have sensitive data stored in these fields. Anything stored in these fields can be read by the customer if the scope is enabled.

Note: Metafields can be created, updated, and deleted via these APIs. Otherwise metafields can only be fetched via includes on the resources they exist on. All of these functions require the write scope of the owner_resource (charge/customer/order/etc.) and write storefront metafields scope.

Example:

await createMetafield(session, {
key: 'testKey',
namespace: 'test',
owner_id: 1234,
owner_resource: 'customer',
value: 'value',
value_type: 'string',
});

const customer = await getCustomer(session, { include: ['metafields'] });

const { metafields } = customer.include;

createMetafield v1.0.0 write storefront metafields Types

Create a metafield.

import { createMetafield } from '@rechargeapps/storefront-client';
await createMetafield(session, {
key: 'testKey',
namespace: 'test',
owner_id: 1234,
owner_resource: 'customer',
value: 'value',
value_type: 'string',
});

updateMetafield v1.0.0 write storefront metafields Types

Update a metafield

import { updateMetafield } from '@rechargeapps/storefront-client';
await updateMetafield(session, 123, { description: 'test_description' });

deleteMetafield v1.0.0 write storefront metafields Types

Delete a metafield.

import { deleteMetafield } from '@rechargeapps/storefront-client';
await deleteMetafield(session, 123);