# Create a feature

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


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

Creates a new feature.

**Note:** This operation creates non-metered features only. To create a metered feature, use the [Create a metered feature](/docs/api/metered_features#create_a_metered_feature) operation.

## Sample Request

### create a switch feature

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/features \
     -u {site_api_key}:\
     -d name="Quickbooks Integration_123" \
     -d type="SWITCH" \
     -d description="Integration of Chargebee with Quickbooks"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Feature.Create()
		.Name("Quickbooks Integration_123")
		.Type(Feature.TypeEnum.Switch)
		.Description("Integration of Chargebee with Quickbooks")
		.Request();

Feature feature = result.Feature;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    featureAction "github.com/chargebee/chargebee-go/v3/actions/feature"
    "github.com/chargebee/chargebee-go/v3/models/feature"
    featureEnum "github.com/chargebee/chargebee-go/v3/models/feature/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := featureAction.Create(&feature.CreateRequestParams{
        Name : "Quickbooks Integration_123",
        Type : featureEnum.TypeSwitch,
        Description : "Integration of Chargebee with Quickbooks",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Feature := res.Feature
    }
}
```

#### 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.FeatureCreateRequest{
    Name : "Quickbooks Integration_123",
    Type : chargebee.FeatureTypeSwitch,
    Description : "Integration of Chargebee with Quickbooks",
}
  res, err := client.Feature.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Feature := res.Feature
    }
}
```

#### 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 = Feature.create()
            .name("Quickbooks Integration_123")
            .type(Feature.Type.SWITCH)
            .description("Integration of Chargebee with Quickbooks")
            .request();

        Feature feature = result.feature();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.feature.Feature;
import com.chargebee.v4.models.feature.params.FeatureCreateParams;
import com.chargebee.v4.models.feature.responses.FeatureCreateResponse;

public class FeatureCreate {

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

        FeatureCreateParams params = FeatureCreateParams.builder()
            .name("Quickbooks Integration_123")
            .type(FeatureCreateParams.Type.SWITCH)
            .description("Integration of Chargebee with Quickbooks")
            .build();

        FeatureCreateResponse response = client.features().create(params);

        Feature feature = response.getFeature();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.feature.create({
        name: "Quickbooks Integration_123",
        type: "switch",
        description: "Integration of Chargebee with Quickbooks"
    });

    console.log(result);
    const feature = result.feature;
} 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->feature()->create([
    "name" => "Quickbooks Integration_123",
    "type" => "switch",
    "description" => "Integration of Chargebee with Quickbooks"
]);
$feature = $result->feature;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Feature.create(
    cb_client.Feature.CreateParams(
        name="Quickbooks Integration_123",
        type=chargebee.Feature.Type.SWITCH,
        description="Integration of Chargebee with Quickbooks"
    )
)
feature = response.feature
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Feature.create({
  :name => "Quickbooks Integration_123",
  :type => "SWITCH",
  :description => "Integration of Chargebee with Quickbooks"
})

feature = result.feature
```

### create a custom type feature

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/features \
     -u {site_api_key}:\
     -d name="Phone Support" \
     -d type="CUSTOM" \
     -d "levels[level][0]"=0 \
     -d "levels[value][0]"="24 * 5" \
     -d "levels[name][0]"="24 * 5" \
     -d "levels[level][1]"=1 \
     -d "levels[value][1]"="24 * 7" \
     -d "levels[name][1]"="24 * 7"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Feature.Create()
		.Name("Phone Support")
		.Type(Feature.TypeEnum.Custom)
		.LevelLevel(0, 0)
		.LevelValue(0, "24 * 5")
		.LevelName(0, "24 * 5")
		.LevelLevel(1, 1)
		.LevelValue(1, "24 * 7")
		.LevelName(1, "24 * 7")
		.Request();

Feature feature = result.Feature;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    featureAction "github.com/chargebee/chargebee-go/v3/actions/feature"
    "github.com/chargebee/chargebee-go/v3/models/feature"
    featureEnum "github.com/chargebee/chargebee-go/v3/models/feature/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := featureAction.Create(&feature.CreateRequestParams{
        Levels : []*feature.CreateLevelParams{
            {
                Level : chargebee.Int32(0),
                Value : "24 * 5",
                Name : "24 * 5",
            },
            {
                Level : chargebee.Int32(1),
                Value : "24 * 7",
                Name : "24 * 7",
            },
        },
        Name : "Phone Support",
        Type : featureEnum.TypeCustom,
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Feature := res.Feature
    }
}
```

