# Update a differential price

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


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

Update a differential price using a `differential_price_id` and `item_price_id` .

## Sample Request

### Default

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/differential_prices/304e773d-2538-4dd8-89d8-d9b478724e21 \
     -u {site_api_key}:\
     -d item_price_id="additional-user-addon-USD" \
     -d price=350
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = DifferentialPrice.Update("304e773d-2538-4dd8-89d8-d9b478724e21")
		.ItemPriceId("additional-user-addon-USD")
		.Price(350)
		.Request();

DifferentialPrice differentialPrice = result.DifferentialPrice;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    differentialpriceAction "github.com/chargebee/chargebee-go/v3/actions/differentialprice"
    "github.com/chargebee/chargebee-go/v3/models/differentialprice"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := differentialpriceAction.Update("304e773d-2538-4dd8-89d8-d9b478724e21", &differentialprice.UpdateRequestParams{
        ItemPriceId : "additional-user-addon-USD",
        Price : chargebee.Int64(350),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        DifferentialPrice := res.DifferentialPrice
    }
}
```

#### 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.DifferentialPriceUpdateRequest{
    ItemPriceId : "additional-user-addon-USD",
    Price : chargebee.Int64(350),
}
  res, err := client.DifferentialPrice.Update("304e773d-2538-4dd8-89d8-d9b478724e21", req)
      if err != nil {
        fmt.Println(err)
    } else {
        DifferentialPrice := res.DifferentialPrice
    }
}
```

#### 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 = DifferentialPrice.update("304e773d-2538-4dd8-89d8-d9b478724e21")
            .itemPriceId("additional-user-addon-USD")
            .price(350L)
            .request();

        DifferentialPrice differentialPrice = result.differentialPrice();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.differentialPrice.DifferentialPrice;
import com.chargebee.v4.models.differentialPrice.params.DifferentialPriceUpdateParams;
import com.chargebee.v4.models.differentialPrice.responses.DifferentialPriceUpdateResponse;

public class DifferentialPriceUpdate {

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

        DifferentialPriceUpdateParams params = DifferentialPriceUpdateParams.builder()
            .itemPriceId("additional-user-addon-USD")
            .price(350L)
            .build();

        DifferentialPriceUpdateResponse response = client
            .differentialPrices()
            .update("304e773d-2538-4dd8-89d8-d9b478724e21", params);

        DifferentialPrice differentialPrice = response.getDifferentialPrice();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.differentialPrice.update("304e773d-2538-4dd8-89d8-d9b478724e21", {
        item_price_id: "additional-user-addon-USD",
        price: 350
    });

    console.log(result);
    const differentialPrice = result.differential_price;
} 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->differentialPrice()->update("304e773d-2538-4dd8-89d8-d9b478724e21", [
    "item_price_id" => "additional-user-addon-USD",
    "price" => 350
]);
$differentialPrice = $result->differential_price;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.DifferentialPrice.update("304e773d-2538-4dd8-89d8-d9b478724e21",
    cb_client.DifferentialPrice.UpdateParams(
        item_price_id="additional-user-addon-USD",
        price=350
    )
)
differential_price = response.differential_price
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::DifferentialPrice.update("304e773d-2538-4dd8-89d8-d9b478724e21",{
  :item_price_id => "additional-user-addon-USD",
  :price => 350
})

differential_price = result.differential_price
```

### update a differential price for charge item

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/differential_prices/38afc406-cae1-47ca-94aa-40098c4cc02b \
     -u {site_api_key}:\
     -d item_price_id="sample-charge-USD" \
     -d price=350 \
     -d "parent_periods[period][0]"='[2]' \
     -d "parent_periods[period_unit][0]"="MONTH"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;
using Newtonsoft.Json.Linq;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = DifferentialPrice.Update("38afc406-cae1-47ca-94aa-40098c4cc02b")
		.ItemPriceId("sample-charge-USD")
		.Price(350)
		.ParentPeriodPeriod(0, new JArray { 2 })
		.ParentPeriodPeriodUnit(0, DifferentialPrice.DifferentialPriceParentPeriod.PeriodUnitEnum.Month)
		.Request();

DifferentialPrice differentialPrice = result.DifferentialPrice;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    differentialpriceAction "github.com/chargebee/chargebee-go/v3/actions/differentialprice"
    "github.com/chargebee/chargebee-go/v3/models/differentialprice"
    differentialPriceEnum "github.com/chargebee/chargebee-go/v3/models/differentialprice/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := differentialpriceAction.Update("38afc406-cae1-47ca-94aa-40098c4cc02b", &differentialprice.UpdateRequestParams{
        ParentPeriods : []*differentialprice.UpdateParentPeriodParams{
            {
                Period : []interface{}{2, "month"},
                PeriodUnit : differentialPriceEnum.ParentPeriodPeriodUnitMonth,
            },
        },
        ItemPriceId : "sample-charge-USD",
        Price : chargebee.Int64(350),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        DifferentialPrice := res.DifferentialPrice
    }
}
```

