# POST /subscription/{{customer_id}} — Create Subscription For Existing Customer

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

The POST request API. In which you will add the customer Id in the link. In response you will get the details of the subscribed plan and a subscription Id. Atrributes::

**Path parameters:**

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

**Body parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| plan_id | string | Yes | Unique Id of the plan which you will assign to this customer. |
| quantity | integer | No | Quantity of the plan. |
| addons | object | No | Addons. |
|   ↳ 5e3aac363c92e44b424b6dfc | object | No |  |
|     ↳ checked | boolean | No |  |
|     ↳ quantity | integer | No | Quantity of the plan. |
|   ↳ 5e3aac9424b63d4b28410d4e | object | No |  |
|     ↳ checked | boolean | No |  |
|     ↳ quantity | integer | No | Quantity of the plan. |
| gateway_type | string | Yes | It can be one of paypal, stripe, test, custom, connect, offline or free. Note: For Razorpay & Authorize gateway gateway_type will be "custom" and for other gateways which are not listed here for them gateway_type will be "connect" ex: Paddle, Adyen & Instamojo. |
| card_number | string | No |  |
| month | string | No |  |
| year | string | No |  |
| cvv | string | No |  |
| gateway_id | string | Yes | When there are multiple payment gateways of same kind. Then add the gateway id from which you want to process the payment |
| redirect_to | string | No | The customer will be redirected to this link after successful payment. |
| tax_id | string | No | To record a Tax Id of a customer. |
| Card Details | string | No | Card Number, Expiry, and CVV of the customers' CC. |
| method_id | string | No | Payment method id if you want to charge payment from an existing or specific card. |
| coupon_code | string | No | This coupon code will be added to this subscription. |
| plan_amount | string | No | Enter only the plan amount without adding the currency symbol. Example: 10, 25, 78, 198 etc. |

**Example request body:**

```json
{
    "plan_id": "5e3bf8b8db85462760295d2f",
    "quantity": 1,
    "addons": {
        "5e3aac363c92e44b424b6dfc": {
            "checked": true,
            "quantity": 1
        },
        "5e3aac9424b63d4b28410d4e": {
            "checked": false,
            "quantity": 1
        }
    },
    "gateway_type": "test",
    "card_number": "4111111111111111",
    "month": "11",
    "year": "2020",
    "cvv": "423",
    "gateway_id": "5e3a950824b63d4b28410c8d",
    "redirect_to": "https://www.pabbly.com/",
    "tax_id": "taxid"
}
```

**Response (200)** — Create Subscription For Existing Customer:

```json
{
    "status": "success",
    "message": "Your payment is successful.",
    "data": {
        "user": {
            "currency": "INR",
            "verified": "0",
            "createdAt": "2020-12-09T10:41:08.853Z",
            "updatedAt": "2022-08-22T12:22:49.056Z",
            "id": "5fd0a9c41cc97d04a15e2a00",
            "first_name": "Carlos",
            "last_name": "Pereira",
            "email": "sweety.wasnik+inr@gmail.com",
            "address_line1": "",
            "address_line2": "",
            "city": "Avanca",
            "state": "Porto",
            "country": "Portugal",
            "zip_code": "3860-078",
            "phone": "918794265",
            "mobile": "",
            "facebook_url": "",
            "twitter_url": "",
            "time_zone": "Asia/Barnaul",
            "date_format": "MMM DD, YYYY hh:mm A",
            "currency_symbol": "₹"
        },
        "customer": {
            "is_affiliate": true,
            "billing_address": {
                "street1": "",
                "city": "",
                "state": "",
                "state_code": "",
                "zip_code": "",
                "country": ""
            },
            "shipping_address": {
                "street1": "",
                "city": "",
                "state": "",
                "state_code": "",
                "zip_code": "",
                "country": ""
            },
            "referral_id": "5c7f7690b96a98eb64392147e4ee",
            "tax_id": "taxid",
            "createdAt": "2022-11-09T10:06:35.691Z",
            "updatedAt": "2022-11-09T10:55:20.577Z",
            "id": "636b7bab56e1a04bce59979d",
            "first_name": "exactly",
            "last_name": "quietly",
            "email_id": "excellent-village-19@inboxkitten.com"
        },
        "product": {
            "status": "active",
            "createdAt": "2022-11-08T11:28:47.602Z",
            "updatedAt": "2022-11-08T11:28:47.602Z",
            "id": "636a3d6f6673cf11c7bc3ba2",
            "product_name": "Cab Booking"
        },
        "plan": {
            "plan_type": "flat_fee",
            "plan_active": "true",
            "failed_payment_gateway": "",
            "failed_payment_gateway_array": [],
            "funnel": [],
            "setup_fee_type": "",
            "trial_type": "day",
            "createdAt": "2022-11-08T12:06:18.219Z",
            "updatedAt": "2022-11-09T05:42:52.486Z",
            "id": "636a463a18e4991283693807",
            "product_id": "636a3d6f6673cf11c7bc3ba2",
            "plan_name": "Uber Base Fare",
            "plan_code": "uber-base-fare",
            "price": 40,
            "billing_period": "",
            "billing_period_num": "",
            "billing_cycle": "onetime",
            "billing_cycle_num": "",
            "trial_period": 0,
            "setup_fee": 0,
            "plan_description": "<p><br></p>"
        },
        "subscription": {
            "plan": {
                "plan_type": "flat_fee",
                "plan_active": "true",
                "failed_payment_gateway": "",
                "failed_payment_gateway_array": [],
                "funnel": [],
                "setup_fee_type": "",
                "trial_type": "day",
                "createdAt": "2022-11-08T12:06:18.219Z",
                "updatedAt": "2022-11-09T05:42:52.486Z",
                "id": "636a463a18e4991283693807",
                "product_id": "636a3d6f6673cf11c7bc3ba2",
                "plan_name": "Uber Base Fare",
                "plan_code": "uber-base-fare",
                "price": 40,
                "billing_period": "",
                "billing_period_num": "",
                "billing_cycle": "onetime",
                "billing_cycle_num": "",
                "trial_period": 0,
                "setup_fee": 0,
                "plan_description": "<p><br></p>"
            },
            "setup_fee": 0,
            "currency_symbol": "₹",
            "addons": [
                {
                    "id": "636b3e3918e49912836955be",
                    "name": "1 Per Min",
                    "product_id": "636a3d6f6673cf11c7bc3ba2",
                    "code": "1-per-min",
                    "price": 1,
                    "quantity": 1,
                    "billing_cycle": "onetime",
                    "billing_period": "",
                    "associate_plans": "selected_plans",
                    "plans_array": [
                        "636a463a18e4991283693807"
                    ],
                    "category_array": [
                        "uncategory"
                    ],
                    "adjusted_amount": 1
                }
            ],
            "payment_method": "636b87180963064bb69bb51f",
            "taxable": true,
            "tax_apply": {
                "country": "",
                "tax_id": "taxid",
                "exempt_tax": [],
                "total_amount": 41,
                "total_tax": 0,
                "total_amount_before_tax": 41
            },
            "gateway_type": "test",
            "payment_terms": "net0",
            "gateway_id": "5fd0a9e53979a81ddafa0ab1",
            "gateway_name": "Test Gateway",
            "custom_fields": [],
            "requested_ip": "2402:e280:3e2d:3a7:51b2:2c63:86b5:16b5",
            "createdAt": "2022-11-09T10:55:20.589Z",
            "updatedAt": "2022-11-09T10:55:21.134Z",
            "id": "636b87180963064bb69bb51c",
            "customer_id": "636b7bab56e1a04bce59979d",
            "product_id": "636a3d6f6673cf11c7bc3ba2",
            "plan_id": "636a463a18e4991283693807",
            "amount": 40,
            "email_id": "excellent-village-19@inboxkitten.com",
            "status": "live",
            "quantity": 1,
            "starts_at": "2022-11-09T10:55:20.202Z",
            "activation_date": "2022-11-09T10:55:21.212Z",
            "expiry_date": "2122-11-09T10:55:20.202Z",
            "trial_days": 0,
            "trial_expiry_date": "",
            "next_billing_date": "",
            "last_billing_date": "2022-11-09T10:55:21.212Z",
            "canceled_date": null
        },
        "invoice": {
            "quantity": 1,
            "product_id": "636a3d6f6673cf11c7bc3ba2",
            "setup_fee": 0,
            "currency_symbol": "₹",
            "credit_note": {
                "total_tax": "0.00",
                "status": "success",
                "new_plan_total": 41,
                "total_credit_amount": 0,
                "charge_amount": 41,
                "credit_applied": []
            },
            "tax_apply": {
                "country": "",
                "tax_id": "taxid",
                "exempt_tax": [],
                "total_amount": 41,
                "total_tax": 0,
                "total_amount_before_tax": 41
            },
            "createdAt": "2022-11-09T10:55:20.602Z",
            "updatedAt": "2022-11-09T10:55:20.607Z",
            "id": "636b87180963064bb69bb51d",
            "customer_id": "636b7bab56e1a04bce59979d",
            "subscription_id": "636b87180963064bb69bb51c",
            "status": "paid",
            "invoice_id": "INV-17",
            "payment_term": "net0",
            "amount": 41,
            "due_amount": 0,
            "due_date": "2022-11-09T10:55:20.202Z",
            "subscription": {
                "plan": {
                    "plan_type": "flat_fee",
                    "plan_active": "true",
                    "failed_payment_gateway": "",
                    "failed_payment_gateway_array": [],
                    "funnel": [],
                    "setup_fee_type": "",
                    "trial_type": "day",
                    "createdAt": "2022-11-08T12:06:18.219Z",
                    "updatedAt": "2022-11-09T05:42:52.486Z",
                    "id": "636a463a18e4991283693807",
                    "product_id": "636a3d6f6673cf11c7bc3ba2",
                    "plan_name": "Uber Base Fare",
                    "plan_code": "uber-base-fare",
                    "price": 40,
                    "billing_period": "",
                    "billing_period_num": "",
                    "billing_cycle": "onetime",
                    "billing_cycle_num": "",
                    "trial_period": 0,
                    "setup_fee": 0,
                    "plan_description": "<p><br></p>"
                },
                "setup_fee": 0,
                "currency_symbol": "₹",
                "addons": [
                    {
                        "id": "636b3e3918e49912836955be",
                        "name": "1 Per Min",
                        "product_id": "636a3d6f6673cf11c7bc3ba2",
                        "code": "1-per-min",
                        "price": 1,
                        "quantity": 1,
                        "billing_cycle": "onetime",
                        "billing_period": "",
                        "associate_plans": "selected_plans",
                        "plans_array": [
                            "636a463a18e4991283693807"
                        ],
                        "category_array": [
                            "uncategory"
                        ],
                        "adjusted_amount": 1
                    }
                ],
                "payment_method": "636b87180963064bb69bb51f",
                "taxable": true,
                "tax_apply": {
                    "country": "",
                    "tax_id": "taxid",
                    "exempt_tax": [],
                    "total_amount": 41,
                    "total_tax": 0,
                    "total_amount_before_tax": 41
                },
                "gateway_type": "test",
                "payment_terms": "net0",
                "gateway_id": "5fd0a9e53979a81ddafa0ab1",
                "gateway_name": "Test Gateway",
                "custom_fields": [],
                "requested_ip": "2402:e280:3e2d:3a7:51b2:2c63:86b5:16b5",
                "createdAt": "2022-11-09T10:55:20.589Z",
                "updatedAt": "2022-11-09T10:55:21.134Z",
                "id": "636b87180963064bb69bb51c",
                "customer_id": "636b7bab56e1a04bce59979d",
                "product_id": "636a3d6f6673cf11c7bc3ba2",
                "plan_id": "636a463a18e4991283693807",
                "amount": 40,
                "email_id": "excellent-village-19@inboxkitten.com",
                "status": "live",
                "quantity": 1,
                "starts_at": "2022-11-09T10:55:20.202Z",
                "activation_date": "2022-11-09T10:55:21.212Z",
                "expiry_date": "2122-11-09T10:55:20.202Z",
                "trial_days": 0,
                "trial_expiry_date": "",
                "next_billing_date": "",
                "last_billing_date": "2022-11-09T10:55:21.212Z",
                "canceled_date": null
            },
            "product": {
                "status": "active",
                "createdAt": "2022-11-08T11:28:47.602Z",
                "updatedAt": "2022-11-08T11:28:47.602Z",
                "id": "636a3d6f6673cf11c7bc3ba2",
                "product_name": "Cab Booking"
            },
            "invoice_link": "https://payments.pabbly.com/secureinvoice/5fd0a9c43979a81ddafa0aa3/?cinvoice_id=3dfb9801d56103c5593b5355626725f9:06b303450cbc222ffe585ddbf4e700f8931be86cd3657bd2f44648229fea8fa23c9f0ba5578e3dee35266bd5e1e1e12881c385903a9660574712672eff9c458de77d44d5c61e6caabd4bb4f258d375fd"
        }
    }
}
```