#### 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.FeatureCreateRequest{
    Levels : []*chargebee.FeatureCreateLevel{
        {
            Level : chargebee.Int32(0),
            Value : "24 * 5",
            Name : "24 * 5",
        },
        {
            Level : chargebee.Int32(1),
            Value : "24 * 7",
            Name : "24 * 7",
        },
    },
    Name : "Phone Support",
    Type : chargebee.FeatureTypeCustom,
}
  res, err := client.Feature.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Feature := res.Feature
    }
}
```

#### 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 = Feature.create()
            .name("Phone Support")
            .type(Feature.Type.CUSTOM)
            .levelLevel(0, 0)
            .levelValue(0, "24 * 5")
            .levelName(0, "24 * 5")
            .levelLevel(1, 1)
            .levelValue(1, "24 * 7")
            .levelName(1, "24 * 7")
            .request();

        Feature feature = result.feature();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.feature.Feature;
import com.chargebee.v4.models.feature.params.FeatureCreateParams;
import com.chargebee.v4.models.feature.responses.FeatureCreateResponse;
import java.util.List;

public class FeatureCreate {

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

        FeatureCreateParams.LevelsParams level0 =
            FeatureCreateParams.LevelsParams.builder()
                .level(0)
                .value("24 * 5")
                .name("24 * 5")
                .build();

        FeatureCreateParams.LevelsParams level1 =
            FeatureCreateParams.LevelsParams.builder()
                .level(1)
                .value("24 * 7")
                .name("24 * 7")
                .build();

        List<FeatureCreateParams.LevelsParams> levelsList =
            List.of(level0, level1);

        FeatureCreateParams params = FeatureCreateParams.builder()
            .name("Phone Support")
            .type(FeatureCreateParams.Type.CUSTOM)
            .levels(levelsList)
            .build();

        FeatureCreateResponse response = client.features().create(params);

        Feature feature = response.getFeature();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.feature.create({
        levels: [
            {
                level: 0,
                value: "24 * 5",
                name: "24 * 5"
            },
            {
                level: 1,
                value: "24 * 7",
                name: "24 * 7"
            }
        ],
        name: "Phone Support",
        type: "custom"
    });

    console.log(result);
    const feature = result.feature;
} 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->feature()->create([
    "levels" => [
        [
            "level" => 0,
            "value" => "24 * 5",
            "name" => "24 * 5"
        ],
        [
            "level" => 1,
            "value" => "24 * 7",
            "name" => "24 * 7"
        ]
    ],
    "name" => "Phone Support",
    "type" => "custom"
]);
$feature = $result->feature;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Feature.create(
    cb_client.Feature.CreateParams(
        levels=[
            cb_client.Feature.CreateLevelParams(
              level=0,
              value="24 * 5",
              name="24 * 5"
            ),
            cb_client.Feature.CreateLevelParams(
              level=1,
              value="24 * 7",
              name="24 * 7"
            )
        ],
        name="Phone Support",
        type=chargebee.Feature.Type.CUSTOM
    )
)
feature = response.feature
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Feature.create({
  :name => "Phone Support",
  :type => "CUSTOM",
  :levels => [
    {
      :level => 0,
      :value => "24 * 5",
      :name => "24 * 5"
    },
    {
      :level => 1,
      :value => "24 * 7",
      :name => "24 * 7"
    }
  ]
})

feature = result.feature
```

