Skip to main content

Metafields

Methods for handling metafields.

info

Metafields are not available by default due to the possibility of sensitive data being stored in these fields. If you would like to enable Metafields for storefront access please reach out to Recharge support to enable this.

This also applies to metafields includes on other functions.

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 for the metafield.

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 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 Types

Update a metafield

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

deleteMetafield v1.0.0 write Types

Delete a metafield.

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