# POST /addon/{{product_id}} — Create Addon

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

This API can be used to add Add-ons in a plan. This request will be fired with POST request and you will add the plan ID in the API link. In form data you will need to add the billing cycle and details about the add-on and fire the API. In response you will get the details of the added add-on along with the add-on Id.

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| product_id | string | Yes | Id of the Product this add-on is associated with |

**Body parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| billing_period | string | Yes | Monthly Addon - "m" Yearly Addon - "y" Weekly Addon - "w" |
| billing_cycle | string | Yes | lifetime - for recurring add-on onetime - for one time add-on |
| status | string | Yes | true - for active |
| associate_plans | string | Yes | Possible values can be selected_plans / all_plans. |
| billing_period_num | integer | Yes | Billing frequency of the add-on |
| category_array | array | No | This add-on will be shown on all the added categories |
| code | string | Yes | Unqiue code of your add-on, Not shown on the checkout page |
| name | string | Yes | Name of your add-on |
| price | integer | Yes | Price of your add-on |
| plans_array | array | No | If associate plan is true then add the plan Id's here |
| description | string | No | For merchat purpose ony, not shwon on the checkout pages |

**Example request body:**

```json
{ 
  "billing_period": "m",
  "billing_cycle": "lifetime",
  "status": "true",
  "associate_plans": "all_plans",
  "billing_period_num": 1,
  "category_array": ["5e3aac233c92e44b424b6dfb"],
  "code": "extra-5gb-data",
  "name": "Extra 5GB Data",
  "price": 10,
  "plans_array": [""],  
  "description": "By adding this addon, you'll get extra 5GB data"
}
```

**Response (200)** — Create Addon:

```json
{
    "status": "success",
    "message": "Addon Created Successfully",
    "data": {
        "billing_period": "m",
        "category_array": [
            "5e3aac233c92e44b424b6dfb"
        ],
        "createdAt": "2020-03-04T08:31:40.457Z",
        "updatedAt": "2020-03-04T08:31:40.457Z",
        "id": "5e5f676c3b2518365c79247a",
        "product_id": "5e3a95143c92e44b424b6d47",
        "user_id": "5b961bc55dfff7797d9cd897",
        "name": "Extra 5GB Data",
        "code": "extra-5gb-data",
        "price": 10,
        "billing_cycle": "lifetime",
        "status": true,
        "associate_plans": "all",
        "plans_array": [
            ""
        ],
        "description": "By adding this addon, you'll get extra 5GB data"
    }
}
```

**Code examples:**

_cURL_

```curl
curl -X POST https://payments.pabbly.com/api/v1/addon/{{product_id}} \
  -u {{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}} \
  -H "Content-Type: application/json" \
  -d '{
    "billing_period": "m",
    "billing_cycle": "lifetime",
    "status": "true",
    "associate_plans": "all_plans",
    "billing_period_num": 1,
    "category_array": [
      "5e3aac233c92e44b424b6dfb"
    ],
    "code": "extra-5gb-data",
    "name": "Extra 5GB Data",
    "price": 10,
    "plans_array": [
      ""
    ],
    "description": "By adding this addon, you'll get extra 5GB data"
  }'
```

_Ruby_

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

uri = URI('https://payments.pabbly.com/api/v1/addon/{{product_id}}')
request = Net::HTTP::Post.new(uri)
request.basic_auth '{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'
request['Content-Type'] = 'application/json'
request.body = "{\"billing_period\":\"m\",\"billing_cycle\":\"lifetime\",\"status\":\"true\",\"associate_plans\":\"all_plans\",\"billing_period_num\":1,\"category_array\":[\"5e3aac233c92e44b424b6dfb\"],\"code\":\"extra-5gb-data\",\"name\":\"Extra 5GB Data\",\"price\":10,\"plans_array\":[\"\"],\"description\":\"By adding this addon, you'll get extra 5GB data\"}"

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.post(
    'https://payments.pabbly.com/api/v1/addon/{{product_id}}',
    auth=HTTPBasicAuth('{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'),
    json={
    'billing_period': 'm',
    'billing_cycle': 'lifetime',
    'status': 'true',
    'associate_plans': 'all_plans',
    'billing_period_num': 1,
    'category_array': [
        '5e3aac233c92e44b424b6dfb'
    ],
    'code': 'extra-5gb-data',
    'name': 'Extra 5GB Data',
    'price': 10,
    'plans_array': [
        ''
    ],
    'description': 'By adding this addon, you'll get extra 5GB data'
},
)