### create a quantity type feature

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/features \
     -u {site_api_key}:\
     -d name="User Licenses" \
     -d type="QUANTITY" \
     -d description="Maximum user licenses allowed" \
     -d "levels[level][0]"=0 \
     -d "levels[value][0]"="5" \
     -d "levels[name][0]"="5 Users" \
     -d "levels[level][1]"=1 \
     -d "levels[value][1]"="10" \
     -d "levels[name][1]"="10 Users" \
     -d "levels[level][2]"=2 \
     -d "levels[value][2]"="Unlimited" \
     -d "levels[name][2]"="Unlimited Users" \
     -d "levels[is_unlimited][2]"="true"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Feature.Create()
		.Name("User Licenses")
		.Type(Feature.TypeEnum.Quantity)
		.Description("Maximum user licenses allowed")
		.LevelLevel(0, 0)
		.LevelValue(0, "5")
		.LevelName(0, "5 Users")
		.LevelLevel(1, 1)
		.LevelValue(1, "10")
		.LevelName(1, "10 Users")
		.LevelLevel(2, 2)
		.LevelValue(2, "Unlimited")
		.LevelName(2, "Unlimited Users")
		.LevelIsUnlimited(2, true)
		.Request();

Feature feature = result.Feature;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    featureAction "github.com/chargebee/chargebee-go/v3/actions/feature"
    "github.com/chargebee/chargebee-go/v3/models/feature"
    featureEnum "github.com/chargebee/chargebee-go/v3/models/feature/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := featureAction.Create(&feature.CreateRequestParams{
        Levels : []*feature.CreateLevelParams{
            {
                Level : chargebee.Int32(0),
                Value : "5",
                Name : "5 Users",
            },
            {
                Level : chargebee.Int32(1),
                Value : "10",
                Name : "10 Users",
            },
            {
                Level : chargebee.Int32(2),
                Value : "Unlimited",
                Name : "Unlimited Users",
                IsUnlimited : chargebee.Bool(true),
            },
        },
        Name : "User Licenses",
        Type : featureEnum.TypeQuantity,
        Description : "Maximum user licenses allowed",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Feature := res.Feature
    }
}
```

#### 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.FeatureCreateRequest{
    Levels : []*chargebee.FeatureCreateLevel{
        {
            Level : chargebee.Int32(0),
            Value : "5",
            Name : "5 Users",
        },
        {
            Level : chargebee.Int32(1),
            Value : "10",
            Name : "10 Users",
        },
        {
            Level : chargebee.Int32(2),
            Value : "Unlimited",
            Name : "Unlimited Users",
            IsUnlimited : chargebee.Bool(true),
        },
    },
    Name : "User Licenses",
    Type : chargebee.FeatureTypeQuantity,
    Description : "Maximum user licenses allowed",
}
  res, err := client.Feature.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Feature := res.Feature
    }
}
```

#### 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 = Feature.create()
            .name("User Licenses")
            .type(Feature.Type.QUANTITY)
            .description("Maximum user licenses allowed")
            .levelLevel(0, 0)
            .levelValue(0, "5")
            .levelName(0, "5 Users")
            .levelLevel(1, 1)
            .levelValue(1, "10")
            .levelName(1, "10 Users")
            .levelLevel(2, 2)
            .levelValue(2, "Unlimited")
            .levelName(2, "Unlimited Users")
            .levelIsUnlimited(2, true)
            .request();

        Feature feature = result.feature();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.feature.Feature;
import com.chargebee.v4.models.feature.params.FeatureCreateParams;
import com.chargebee.v4.models.feature.responses.FeatureCreateResponse;
import java.util.List;

public class FeatureCreate {

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

        FeatureCreateParams.LevelsParams level0 =
            FeatureCreateParams.LevelsParams.builder()
                .level(0)
                .value("5")
                .name("5 Users")
                .build();

        FeatureCreateParams.LevelsParams level1 =
            FeatureCreateParams.LevelsParams.builder()
                .level(1)
                .value("10")
                .name("10 Users")
                .build();

        FeatureCreateParams.LevelsParams level2 =
            FeatureCreateParams.LevelsParams.builder()
                .level(2)
                .value("Unlimited")
                .name("Unlimited Users")
                .isUnlimited(true)
                .build();

        List<FeatureCreateParams.LevelsParams> levelsList =
            List.of(level0, level1, level2);

        FeatureCreateParams params = FeatureCreateParams.builder()
            .name("User Licenses")
            .type(FeatureCreateParams.Type.QUANTITY)
            .description("Maximum user licenses allowed")
            .levels(levelsList)
            .build();

        FeatureCreateResponse response = client.features().create(params);

