# Create a price variant

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

This endpoint allows the creation of a new price variant that can be attached to [item prices](/docs/api/item_prices).

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/price_variants \
     -u {site_api_key}:\
     -d id="germany-berlin" \
     -d name="Germany Berlin" \
     -d external_name="Germany" \
     -d "attributes[name][0]"="country" \
     -d "attributes[value][0]"="germany" \
     -d "attributes[name][1]"="city" \
     -d "attributes[value][1]"="berlin"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PriceVariant.Create()
		.Id("germany-berlin")
		.Name("Germany Berlin")
		.ExternalName("Germany")
		.AttributeName(0, "country")
		.AttributeValue(0, "germany")
		.AttributeName(1, "city")
		.AttributeValue(1, "berlin")
		.Request();

PriceVariant priceVariant = result.PriceVariant;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    pricevariantAction "github.com/chargebee/chargebee-go/v3/actions/pricevariant"
    "github.com/chargebee/chargebee-go/v3/models/pricevariant"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := pricevariantAction.Create(&pricevariant.CreateRequestParams{
        Attributes : []*pricevariant.CreateAttributeParams{
            {
                Name : "country",
                Value : "germany",
            },
            {
                Name : "city",
                Value : "berlin",
            },
        },
        Id : "germany-berlin",
        Name : "Germany Berlin",
        ExternalName : "Germany",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        PriceVariant := res.PriceVariant
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.PriceVariantCreateRequest{
    Attributes : []*chargebee.PriceVariantCreateAttribute{
        {
            Name : "country",
            Value : "germany",
        },
        {
            Name : "city",
            Value : "berlin",
        },
    },
    Id : "germany-berlin",
    Name : "Germany Berlin",
    ExternalName : "Germany",
}
  res, err := client.PriceVariant.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        PriceVariant := res.PriceVariant
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = PriceVariant.create()
            .id("germany-berlin")
            .name("Germany Berlin")
            .externalName("Germany")
            .attributeName(0, "country")
            .attributeValue(0, "germany")
            .attributeName(1, "city")
            .attributeValue(1, "berlin")
            .request();

        PriceVariant priceVariant = result.priceVariant();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.priceVariant.PriceVariant;
import com.chargebee.v4.models.priceVariant.params.PriceVariantCreateParams;
import com.chargebee.v4.models.priceVariant.responses.PriceVariantCreateResponse;
import java.util.List;

public class PriceVariantCreate {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        PriceVariantCreateParams.AttributesParams attribute0 =
            PriceVariantCreateParams.AttributesParams.builder()
                .name("country")
                .value("germany")
                .build();

        PriceVariantCreateParams.AttributesParams attribute1 =
            PriceVariantCreateParams.AttributesParams.builder()
                .name("city")
                .value("berlin")
                .build();

        List<PriceVariantCreateParams.AttributesParams> attributesList =
            List.of(attribute0, attribute1);

        PriceVariantCreateParams params = PriceVariantCreateParams.builder()
            .id("germany-berlin")
            .name("Germany Berlin")
            .externalName("Germany")
            .attributes(attributesList)
            .build();

        PriceVariantCreateResponse response = client.priceVariants().create(params);

        PriceVariant priceVariant = response.getPriceVariant();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.priceVariant.create({
        attributes: [
            {
                name: "country",
                value: "germany"
            },
            {
                name: "city",
                value: "berlin"
            }
        ],
        id: "germany-berlin",
        name: "Germany Berlin",
        external_name: "Germany"
    });

    console.log(result);
    const priceVariant = result.price_variant;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->priceVariant()->create([
    "attributes" => [
        [
            "name" => "country",
            "value" => "germany"
        ],
        [
            "name" => "city",
            "value" => "berlin"
        ]
    ],
    "id" => "germany-berlin",
    "name" => "Germany Berlin",
    "external_name" => "Germany"
]);
$priceVariant = $result->price_variant;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.PriceVariant.create(
    cb_client.PriceVariant.CreateParams(
        attributes=[
            cb_client.PriceVariant.CreateAttributeParams(
              name="country",
              value="germany"
            ),
            cb_client.PriceVariant.CreateAttributeParams(
              name="city",
              value="berlin"
            )
        ],
        id="germany-berlin",
        name="Germany Berlin",
        external_name="Germany"
    )
)
price_variant = response.price_variant
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::PriceVariant.create({
  :id => "germany-berlin",
  :name => "Germany Berlin",
  :external_name => "Germany",
  :attributes => [
    {
      :name => "country",
      :value => "germany"
    },
    {
      :name => "city",
      :value => "berlin"
    }
  ]
})

price_variant = result.price_variant
```

## Sample Response

```json
{
  "price_variant": {
    "updated_at": 1709200385,
    "name": "Germany Berlin",
    "created_at": 1709200385,
    "attributes": [
      {
        "name": "country",
        "value": "germany"
      },
      {..}
    ],
    "id": "germany-berlin",
    "external_name": "Germany",
    "resource_version": 1709200385728,
    "status": "active",
    "object": "price_variant"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/price_variants

## Input Parameters

- `id` (required, string, max chars=100)
  The unique and immutable identifier of the price variant.

- `name` (required, string, max chars=100)
  A unique name of the price variant.

- `external_name` (optional, string, max chars=100)
  A unique display name for the price variant.

- `description` (optional, string, max chars=500)
  Description of the price variant.

- `variant_group` (optional, string, max chars=100)
  The `variant_group` organizes similar `[price_variants](/docs/api/price_variants)` to optimize strategies such as bundling, geo-based pricing experiments, and campaign-specific pricing like `cb-atomic-pricing-` for effective grouping. The `variant_group` provides greater flexibility and precision in your pricing models.

- `business_entity_id` (optional, string, max chars=50)
  The unique ID of the [business entity](/docs/api/business_entities) for this `price_variant`. This is applicable only when multiple business entities have been created for the site. When provided, the operation will read or write data associated with the specified business entity. If not provided, the resource will be created at the site level, and the `business_entity_id` will not be included in the API response.
  
  **Note** An alternative way of passing this parameter is by means of a [custom HTTP header](/docs/api/advanced-features#mbe-header-main).

- `attributes` (optional, array)
  The list of price variant attribute values. Attributes can be used to store additional information about the price variant. For example, for a price variant called 'Germany', the attributes can be 'Country':'Germany', 'City':'Berlin' and so on.
  - `name` (required, string, max chars=100)
    Attribute name
  - `value` (required, string, max chars=100)
    Attribute value

## Returns

- `price_variant` (Price variant object)
  Resource object representing price\_variant