**Code examples:**

_cURL_

```curl
curl -X POST https://payments.pabbly.com/api/v1/subscription/{{customer_id}} \
  -u {{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}} \
  -H "Content-Type: application/json" \
  -d '{
    "plan_id": "5e3bf8b8db85462760295d2f",
    "quantity": 1,
    "addons": {
      "5e3aac363c92e44b424b6dfc": {
        "checked": true,
        "quantity": 1
      },
      "5e3aac9424b63d4b28410d4e": {
        "checked": false,
        "quantity": 1
      }
    },
    "gateway_type": "test",
    "card_number": "4111111111111111",
    "month": "11",
    "year": "2020",
    "cvv": "423",
    "gateway_id": "5e3a950824b63d4b28410c8d",
    "redirect_to": "https://www.pabbly.com/",
    "tax_id": "taxid"
  }'
```

_Ruby_

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

uri = URI('https://payments.pabbly.com/api/v1/subscription/{{customer_id}}')
request = Net::HTTP::Post.new(uri)
request.basic_auth '{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'
request['Content-Type'] = 'application/json'
request.body = "{\"plan_id\":\"5e3bf8b8db85462760295d2f\",\"quantity\":1,\"addons\":{\"5e3aac363c92e44b424b6dfc\":{\"checked\":true,\"quantity\":1},\"5e3aac9424b63d4b28410d4e\":{\"checked\":false,\"quantity\":1}},\"gateway_type\":\"test\",\"card_number\":\"4111111111111111\",\"month\":\"11\",\"year\":\"2020\",\"cvv\":\"423\",\"gateway_id\":\"5e3a950824b63d4b28410c8d\",\"redirect_to\":\"https://www.pabbly.com/\",\"tax_id\":\"taxid\"}"

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/subscription/{{customer_id}}',
    auth=HTTPBasicAuth('{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'),
    json={
    'plan_id': '5e3bf8b8db85462760295d2f',
    'quantity': 1,
    'addons': {
        '5e3aac363c92e44b424b6dfc': {
            'checked': True,
            'quantity': 1
        },
        '5e3aac9424b63d4b28410d4e': {
            'checked': False,
            'quantity': 1
        }
    },
    'gateway_type': 'test',
    'card_number': '4111111111111111',
    'month': '11',
    'year': '2020',
    'cvv': '423',
    'gateway_id': '5e3a950824b63d4b28410c8d',
    'redirect_to': 'https://www.pabbly.com/',
    'tax_id': 'taxid'
},
)