        Feature feature = response.getFeature();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.feature.create({
        levels: [
            {
                level: 0,
                value: 5,
                name: "5 Users"
            },
            {
                level: 1,
                value: 10,
                name: "10 Users"
            },
            {
                level: 2,
                value: "Unlimited",
                name: "Unlimited Users",
                is_unlimited: true
            }
        ],
        name: "User Licenses",
        type: "quantity",
        description: "Maximum user licenses allowed"
    });

    console.log(result);
    const feature = result.feature;
} 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->feature()->create([
    "levels" => [
        [
            "level" => 0,
            "value" => 5,
            "name" => "5 Users"
        ],
        [
            "level" => 1,
            "value" => 10,
            "name" => "10 Users"
        ],
        [
            "level" => 2,
            "value" => "Unlimited",
            "name" => "Unlimited Users",
            "is_unlimited" => true
        ]
    ],
    "name" => "User Licenses",
    "type" => "quantity",
    "description" => "Maximum user licenses allowed"
]);
$feature = $result->feature;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Feature.create(
    cb_client.Feature.CreateParams(
        levels=[
            cb_client.Feature.CreateLevelParams(
              level=0,
              value="5",
              name="5 Users"
            ),
            cb_client.Feature.CreateLevelParams(
              level=1,
              value="10",
              name="10 Users"
            ),
            cb_client.Feature.CreateLevelParams(
              level=2,
              value="Unlimited",
              name="Unlimited Users",
              is_unlimited=True
            )
        ],
        name="User Licenses",
        type=chargebee.Feature.Type.QUANTITY,
        description="Maximum user licenses allowed"
    )
)
feature = response.feature
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Feature.create({
  :name => "User Licenses",
  :type => "QUANTITY",
  :description => "Maximum user licenses allowed",
  :levels => [
    {
      :level => 0,
      :value => "5",
      :name => "5 Users"
    },
    {
      :level => 1,
      :value => "10",
      :name => "10 Users"
    },
    {
      :level => 2,
      :value => "Unlimited",
      :name => "Unlimited Users",
      :is_unlimited => "true"
    }
  ]
})

feature = result.feature
```

### create a range type feature

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/features \
     -u {site_api_key}:\
     -d name="API call limit" \
     -d type="RANGE" \
     -d description="API call limit" \
     -d "levels[level][0]"=0 \
     -d "levels[value][0]"="5" \
     -d "levels[name][0]"="5 calls/month" \
     -d "levels[level][1]"=1 \
     -d "levels[value][1]"="100" \
     -d "levels[name][1]"="100 calls/month"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Feature.Create()
		.Name("API call limit")
		.Type(Feature.TypeEnum.Range)
		.Description("API call limit")
		.LevelLevel(0, 0)
		.LevelValue(0, "5")
		.LevelName(0, "5 calls/month")
		.LevelLevel(1, 1)
		.LevelValue(1, "100")
		.LevelName(1, "100 calls/month")
		.Request();

Feature feature = result.Feature;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    featureAction "github.com/chargebee/chargebee-go/v3/actions/feature"
    "github.com/chargebee/chargebee-go/v3/models/feature"
    featureEnum "github.com/chargebee/chargebee-go/v3/models/feature/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := featureAction.Create(&feature.CreateRequestParams{
        Levels : []*feature.CreateLevelParams{
            {
                Level : chargebee.Int32(0),
                Value : "5",
                Name : "5 calls/month",
            },
            {
                Level : chargebee.Int32(1),
                Value : "100",
                Name : "100 calls/month",
            },
        },
        Name : "API call limit",
        Type : featureEnum.TypeRange,
        Description : "API call limit",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Feature := res.Feature
    }
}
```

