# PUT /plan/update/{{plan_id}} — Update Plan

> Product: **Pabbly Subscription Billing** (v1)
> Base URL: `https://payments.pabbly.com/api/v1`
> Auth: Basic via `Authorization` header
> Canonical: `/subscription-billing/plans/update-plan`

A PUT request API can be used to update or edit the details of an existing plan. You will need to add the plan Id in Request the URL In response, you will get the new details of the plan on the same plan Id. Attribute:

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| plan_id | string | Yes |  |

**Body parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| redirect_url | string | No | The customer will be redirected to this link after successful payment. |
| currency_code | string | No | In what currency do you want to sell |
| plan_name | string | Yes | Update the plan name. |
| plan_code | string | Yes | Plan Code can be same as plan name. This will be displayed at the end of the checkout page link. |
| product_id | string | Yes | Unique product Id in which you are creating this plan. |
| billing_cycle | string | No | specific |
| setup_fee | string | No | Fees deducted at the time of first payment only. |
| billing_cycle_num | string | No | Update the billing timeline. |
| price | string | No | Update the price of the plan. Required only if plan type is flat_fee |
| billing_period | string | No | Update the billing period. |
| billing_period_num | string | No | Number of billing number of weeks, months, or year. |
| plan_active | string | No | true |
| plan_description | string | No | Add the plan description here that you want to display on the checkout page. |
| plan_type | string | No | flat_fee |
| trial_amount | string | No | trial_amount |
| trial_period | string | No | Add the number of trials |
| trial_type | string | No | Required if trial period is set day |
| variable_increase_price | string | No | Add the amount to increase price by each time it goes up. |
| variable_max_price_amount | string | No | Add the maximum price your product will sell for. |
| variable_period_num | string | No | Add the amount, how often to increase the price. |
| variable_type | string | No | hour |
| variable_start_time | string | No | Add the date and time that the timesale will start. |
| payment_gateway | string | No | selected |
| gateways_array | string | No | ["615c365d2688ae545d670709",...] Use this when you use payment gateway as "Selected" |
| failed_payment_gateway | string | No | selected |
| failed_payment_gateway_array | string | No | ["615c365d2688ae545d670709",...] Use this when you use payment gateway as "Selected" |
| payment_term | string | No | net0 |
| specific_keep_live | string | No | live |
| meta_data | string | No | { "value1": "{value_details}", "value2": "{value_details}", "value3": "{value_details}" } This will help you to pass the hidden custom field data on the checkout page. |
| min_quantity | string | No | Minimum quantity to make the purchase. |
| max_quantity | string | No | The maximum quantity allowed in one purchase. The customer can't exceed the maximum quantity limit. |

**Example request body:**

```json
{
    "plan_name": "Per Unit Plan",
    "plan_code": "perunitplan", //Unique plan code
    "product_id": "5ea2d55617f6bf3123f0f95f",
    "price": 10, //Required only if plan type is flat_fee | per_unit | donation | variable
    "billing_cycle": "lifetime", //Optional specific|lifetime|onetime
    "billing_cycle_num": "2", //Required if billing cycle is specific
    "billing_period": "m", //Optional m|w|y
    "billing_period_num": "1", //Optional
    "setup_fee": 2, //Optional
    "setup_fee_type": "per_unit", //Required if setupfee amount is set flat_fee | per_unit
    "plan_type": "per_unit", //Optional flat_fee | per_unit | volume | tiered | stairstep | donation | variable
    "tiers": [
        {
            "starting_unit": "1",
            "ending_unit": "10",
            "price": "100"
        },
        {
            "starting_unit": "11",
            "price": "500"
        }
    ], //Required if plan type is tiered/volume/stairtstep
    "trial_amount": 10,
    "trial_period": 1,
    "trial_type": "day", // Required if trial period is set day|month
    "variable_increase_price": 5, //Required if plan type is variable
    "variable_max_price_amount": 100, //Required if plan type is variable
    "variable_period_num": 1, //Required if plan type is variable
    "variable_type": "hour", //Required if plan type is variable sale | hour
    "variable_start_time": "2021-10-06 21:15", //Required if variable_type is hour
    "payment_gateway": "selected",
    "gateways_array": [
        "615c365d2688ae545d670709",
        "615c365d2688ae545d670705"
    ],
    "failed_payment_gateway": "selected",
    "failed_payment_gateway_array": [
        "615c365d2688ae545d670709"
    ],
    "plan_active": "true",
    "plan_description": "",
    "redirect_url": "https://www.pabbly.com/",
    "payment_term": "net15", //Optional net0|net15|net30|net45|net60|month|nextmonth
    "specific_keep_live": "live", //Optional live|expire
    "meta_data": {
        "value1": "{value_details}",
        "value2": "{value_details}",
        "value3": "{value_details}"
    }
}
```

**Response (200)** — Update Plan:

