> ## Documentation Index
> Fetch the complete documentation index at: https://docs.napps.io/llms.txt
> Use this file to discover all available pages before exploring further.

# ProductService

`ProductService` lets you fetch product information and product metafields.

Use it when your extension needs product data that is not already available in the current context.

## Global Name

```ts theme={null}
productService
```

## API

```ts theme={null}
interface ProductService {
  getProductByID(productId: string): Promise<Product | null>;
  getProductByHandle(handle: string): Promise<Product | null>;
  getProductMetaFields(
    productId: string,
    metaFields: string[]
  ): Promise<MetaFieldDetails>;
}
```

## Product

```ts theme={null}
interface Product {
  id: string;
  name: string;
  vendor: string;
  collectionIDs: string[];
  tags: string[];
  discountPercentage: number;
  thumbnail: string | null;
  metaFields(keys: string[]): object;
  getMetaFields(keys: string[]): Promise<unknown>;
}
```

## Methods

> **Implementation note:** `getProductByID` and `getProductByHandle` are exposed as promises. Verify the app version's resolution behavior before depending on either lookup in production; use `getProductMetaFields` or the documented call APIs when a lookup is not available in your target runtime.

### getProductByID

Fetches a product by ID.

```ts theme={null}
const product = await productService.getProductByID(
  "gid://shopify/Product/123"
);

if (product) {
  console.log(product.name);
}
```

Returns `null` when the product is not found.

### getProductByHandle

Fetches a product by handle.

```ts theme={null}
const product = await productService.getProductByHandle("my-product-handle");
```

Returns `null` when the product is not found.

### getProductMetaFields

Fetches product metafields.

Pass metafield keys using `namespace.key` format.

```ts theme={null}
const metafields = await productService.getProductMetaFields(
  "gid://shopify/Product/123",
  ["custom.material", "custom.care"]
);
```

The result is returned by the native product API. Treat its shape as `unknown` unless your shop's metafield schema provides a narrower type.

```ts theme={null}
type MetaFieldDetails = Record<string, Record<string, MetafieldValue>>;
```

## Metafield Values

Metafield values can be strings, numbers, booleans, arrays, media objects, metaobjects, objects, or `null`.

```ts theme={null}
type MetafieldValue =
  | boolean
  | number
  | string
  | object
  | MetaFieldMedia
  | MetaFieldMedia[]
  | string[]
  | object[]
  | MetaObject
  | MetaObject[]
  | null;
```
