<!-- ZenPays documentation · https://docs.zenpayz.com/docs/rest-api/endpoints/billing/products/create-product -->

# Create Product

Create a new product for billing and invoicing.

<EndpointHeader verb="POST" path="/merchant/api/v1/products" />

## Request

### Headers

<ParamTable
  label="Header"
  rows={[
    { name: "Authorization", required: true, desc: "`Bearer {api_key}`" },
    { name: "X-Signature", required: true, desc: "HMAC-SHA256 signature" },
    { name: "X-Timestamp", required: true, desc: "ISO 8601 timestamp" },
    { name: "X-Secret-Salt", required: true, desc: "Secret salt for HMAC validation" },
    { name: "Content-Type", required: true, desc: "`application/json`" },
  ]}
/>

### Body Parameters

<ParamTable
  rows={[
    { name: "name", type: "string", required: true, desc: "Product name (1-255 characters)" },
    { name: "description", type: "string", desc: "Product description" },
    { name: "price", type: "number", required: true, desc: "Product price (minimum 0)" },
    { name: "currency", type: "string", desc: "Currency code (default: `INR`). One of `USD`, `INR`, `EUR`, `GBP`" },
    { name: "sku", type: "string", desc: "Stock keeping unit (1-100 characters)" },
    { name: "status", type: "string", desc: "Product status (default: `ACTIVE`). One of `ACTIVE`, `INACTIVE`, `ARCHIVED`" },
    { name: "categoryId", type: "number", desc: "Category ID to assign the product to" },
    {
      name: "images",
      type: "array",
      desc: "Array of product images",
      nested: [
        { name: "images[].url", type: "string", required: true, desc: "Image URL" },
        { name: "images[].alt", type: "string", desc: "Alt text for the image" },
        { name: "images[].isPrimary", type: "boolean", desc: "Whether this is the primary image" },
      ],
    },
    {
      name: "pricingTiers",
      type: "array",
      desc: "Array of pricing tiers",
      nested: [
        { name: "pricingTiers[].name", type: "string", required: true, desc: "Tier name" },
        { name: "pricingTiers[].price", type: "number", required: true, desc: "Tier price (minimum 0)" },
        { name: "pricingTiers[].description", type: "string", desc: "Tier description" },
        { name: "pricingTiers[].features", type: "string[]", desc: "List of features included in the tier" },
      ],
    },
    { name: "metadata", type: "object", desc: "Custom key-value pairs" },
  ]}
/>

## Response

### Success (201 Created)

```json
{
  "success": true,
  "data": {
    "productId": "prod_a1b2c3d4e5f6g7h8",
    "name": "Pro Plan",
    "description": "Professional subscription plan with advanced features",
    "price": 4999,
    "currency": "INR",
    "sku": "PRO-PLAN-001",
    "status": "ACTIVE",
    "categoryId": 1,
    "images": [
      {
        "url": "https://example.com/images/pro-plan.png",
        "alt": "Pro Plan",
        "isPrimary": true
      }
    ],
    "pricingTiers": [
      {
        "name": "Monthly",
        "price": 4999,
        "description": "Billed monthly",
        "features": ["Unlimited access", "Priority support"]
      }
    ],
    "metadata": {},
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-01-15T10:30:00.000Z"
  },
  "message": "Product created successfully",
  "error": null,
  "meta": {
    "request_id": "req_xxxxx",
    "timestamp": "2024-01-15T10:30:00.000Z",
    "processing_time_ms": 45,
    "api_version": "v1",
    "endpoint": "POST /products",
    "user_type": "merchant"
  }
}
```

### Error Responses

<ErrorTable
  rows={[
    { code: "VALIDATION_ERROR", status: "400", message: "Invalid request parameters" },
    { code: "UNAUTHORIZED", status: "401", message: "Invalid API key" },
    { code: "DUPLICATE_SKU", status: "409", message: "Product with this SKU already exists" },
  ]}
/>

<CodeRail>

## Examples

<Tabs groupId="language">
  <TabItem value="curl" label="cURL" default>

```bash
curl -X POST https://api.zenpayz.com/merchant/api/v1/products \
  -H "Authorization: Bearer zp_test_xxxxx" \
  -H "X-Timestamp: 2024-01-15T10:30:00.000Z" \
  -H "X-Signature: a1b2c3d4e5f6..." \
  -H "X-Secret-Salt: your_secret_salt" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Pro Plan",
    "description": "Professional subscription plan with advanced features",
    "price": 4999,
    "currency": "INR",
    "sku": "PRO-PLAN-001",
    "status": "ACTIVE",
    "categoryId": 1,
    "images": [
      {
        "url": "https://example.com/images/pro-plan.png",
        "alt": "Pro Plan",
        "isPrimary": true
      }
    ],
    "pricingTiers": [
      {
        "name": "Monthly",
        "price": 4999,
        "description": "Billed monthly",
        "features": ["Unlimited access", "Priority support"]
      }
    ]
  }'
```

  </TabItem>
  <TabItem value="javascript" label="JavaScript">

```javascript
const response = await fetch('https://api.zenpayz.com/merchant/api/v1/products', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'X-Timestamp': timestamp,
    'X-Signature': signature,
    'X-Secret-Salt': secretSalt,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'Pro Plan',
    description: 'Professional subscription plan with advanced features',
    price: 4999,
    currency: 'INR',
    sku: 'PRO-PLAN-001',
    status: 'ACTIVE',
    categoryId: 1,
    images: [
      {
        url: 'https://example.com/images/pro-plan.png',
        alt: 'Pro Plan',
        isPrimary: true,
      },
    ],
    pricingTiers: [
      {
        name: 'Monthly',
        price: 4999,
        description: 'Billed monthly',
        features: ['Unlimited access', 'Priority support'],
      },
    ],
  }),
});

const result = await response.json();
console.log(result.data.productId); // prod_a1b2c3d4e5f6g7h8
```

  </TabItem>
  <TabItem value="sdk" label="SDK">

```javascript
const product = await zenpays.products.create({
  name: 'Pro Plan',
  description: 'Professional subscription plan with advanced features',
  price: 4999,
  currency: 'INR',
  sku: 'PRO-PLAN-001',
  status: 'ACTIVE',
  categoryId: 1,
  images: [
    {
      url: 'https://example.com/images/pro-plan.png',
      alt: 'Pro Plan',
      isPrimary: true,
    },
  ],
  pricingTiers: [
    {
      name: 'Monthly',
      price: 4999,
      description: 'Billed monthly',
      features: ['Unlimited access', 'Priority support'],
    },
  ],
});

console.log(product.productId); // prod_a1b2c3d4e5f6g7h8
```

  </TabItem>
</Tabs>

</CodeRail>

## Related Endpoints

- [List Products](/docs/rest-api/endpoints/billing/products/list-products)
- [Get Product](/docs/rest-api/endpoints/billing/products/get-product)
- [Update Product](/docs/rest-api/endpoints/billing/products/update-product)
- [Delete Product](/docs/rest-api/endpoints/billing/products/delete-product)