```json
{
    "status": "success",
    "message": "Plan Updated",
    "data": {
        "plan_type": "per_unit",
        "plan_active": "true",
        "redirect_url": "https://www.pabbly.com/",
        "currency_code": "INR",
        "currency_symbol": "₹",
        "payment_gateway": "selected",
        "gateways_array": [
            "615c365d2688ae545d670709"
        ],
        "tiers": [
            {
                "starting_unit": "1",
                "ending_unit": "10",
                "price": "100"
            },
            {
                "starting_unit": "11",
                "price": "500"
            }
        ],
        "setup_fee_type": "per_unit",
        "trial_type": "day",
        "trial_amount": 10,
        "createdAt": "2021-10-06T10:46:40.960Z",
        "updatedAt": "2021-10-06T10:46:40.960Z",
        "id": "615d7e9086d80a30fcf9b6fb",
        "product_id": "615c5494aa7246671999768d",
        "plan_name": "Per Unit Plan",
        "plan_code": "perunitplan",
        "price": 10,
        "billing_period": "m",
        "billing_period_num": "1",
        "billing_cycle": "lifetime",
        "billing_cycle_num": "2",
        "trial_period": 2,
        "setup_fee": 2,
        "plan_description": "",
        "checkout_page": "http://localhost:1337/subscribe/615d7e9086d80a30fcf9b6fb/perunitplan"
    }}
```

**Code examples:**

_cURL_

```curl
curl -X PUT https://payments.pabbly.com/api/v1/plan/update/{{plan_id}} \
  -u {{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}} \
  -H "Content-Type: application/json" \
  -d '{
    "plan_name": "{{plan_name}}",
    "plan_code": "{{plan_code}}",
    "product_id": "{{product_id}}"
  }'
```

_Ruby_

```ruby
require 'net/http'
require 'json'

uri = URI('https://payments.pabbly.com/api/v1/plan/update/{{plan_id}}')
request = Net::HTTP::Put.new(uri)
request.basic_auth '{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'
request['Content-Type'] = 'application/json'
request.body = "{\"plan_name\":\"{{plan_name}}\",\"plan_code\":\"{{plan_code}}\",\"product_id\":\"{{product_id}}\"}"

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
  http.request(request)
end

data = JSON.parse(response.body)
```

_Python_

```python
import requests
from requests.auth import HTTPBasicAuth

response = requests.put(
    'https://payments.pabbly.com/api/v1/plan/update/{{plan_id}}',
    auth=HTTPBasicAuth('{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'),
    json={
    'plan_name': '{{plan_name}}',
    'plan_code': '{{plan_code}}',
    'product_id': '{{product_id}}'
},
)

data = response.json()
```

_PHP_

```php
<?php
$ch = curl_init('https://payments.pabbly.com/api/v1/plan/update/{{plan_id}}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_USERPWD, '{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"plan_name":"{{plan_name}}","plan_code":"{{plan_code}}","product_id":"{{product_id}}"}');

$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
```

_Java_

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Base64;

String credentials = Base64.getEncoder().encodeToString("{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}".getBytes());

HttpClient client = HttpClient.newHttpClient();
HttpRequest.Builder builder = HttpRequest.newBuilder()
    .uri(URI.create("https://payments.pabbly.com/api/v1/plan/update/{{plan_id}}"))
    .header("Authorization", "Basic " + credentials)
    .header("Content-Type", "application/json")
    .PUT(HttpRequest.BodyPublishers.ofString("{\"plan_name\":\"{{plan_name}}\",\"plan_code\":\"{{plan_code}}\",\"product_id\":\"{{product_id}}\"}"));

HttpRequest request = builder.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

_Node.js_

```node
const credentials = Buffer.from('{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}').toString('base64');

const response = await fetch('https://payments.pabbly.com/api/v1/plan/update/{{plan_id}}', {
  method: 'PUT',
  headers: {
    'Authorization': `Basic ${credentials}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "plan_name": "{{plan_name}}",
    "plan_code": "{{plan_code}}",
    "product_id": "{{product_id}}"
  }),
});

const data = await response.json();
```

_Go_

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    payload := strings.NewReader("{\"plan_name\":\"{{plan_name}}\",\"plan_code\":\"{{plan_code}}\",\"product_id\":\"{{product_id}}\"}")
    req, _ := http.NewRequest("PUT", "https://payments.pabbly.com/api/v1/plan/update/{{plan_id}}", payload)
    req.Header.Set("Content-Type", "application/json")
    req.SetBasicAuth("{{YOUR_API_KEY}}", "{{YOUR_SECRET_KEY}}")

    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)
    fmt.Println(string(body))
}
```

_.NET_

```dotnet
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}"));

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Put, "https://payments.pabbly.com/api/v1/plan/update/{{plan_id}}");
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {credentials}");
request.Content = new StringContent("{\"plan_name\":\"{{plan_name}}\",\"plan_code\":\"{{plan_code}}\",\"product_id\":\"{{product_id}}\"}");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

var response = await client.SendAsync(request);
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);
```

---

**Other endpoints in Plans:**

- [POST /plan/create — Create Plan](/subscription-billing/plans/create-plan)
- [GET /plans — List All Plans](/subscription-billing/plans/list-all-plans)
- [GET /plan/{{plan_id}} — Get single Plan by Plan ID](/subscription-billing/plans/get-single-plan-by-plan-id)
- [GET /plans/{{product_id}} — List All Plans By Product ID](/subscription-billing/plans/list-all-plans-by-product-id)
- [DELETE /plans/{{plan_id}} — Delete Plan](/subscription-billing/plans/delete-plan)