data = response.json()
```

_PHP_

```php
<?php
$ch = curl_init('https://payments.pabbly.com/api/v1/subscription/{{customer_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, '{"plan_id":"5e3bf8b8db85462760295d2f","quantity":1,"addons":{"5e3aac363c92e44b424b6dfc":{"checked":true,"quantity":1},"5e3aac9424b63d4b28410d4e":{"checked":false,"quantity":1}},"gateway_type":"test","card_number":"4111111111111111","month":"11","year":"2020","cvv":"423","gateway_id":"5e3a950824b63d4b28410c8d","redirect_to":"https://www.pabbly.com/","tax_id":"taxid"}');

$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/subscription/{{customer_id}}"))
    .header("Authorization", "Basic " + credentials)
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("{\"plan_id\":\"5e3bf8b8db85462760295d2f\",\"quantity\":1,\"addons\":{\"5e3aac363c92e44b424b6dfc\":{\"checked\":true,\"quantity\":1},\"5e3aac9424b63d4b28410d4e\":{\"checked\":false,\"quantity\":1}},\"gateway_type\":\"test\",\"card_number\":\"4111111111111111\",\"month\":\"11\",\"year\":\"2020\",\"cvv\":\"423\",\"gateway_id\":\"5e3a950824b63d4b28410c8d\",\"redirect_to\":\"https://www.pabbly.com/\",\"tax_id\":\"taxid\"}"));

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/subscription/{{customer_id}}', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${credentials}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "plan_id": "5e3bf8b8db85462760295d2f",
    "quantity": 1,
    "addons": {
      "5e3aac363c92e44b424b6dfc": {
        "checked": true,
        "quantity": 1
      },
      "5e3aac9424b63d4b28410d4e": {
        "checked": false,
        "quantity": 1
      }
    },
    "gateway_type": "test",
    "card_number": "4111111111111111",
    "month": "11",
    "year": "2020",
    "cvv": "423",
    "gateway_id": "5e3a950824b63d4b28410c8d",
    "redirect_to": "https://www.pabbly.com/",
    "tax_id": "taxid"
  }),
});

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