#### 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.FeatureCreateRequest{
    Levels : []*chargebee.FeatureCreateLevel{
        {
            Level : chargebee.Int32(0),
            Value : "5",
            Name : "5 calls/month",
        },
        {
            Level : chargebee.Int32(1),
            Value : "100",
            Name : "100 calls/month",
        },
    },
    Name : "API call limit",
    Type : chargebee.FeatureTypeRange,
    Description : "API call limit",
}
  res, err := client.Feature.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Feature := res.Feature
    }
}
```

#### 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 = Feature.create()
            .name("API call limit")
            .type(Feature.Type.RANGE)
            .description("API call limit")
            .levelLevel(0, 0)
            .levelValue(0, "5")
            .levelName(0, "5 calls/month")
            .levelLevel(1, 1)
            .levelValue(1, "100")
            .levelName(1, "100 calls/month")
            .request();

        Feature feature = result.feature();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.feature.Feature;
import com.chargebee.v4.models.feature.params.FeatureCreateParams;
import com.chargebee.v4.models.feature.responses.FeatureCreateResponse;
import java.util.List;

public class FeatureCreate {

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

        FeatureCreateParams.LevelsParams level0 =
            FeatureCreateParams.LevelsParams.builder()
                .level(0)
                .value("5")
                .name("5 calls/month")
                .build();

        FeatureCreateParams.LevelsParams level1 =
            FeatureCreateParams.LevelsParams.builder()
                .level(1)
                .value("100")
                .name("100 calls/month")
                .build();

        List<FeatureCreateParams.LevelsParams> levelsList =
            List.of(level0, level1);

        FeatureCreateParams params = FeatureCreateParams.builder()
            .name("API call limit")
            .type(FeatureCreateParams.Type.RANGE)
            .description("API call limit")
            .levels(levelsList)
            .build();

        FeatureCreateResponse response = client.features().create(params);

        Feature feature = response.getFeature();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.feature.create({
        levels: [
            {
                level: 0,
                value: 5,
                name: "5 calls/month"
            },
            {
                level: 1,
                value: 100,
                name: "100 calls/month"
            }
        ],
        name: "API call limit",
        type: "range",
        description: "API call limit"
    });

    console.log(result);
    const feature = result.feature;
} 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->feature()->create([
    "levels" => [
        [
            "level" => 0,
            "value" => 5,
            "name" => "5 calls/month"
        ],
        [
            "level" => 1,
            "value" => 100,
            "name" => "100 calls/month"
        ]
    ],
    "name" => "API call limit",
    "type" => "range",
    "description" => "API call limit"
]);
$feature = $result->feature;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Feature.create(
    cb_client.Feature.CreateParams(
        levels=[
            cb_client.Feature.CreateLevelParams(
              level=0,
              value="5",
              name="5 calls/month"
            ),
            cb_client.Feature.CreateLevelParams(
              level=1,
              value="100",
              name="100 calls/month"
            )
        ],
        name="API call limit",
        type=chargebee.Feature.Type.RANGE,
        description="API call limit"
    )
)
feature = response.feature
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Feature.create({
  :name => "API call limit",
  :type => "RANGE",
  :description => "API call limit",
  :levels => [
    {
      :level => 0,
      :value => "5",
      :name => "5 calls/month"
    },
    {
      :level => 1,
      :value => "100",
      :name => "100 calls/month"
    }
  ]
})

feature = result.feature
```

## Sample Response

```json
{
  "feature": {
    "description": "Integration of Chargebee with Quickbooks",
    "id": "fea-0e400372-75e0-432a-ae30-82f796a5b7e6",
    "levels": {},
    "name": "Quickbooks Integration_123",
    "object": "feature",
    "status": "draft",
    "type": "switch"
  }
}
```

## URL Format

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

## Input Parameters

- `id` (optional, string, max chars=50)
  A unique and immutable identifier for the feature. You can set it yourself, in which case it is recommended that a human-readable format (or slug) be used. For example, `number-of-users-ccjht01`. When not provided, a random value is automatically set.

- `name` (required, string, max chars=50)
  A case-sensitive unique name for the feature. For example: `user license` , `data storage` , `Salesforce Integration` , `devices` , `UHD Streaming` , and so on.
  
  **Note:** This name is not displayed on any customer-facing documents or pages such as [invoice PDFs](/docs/api/invoices/retrieve-invoice-as-pdf) or [hosted pages](/docs/api/hosted_pages). However, in the future, it is likely to be introduced on the [Self-Serve Portal](/docs/api/portal_sessions) .

- `description` (optional, string, max chars=500)
  A brief description of the feature. For example: `Access to 10TB cloud storage` .