data = response.json()
```

_PHP_

```php
<?php
$ch = curl_init('https://payments.pabbly.com/api/v1/addon/{{product_id}}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
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, '{"billing_period":"m","billing_cycle":"lifetime","status":"true","associate_plans":"all_plans","billing_period_num":1,"category_array":["5e3aac233c92e44b424b6dfb"],"code":"extra-5gb-data","name":"Extra 5GB Data","price":10,"plans_array":[""],"description":"By adding this addon, you\'ll get extra 5GB data"}');

$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/addon/{{product_id}}"))
    .header("Authorization", "Basic " + credentials)
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("{\"billing_period\":\"m\",\"billing_cycle\":\"lifetime\",\"status\":\"true\",\"associate_plans\":\"all_plans\",\"billing_period_num\":1,\"category_array\":[\"5e3aac233c92e44b424b6dfb\"],\"code\":\"extra-5gb-data\",\"name\":\"Extra 5GB Data\",\"price\":10,\"plans_array\":[\"\"],\"description\":\"By adding this addon, you'll get extra 5GB data\"}"));

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/addon/{{product_id}}', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${credentials}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "billing_period": "m",
    "billing_cycle": "lifetime",
    "status": "true",
    "associate_plans": "all_plans",
    "billing_period_num": 1,
    "category_array": [
      "5e3aac233c92e44b424b6dfb"
    ],
    "code": "extra-5gb-data",
    "name": "Extra 5GB Data",
    "price": 10,
    "plans_array": [
      ""
    ],
    "description": "By adding this addon, you'll get extra 5GB data"
  }),
});

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

_Go_

```go
package main

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

func main() {
    payload := strings.NewReader("{\"billing_period\":\"m\",\"billing_cycle\":\"lifetime\",\"status\":\"true\",\"associate_plans\":\"all_plans\",\"billing_period_num\":1,\"category_array\":[\"5e3aac233c92e44b424b6dfb\"],\"code\":\"extra-5gb-data\",\"name\":\"Extra 5GB Data\",\"price\":10,\"plans_array\":[\"\"],\"description\":\"By adding this addon, you'll get extra 5GB data\"}")
    req, _ := http.NewRequest("POST", "https://payments.pabbly.com/api/v1/addon/{{product_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.Post, "https://payments.pabbly.com/api/v1/addon/{{product_id}}");
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {credentials}");
request.Content = new StringContent("{\"billing_period\":\"m\",\"billing_cycle\":\"lifetime\",\"status\":\"true\",\"associate_plans\":\"all_plans\",\"billing_period_num\":1,\"category_array\":[\"5e3aac233c92e44b424b6dfb\"],\"code\":\"extra-5gb-data\",\"name\":\"Extra 5GB Data\",\"price\":10,\"plans_array\":[\"\"],\"description\":\"By adding this addon, you'll get extra 5GB data\"}");
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 Add-on:**

- [GET /addon/{{addonId}} — Get Single Addon](/subscription-billing/add-on/get-single-addon)
- [GET /addons/{{product_id}} — List All Addons](/subscription-billing/add-on/list-all-addons)
- [PUT /addon/{{addon_id}} — Update Addon](/subscription-billing/add-on/update-addon)
- [DELETE /addon/{{addon_id}} — Delete Addon](/subscription-billing/add-on/delete-addon)