_Go_

```go
package main

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

func main() {
    payload := strings.NewReader("{\"plan_id\":\"5e3bf8b8db85462760295d2f\",\"quantity\":1,\"addons\":{\"5e3aac363c92e44b424b6dfc\":{\"checked\":true,\"quantity\":1},\"5e3aac9424b63d4b28410d4e\":{\"checked\":false,\"quantity\":1}},\"gateway_type\":\"test\",\"card_number\":\"4111111111111111\",\"month\":\"11\",\"year\":\"2020\",\"cvv\":\"423\",\"gateway_id\":\"5e3a950824b63d4b28410c8d\",\"redirect_to\":\"https://www.pabbly.com/\",\"tax_id\":\"taxid\"}")
    req, _ := http.NewRequest("POST", "https://payments.pabbly.com/api/v1/subscription/{{customer_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/subscription/{{customer_id}}");
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {credentials}");
request.Content = new StringContent("{\"plan_id\":\"5e3bf8b8db85462760295d2f\",\"quantity\":1,\"addons\":{\"5e3aac363c92e44b424b6dfc\":{\"checked\":true,\"quantity\":1},\"5e3aac9424b63d4b28410d4e\":{\"checked\":false,\"quantity\":1}},\"gateway_type\":\"test\",\"card_number\":\"4111111111111111\",\"month\":\"11\",\"year\":\"2020\",\"cvv\":\"423\",\"gateway_id\":\"5e3a950824b63d4b28410c8d\",\"redirect_to\":\"https://www.pabbly.com/\",\"tax_id\":\"taxid\"}");
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 Subscriptions:**

- [POST /subscription/{{subscription_id}}/cancel — Cancel Subscription For Existing Customer](/subscription-billing/subscriptions/cancel-subscription-for-existing-customer)
- [GET /subscription/{{subscription_id}} — Get Single Subscription](/subscription-billing/subscriptions/get-single-subscription)
- [GET /subscriptions/{{customer_id}} — List All Subscriptions By Customer Id](/subscription-billing/subscriptions/list-all-subscriptions-by-customer-id)
- [GET /subscriptions — List All Subscriptions](/subscription-billing/subscriptions/list-all-subscriptions)
- [GET /scheduledchanges/{{suscription_id}} — Get Scheduled Subscription](/subscription-billing/subscriptions/get-scheduled-subscription)
- [PUT /subscription/{{subscription_id}}/upgrade-downgrade — Upgrade Downgrade Subscription](/subscription-billing/subscriptions/upgrade-downgrade-subscription)
- [POST /subscription/{{subscription_id}}/update_charges — Subscription Update Charges](/subscription-billing/subscriptions/subscription-update-charges)
- [DELETE /subscriptions/{{subscription_id}} — Delete Subscription](/subscription-billing/subscriptions/delete-subscription)
- [PUT /subscription/change-billing/{{subscription_id}} — Change Subscription Billing Date](/subscription-billing/subscriptions/change-subscription-billing-date)
- [PUT /subscription/{{subscription_id}}/update — Update Subscription](/subscription-billing/subscriptions/update-subscription)
- [PUT /subscription/{{subscription_id}}/pause — Pause Subscription](/subscription-billing/subscriptions/pause-subscription)
- [PUT /subscription/{{subscription_id}}/resume — Resume Subscription](/subscription-billing/subscriptions/resume-subscription)