#### 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.DifferentialPriceUpdateRequest{
    ParentPeriods : []*chargebee.DifferentialPriceUpdateParentPeriod{
        {
            Period : []interface{}{2, "month"},
            PeriodUnit : chargebee.DifferentialPriceParentPeriodPeriodUnitMonth,
        },
    },
    ItemPriceId : "sample-charge-USD",
    Price : chargebee.Int64(350),
}
  res, err := client.DifferentialPrice.Update("38afc406-cae1-47ca-94aa-40098c4cc02b", req)
      if err != nil {
        fmt.Println(err)
    } else {
        DifferentialPrice := res.DifferentialPrice
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;
import java.util.List;
import com.chargebee.org.json.JSONArray;
import com.chargebee.org.json.JSONObject;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = DifferentialPrice.update("38afc406-cae1-47ca-94aa-40098c4cc02b")
            .itemPriceId("sample-charge-USD")
            .price(350L)
            .parentPeriodPeriod(0, new JSONArray("[2]"))
            .parentPeriodPeriodUnit(0, DifferentialPrice.ParentPeriod.PeriodUnit.MONTH)
            .request();

        DifferentialPrice differentialPrice = result.differentialPrice();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.differentialPrice.DifferentialPrice;
import com.chargebee.v4.models.differentialPrice.params.DifferentialPriceUpdateParams;
import com.chargebee.v4.models.differentialPrice.responses.DifferentialPriceUpdateResponse;
import java.util.List;

public class DifferentialPriceUpdate {

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

        DifferentialPriceUpdateParams.ParentPeriodsParams parentPeriod0 =
            DifferentialPriceUpdateParams.ParentPeriodsParams.builder()
                .period(List.of("[2]"))
                .periodUnit(DifferentialPriceUpdateParams.ParentPeriodsParams.PeriodUnit.MONTH)
                .build();

        List<DifferentialPriceUpdateParams.ParentPeriodsParams> parentPeriodsList =
            List.of(parentPeriod0);

        DifferentialPriceUpdateParams params = DifferentialPriceUpdateParams.builder()
            .itemPriceId("sample-charge-USD")
            .price(350L)
            .parentPeriods(parentPeriodsList)
            .build();

        DifferentialPriceUpdateResponse response = client
            .differentialPrices()
            .update("38afc406-cae1-47ca-94aa-40098c4cc02b", params);

        DifferentialPrice differentialPrice = response.getDifferentialPrice();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.differentialPrice.update("38afc406-cae1-47ca-94aa-40098c4cc02b", {
        parent_periods: [
            {
                period: "[2]",
                period_unit: "month"
            }
        ],
        item_price_id: "sample-charge-USD",
        price: 350
    });

    console.log(result);
    const differentialPrice = result.differential_price;
} 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->differentialPrice()->update("38afc406-cae1-47ca-94aa-40098c4cc02b", [
    "parent_periods" => [
        [
            "period" => "[2]",
            "period_unit" => "month"
        ]
    ],
    "item_price_id" => "sample-charge-USD",
    "price" => 350
]);
$differentialPrice = $result->differential_price;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.DifferentialPrice.update("38afc406-cae1-47ca-94aa-40098c4cc02b",
    cb_client.DifferentialPrice.UpdateParams(
        parent_periods=[
            cb_client.DifferentialPrice.UpdateParentPeriodParams(
              period="[2]",
              period_unit=chargebee.DifferentialPrice.ParentPeriodPeriodUnit.MONTH
            )
        ],
        item_price_id="sample-charge-USD",
        price=350
    )
)
differential_price = response.differential_price
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::DifferentialPrice.update("38afc406-cae1-47ca-94aa-40098c4cc02b",{
  :item_price_id => "sample-charge-USD",
  :price => 350,
  :parent_periods => [
    {
      :period => "[2]",
      :period_unit => "MONTH"
    }
  ]
})

differential_price = result.differential_price
```

## Sample Response

```json
{
  "differential_price": {
    "created_at": 1594110588,
    "currency_code": "USD",
    "id": "304e773d-2538-4dd8-89d8-d9b478724e21",
    "item_price_id": "additional-user-addon-USD",
    "object": "differential_price",
    "parent_item_id": "scale",
    "price": 350,
    "resource_version": 1594110588618,
    "status": "active",
    "updated_at": 1594110588
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/differential_prices/{differential-price-id}

## Input Parameters

- `item_price_id` (required, string, max chars=100)
  The id of the item price (`addon` or `charge` ) whose price should change according to the plan-item it is applied to.

- `price` (optional, in cents, min=0)
  The differential price. If the pricing model of the `item_price_id` is `tiered` , `volume` , or `stairstep` , pass `tiers` instead of this.

- `price_in_decimal` (optional, string, max chars=39)
  The price of the item when the pricing\_model is `flat_fee`. When the pricing model is `per_unit` , it is the price per unit quantity of the item. Not applicable for the other pricing models. The value is in decimal and in major units of the currency. Also, this is only applicable when [multi-decimal pricing](/docs/api/currencies) is enabled.

- `parent_periods` (optional, array)
  Parameters for parent\_periods
  - `period_unit` (required, enumerated string)
    The unit of time for `period` .
    Possible enum values:
      - `day`
        A period of 24 hours.
      - `week`
        A period of 7 days.
      - `month`
        A period of 1 calendar month.
      - `year`
        A period of 1 calendar year.
  - `period` (optional, array)
    The billing period of the plan in `period_unit` s. For example, a 6 month plan has `period` as 6 and `period_unit` as `month`.
    
    **Note** For a [charge-item price](/docs/api/item_prices),
    
    -   When `parent_periods[period_unit]` and `parent_periods[period]` values are **passed**, then the [price](/docs/api/differential_prices/create-a-differential-price#price) is applied to a **specific** billing frequency of the plan-item.
    -   When `parent_periods[period_unit]` and `parent_periods[period]` values are **not passed**, then the [price](/docs/api/differential_prices/create-a-differential-price#price) is applied to **all** billing frequencies of the plan-item.
    -   When parent\_periods\[period\_unit\] is **passed** (eg. month) and the `parent_periods[period]` value is **not passed**, then the price is applied to all `parent_periods[period_unit]` (eg. monthly) frequencies of the plan-item. Updating or deleting the [price](/docs/api/differential_prices/create-a-differential-price#price) after creation will impact all of its related plan-item frequencies.

- `tiers` (optional, array)
  Parameters for tiers
  - `starting_unit` (optional, integer)
    The lower limit of a range of units for the tier
  - `ending_unit` (optional, integer)
    The upper limit of a range of units for the tier
  - `price` (optional, in cents)
    The per-unit price for the tier when the `pricing_model` is `tiered` or `volume` ; the total cost for the item price when the `pricing_model` is `stairstep`. The value is in the [minor unit of the currency](/docs/api/currencies) .
  - `starting_unit_in_decimal` (optional, string, max chars=33)
    The decimal representation of the lowest value of quantity in this tier. This is zero for the lowest tier. For all other tiers, it is the same as `ending_unit_in_decimal` of the next lower tier. Returned only when the `pricing_model` is `tiered` , `volume` or `stairstep` and [multi-decimal pricing](/docs/api/currencies) is enabled.
  - `ending_unit_in_decimal` (optional, string, max chars=33)
    The decimal representation of the highest value of quantity in this tier. This attribute is not applicable for the highest tier. For all other tiers, it must be equal to the `starting_unit_in_decimal` of the next higher tier. Returned only when the `pricing_model` is `tiered` , `volume` or `stairstep` and [multi-decimal pricing](/docs/api/currencies) is enabled.
  - `price_in_decimal` (optional, string, max chars=39)
    The decimal representation of the per-unit price for the tier when the `pricing_model` is `tiered` or `volume`. When the `pricing_model` is `stairstep` , it is the decimal representation of the total price for the addon. The value is in major units of the currency. Returned when the plan is quantity-based and [multi-decimal pricing](/docs/api/currencies) is enabled.
  - `pricing_type` (optional, enumerated string)
    Pricing type for the tier.
    Possible enum values:
      - `per_unit`
        Indicates that the tier pricing is based on individual units. Customers are charged a fixed price per unit. For example, if the price per unit is $2 and the customer consumes 150 units, they will be charged $300 (150 × $2).
      - `flat_fee`
        Indicates that the tier pricing is a flat fee, applied to the entire tier regardless of the number of units consumed. For the **stairstep** pricing model, `pricing_type` will be set to `flat_fee` by default. For example, if the flat fee for a tier is $100, the customer pays $100 whether they consume 1 unit or the maximum number of units within that tier.
      - `package`
        Indicates that the tier pricing is based on a package of units. Customers are charged for each block or package of units. For example, if the package size is 100 units and the cost per block is $20 consuming 400 units will result in a charge of $80 (4 × $20).
  - `package_size` (optional, integer)
    Package size for the tier when pricing type is `package`. Specify the number of units that make up one package. For example, if 1000 API hits are grouped into a single package, set the package size to 1000.

## Returns

- `differential_price` (Differential price object)
  Resource object representing differential\_price
