# Update a price ramp

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


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

Updates a price ramp. You can either change its `status` (to activate or archive it) or replace its `ramp_intervals`. These two changes are mutually exclusive within a single request.

When `ramp_intervals` is provided, the existing intervals are replaced in full with the new ordered set. Each interval in that set must include `starting_billing_cycle`.

Chargebee merges adjacent `ramp_intervals` that have the same pricing before saving. Intervals are merged when they have the same `price`, or when consecutive intervals have `apply_catalog_price` set to `true`. Intervals with different prices, a mix of catalog and fixed pricing, or gaps in billing cycles aren't merged.

The ramp must contain at least two intervals after merging. If the submitted intervals merge into a single interval, the request is rejected.

Changes apply to **new subscriptions only**. Existing subscribers keep the ramp schedule captured when their subscription was created.

### Prerequisites & Constraints

-   [Price Ramps](https://www.chargebee.com/docs/billing/2.0/product-catalog/price-ramps) must be enabled for the site. Contact [Chargebee Support](https://www.chargebee.com/docs/billing/2.0/kb/getting-started/how-to-contact-chargebees-support-team?utm_source=docs_api&utm_medium=content&utm_campaign=support) to enable them. Until they are enabled, this operation returns `API_RESTRICTED`.
-   The price ramp's `status` must not be `archived` when replacing `ramp_intervals`.
-   The linked item price must not be archived.

## Sample Request

#### Chargebee CLI

```bash
chargebee price-ramp update 3b930dda-1444-44f1-b79b-8de01fd9c139 \
    -d 'ramp_intervals[starting_billing_cycle][0]=1' \
    -d 'ramp_intervals[ending_billing_cycle][0]=2' \
    -d 'ramp_intervals[price][0]=99' \
    -d 'ramp_intervals[starting_billing_cycle][1]=3' \
    -d 'ramp_intervals[apply_catalog_price][1]=true'
```

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/price_ramps/3b930dda-1444-44f1-b79b-8de01fd9c139 \
     -u {site_api_key}:\
     -d "ramp_intervals[starting_billing_cycle][0]"=1 \
     -d "ramp_intervals[ending_billing_cycle][0]"=2 \
     -d "ramp_intervals[price][0]"=99 \
     -d "ramp_intervals[starting_billing_cycle][1]"=3 \
     -d "ramp_intervals[apply_catalog_price][1]"="true"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PriceRamp.Update("3b930dda-1444-44f1-b79b-8de01fd9c139")
		.RampIntervalStartingBillingCycle(0, 1)
		.RampIntervalEndingBillingCycle(0, 2)
		.RampIntervalPrice(0, 99)
		.RampIntervalStartingBillingCycle(1, 3)
		.RampIntervalApplyCatalogPrice(1, true)
		.Request();

PriceRamp priceRamp = result.PriceRamp;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    pricerampAction "github.com/chargebee/chargebee-go/v3/actions/priceramp"
    "github.com/chargebee/chargebee-go/v3/models/priceramp"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := pricerampAction.Update("3b930dda-1444-44f1-b79b-8de01fd9c139", &priceramp.UpdateRequestParams{
        RampIntervals : []*priceramp.UpdateRampIntervalParams{
            {
                StartingBillingCycle : chargebee.Int32(1),
                EndingBillingCycle : chargebee.Int32(2),
                Price : chargebee.Int64(99),
            },
            {
                StartingBillingCycle : chargebee.Int32(3),
                ApplyCatalogPrice : chargebee.Bool(true),
            },
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        PriceRamp := res.PriceRamp
    }
}
```

#### 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.PriceRampUpdateRequest{
    RampIntervals : []*chargebee.PriceRampUpdateRampInterval{
        {
            StartingBillingCycle : chargebee.Int32(1),
            EndingBillingCycle : chargebee.Int32(2),
            Price : chargebee.Int64(99),
        },
        {
            StartingBillingCycle : chargebee.Int32(3),
            ApplyCatalogPrice : chargebee.Bool(true),
        },
    },
}
  res, err := client.PriceRamp.Update("3b930dda-1444-44f1-b79b-8de01fd9c139", req)
      if err != nil {
        fmt.Println(err)
    } else {
        PriceRamp := res.PriceRamp
    }
}
```

#### 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 = PriceRamp.update("3b930dda-1444-44f1-b79b-8de01fd9c139")
            .rampIntervalStartingBillingCycle(0, 1)
            .rampIntervalEndingBillingCycle(0, 2)
            .rampIntervalPrice(0, 99L)
            .rampIntervalStartingBillingCycle(1, 3)
            .rampIntervalApplyCatalogPrice(1, true)
            .request();

        PriceRamp priceRamp = result.priceRamp();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.priceRamp.PriceRamp;
import com.chargebee.v4.models.priceRamp.params.PriceRampUpdateParams;
import com.chargebee.v4.models.priceRamp.responses.PriceRampUpdateResponse;
import java.util.List;

public class PriceRampUpdate {

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

        PriceRampUpdateParams.RampIntervalsParams rampInterval0 =
            PriceRampUpdateParams.RampIntervalsParams.builder()
                .startingBillingCycle(1)
                .endingBillingCycle(2)
                .price(99L)
                .build();

        PriceRampUpdateParams.RampIntervalsParams rampInterval1 =
            PriceRampUpdateParams.RampIntervalsParams.builder()
                .startingBillingCycle(3)
                .applyCatalogPrice(true)
                .build();

        List<PriceRampUpdateParams.RampIntervalsParams> rampIntervalsList =
            List.of(rampInterval0, rampInterval1);

        PriceRampUpdateParams params = PriceRampUpdateParams.builder()
            .rampIntervals(rampIntervalsList)
            .build();

        PriceRampUpdateResponse response = client
            .priceRamps()
            .update("3b930dda-1444-44f1-b79b-8de01fd9c139", params);

        PriceRamp priceRamp = response.getPriceRamp();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.priceRamp.update("3b930dda-1444-44f1-b79b-8de01fd9c139", {
        ramp_intervals: [
            {
                starting_billing_cycle: 1,
                ending_billing_cycle: 2,
                price: 99
            },
            {
                starting_billing_cycle: 3,
                apply_catalog_price: true
            }
        ]
    });

    console.log(result);
    const priceRamp = result.price_ramp;
} 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->priceRamp()->update("3b930dda-1444-44f1-b79b-8de01fd9c139", [
    "ramp_intervals" => [
        [
            "starting_billing_cycle" => 1,
            "ending_billing_cycle" => 2,
            "price" => 99
        ],
        [
            "starting_billing_cycle" => 3,
            "apply_catalog_price" => true
        ]
    ]
]);
$priceRamp = $result->price_ramp;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.PriceRamp.update("3b930dda-1444-44f1-b79b-8de01fd9c139",
    cb_client.PriceRamp.UpdateParams(
        ramp_intervals=[
            cb_client.PriceRamp.UpdateRampIntervalParams(
              starting_billing_cycle=1,
              ending_billing_cycle=2,
              price=99
            ),
            cb_client.PriceRamp.UpdateRampIntervalParams(
              starting_billing_cycle=3,
              apply_catalog_price=True
            )
        ]
    )
)
price_ramp = response.price_ramp
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::PriceRamp.update("3b930dda-1444-44f1-b79b-8de01fd9c139",{
  :ramp_intervals => [
    {
      :starting_billing_cycle => 1,
      :ending_billing_cycle => 2,
      :price => 99
    },
    {
      :starting_billing_cycle => 3,
      :apply_catalog_price => "true"
    }
  ]
})

price_ramp = result.price_ramp
```

## Sample Response

```json
{
  "price_ramp": {
    "id": "3b930dda-1444-44f1-b79b-8de01fd9c139",
    "item_price_id": "basic-USD-Monthly",
    "status": "active",
    "object": "price_ramp",
    "ramp_intervals": [
      {
        "starting_billing_cycle": 1,
        "ending_billing_cycle": 2,
        "price": 99
      },
      {
        "starting_billing_cycle": 3,
        "apply_catalog_price": true,
        "price": 999
      }
    ],
    "resource_version": 1594114187730,
    "created_at": 1594110587,
    "updated_at": 1594114187
  }
}
```

## URL Format

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

## Input Parameters

- `status` (optional, enumerated string, default=active)
  The status to set for the price ramp. Use this to activate a ramp or archive it so that it no longer applies to the linked item price. `status` and `ramp_intervals` are mutually exclusive in a single request.
  Possible enum values:
    - `active`
      Activates the price ramp so that its ramp intervals apply to the linked item price.
    - `archived`
      Archives the price ramp so that it no longer applies to the linked item price.

- `ramp_intervals` (optional, array)
  The new ordered list of intervals for the price ramp. When provided, this **replaces** the existing set of ramp intervals in full. Each interval must include `starting_billing_cycle`. Intervals must be contiguous and ordered by `starting_billing_cycle`, with the first interval starting at billing cycle `1`. Adjacent intervals with the same pricing are merged before the ramp is saved. At least 2 intervals must remain after the merge. Up to 3 intervals. `ramp_intervals` and `status` are mutually exclusive in a single request.
  - `starting_billing_cycle` (required, integer)
    The billing cycle at which this interval begins. The first interval must start at billing cycle `1`, and each subsequent interval must begin at the billing cycle immediately after the previous interval's `ending_billing_cycle`. Required for each interval when `ramp_intervals` is provided.
  - `ending_billing_cycle` (optional, integer)
    The billing cycle at which this interval ends. Omit this for the final interval so that its price applies to all remaining billing cycles.
  - `apply_catalog_price` (optional, boolean)
    Set to `true` to apply the item price's catalog price for this interval instead of an overridden ramp price. When `true`, do not pass `price` or `price_in_decimal` for the interval.
  - `price` (optional, in cents)
    The price that applies for this interval, in the [minor unit of the currency](/docs/api/currencies). Do not pass this when `apply_catalog_price` is `true`.
  - `price_in_decimal` (optional, string, max chars=39)
    The price that applies for this interval, in the major (decimal) unit of the currency. Applicable only when [multi-decimal pricing](/docs/api/currencies) is enabled. Do not pass this when `apply_catalog_price` is `true`.

## Returns

- `price_ramp` (Price ramp object)