- `type` (optional, enumerated string)
  The type of feature.
  Possible enum values:
    - `switch`
      A switch or toggle is a feature that an item or subscription can be either fully entitled to or not entitled to at all.
    - `custom`
      The entitlement levels available for this feature are defined as a set of custom values. For example, a feature `Email Support` can have entitlement levels as `24×7` and `24×5` .
    - `quantity`
      The feature is quantity-based and entitlement levels available for it are a set of predefined number of quantity units. For example, a feature with `name` such as `number of users` can have entitlement levels of say, `5` , `20` , `50` , and `100`. `levels[is_unlimited]` is used for specifying the "unlimited" entitlement level.
    - `range`
      The feature is quantity-based and the entitlement levels available for it are the set of whole numbers within a range. The range is defined by a minimum and a maximum value. For example, a feature such as `number of users` can have entitlement levels starting at `5` users and go up to `50000`. `levels[is_unlimited]` is used for specifying the "unlimited" entitlement level.

- `status` (optional, enumerated string)
  The current status of the feature.
  Possible enum values:
    - `active`
      A `draft` or an `archived` feature can be changed to `active`. Any [entitlements](/docs/api/entitlements) or [subscription entitlements](/docs/api/subscription_entitlements) defined for the feature take effect immediately.
    - `draft`
      The feature is in an unpublished state. [Entitlements](/docs/api/entitlements) and [subscription entitlements](/docs/api/subscription_entitlements) can be created for a draft feature but they are not effective until the feature is active. A feature `status` cannot be changed back to `draft` once it is in `active` or `archived` `status` .

- `unit` (optional, string, max chars=50)
  For features of `type` `quantity` or `range` , this specifies the unit of measure. The value is expected in the singular form and when used by the system, it is pluralized automatically as needed. For example, for a feature such as `user licenses` , the `unit` can be `license` .

- `levels` (optional, array)
  Parameters for levels
  - `name` (optional, string, max chars=50)
    A case-sensitive display name for the entitlement level. Provide a name that helps you clearly identify the entitlement level. For example: a feature such as `Email Support` can have entitlement levels named as `All weekdays` , `All days` , `40 hours per week` and so on.
    
    When not provided for `feature.type` `quantity` or `range` , this name is auto-generated as the space-separated concatenation of `levels[].value` and the pluralized version of `unit`. For example, if `levels[].value` is `20` and `unit` is `user` , then `levels[].name` becomes `20 users` .
  - `value` (optional, string, max chars=50)
    The value denoting the entitlement level granted.
    
    -   **When `type` is `quantity`:** this attribute denotes the quantity of units of the feature for this entitlement level. For example, a feature such as `number of users` can have `levels[].value` as `5`, `20`, `50`, and `100`. `levels[].is_unlimited` is used to set the entitlement level to "unlimited".
    -   **When `type` is `range`:** there can be be only two elements in the `levels[]` array; one corresponding to the minimum value (`levels[0]`) and the other to the maximum value (`levels[1]`) of the range of possible entitlement levels. For example, a feature such as `number of users` may have `levels[0].value` = `5` and `levels[1].value` = `50000`. When the upper limit is "unlimited", then `levels[1].value` is not set and `levels[1].is_unlimited` is `true`.
    -   **When `type` is `custom`:** this attribute denotes the value of this custom entitlement level. For example, a feature `Email Support` can have `levels[].value` as one of say, `24×7` and `24×5`.
  - `is_unlimited` (optional, boolean)
    When `type` is `quantity` or `range`, this attribute indicates whether the entitlement level corresponds to unlimited units of the feature. Possible values are:
    
    -   `true`: The entitlement level corresponds to unlimited units of the feature. `levels[].value` is ignored for this level. This can only be set for the level that has the highest value for `levels[].level.`
    -   `false`: The entitlement level does not correspond to unlimited units of the feature.
    
    Either this or levels\[value\] should be passed.
  - `level` (optional, integer)
    Represents the order of the entitlement levels from lowest to highest.
    
    -   **When `type` is `quantity` or `custom`:** Provide the `level` for the lowest entitlement level as `0`, the next higher level as `1`, followed by `2`, and so on.
    -   **When `type` is `range`:** Provide `0` for the minimum value and `1` for the maximum value in the range.
    
    When not defined, it is assumed as the index of the `levels[]` array.

## Returns

- `feature` (Feature object)
  Resource object representing feature
