# POST /subscription — Create Customer With Subscription

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

The post request API which is fired to create a new customer with a subscription. In response you will get a unique customer Id and Subscription Id.

**Body parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| first_name | string | No |  |
| last_name | string | No |  |
| email | string | No |  |
| card_number | string | No |  |
| month | string | No |  |
| year | string | No |  |
| cvv | string | No |  |
| gateway_type | string | No | 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. |
| gateway_id | string | No | Unique Id of the payment gateway from which the payment is processed. |
| street | string | No |  |
| city | string | No |  |
| state | string | No |  |
| zip_code | string | No |  |
| country | string | No |  |
| plan_id | string | No | Unique Id of the plan which you will assign to this customer. |
| coupon_code | string | No |  |
| redirect_to | string | No | The customer will be redirected to this link after successful payment. |
| plan_amount | string | No | Enter only the plan amount without adding the currency symbol. Example: 10, 25, 78, 198 etc. |
| quantity | string | No | Quantity of the plan. |
| is_affiliate | boolean | No | To create this customer as a Affiliate, It can be boolean value true or false |
| tax_id | string | No | To record a Tax Id of a customer. |
| 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. |
| Basic Details | string | No | First name, Last_name, and Email address of the customer. |
| Card Details | string | No | Card Number, Expiry, and CVV of the customers' CC. |
| Billing Address | string | No | Add the address details in respective fields. |

**Example request body:**

```json
{
    "first_name": "john",
    "last_name": "smith",
    "email": "jhonsmith@xxxxx.com",
    "card_number": "4111111111111111",
    "month": "11",
    "year": "2020",
    "cvv": "423",
    "gateway_type": "test",
    "gateway_id": "5ae0243aec4b151d26bbfe90",
    "street": "arera colony",
    "city": "Bhopal",
    "state": "MP",
    "zip_code": "462016",
    "country": "IN",
    "plan_id": "5e3bf8b8db85462760295d2f",
    "coupon_code": "PER",
    "redirect_to": "https://www.pabbly.com/",
    "plan_amount": "10",
    "quantity": "8",
    "is_affiliate": true,
    "tax_id": "taxid",
    "addons": {
        "5e3aac363c92e44b424b6dfc": {
            "checked": true,
            "quantity": 1
        },
        "5e3aac9424b63d4b28410d4e": {
            "checked": false,
            "quantity": 1
        }
    }
}
```

**Response (200)** — Create Customer With Subscription:

```json
{
    "status": "success",
    "message": "Subscription created successfully",
    "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": "arera colony",
                "city": "Bhopal",
                "state": "MP",
                "state_code": "",
                "zip_code": "462016",
                "country": "india"
            },
            "shipping_address": {
                "street1": "",
                "city": "",
                "state": "",
                "state_code": "",
                "zip_code": "",
                "country": ""
            },
            "referral_id": "0cd73276bd154feb3156207d3ec7",
            "createdAt": "2022-11-08T12:55:21.053Z",
            "updatedAt": "2022-11-09T10:30:57.574Z",
            "id": "636a51b918e49912836939af",
            "first_name": "Steve",
            "last_name": "Rono",
            "email_id": "ronoh@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": "₹",
            "payment_method": "offline",
            "taxable": true,
            "tax_apply": {
                "country": "india",
                "tax_id": "",
                "exempt_tax": []
            },
            "gateway_type": "offline",
            "payment_terms": "net0",
            "custom_fields": [],
            "requested_ip": "2402:e280:3e2d:3a7:51b2:2c63:86b5:16b5",
            "createdAt": "2022-11-09T10:30:57.583Z",
            "updatedAt": "2022-11-09T10:30:57.609Z",
            "id": "636b81610963064bb69bb45d",
            "customer_id": "636a51b918e49912836939af",
            "product_id": "636a3d6f6673cf11c7bc3ba2",
            "plan_id": "636a463a18e4991283693807",
            "amount": 40,
            "email_id": "ronoh@inboxkitten.com",
            "status": "pending",
            "quantity": 1,
            "starts_at": "2022-11-09T10:30:57.575Z",
            "activation_date": "",
            "expiry_date": "2122-11-09T10:30:57.575Z",
            "trial_days": 0,
            "trial_expiry_date": "",
            "next_billing_date": "",
            "last_billing_date": "",
            "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": 40,
                "total_credit_amount": 0,
                "charge_amount": 40,
                "credit_applied": []
            },
            "tax_apply": {
                "country": "india",
                "tax_id": "",
                "exempt_tax": [],
                "total_amount": 40,
                "total_amount_before_tax": 40,
                "total_tax": 0
            },
            "createdAt": "2022-11-09T10:30:57.598Z",
            "updatedAt": "2022-11-09T10:30:57.612Z",
            "id": "636b81610963064bb69bb45e",
            "customer_id": "636a51b918e49912836939af",
            "subscription_id": "636b81610963064bb69bb45d",
            "status": "sent",
            "invoice_id": "INV-15",
            "payment_term": "net0",
            "amount": 40,
            "due_amount": 40,
            "due_date": "2022-11-09T10:30:57.575Z",
            "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": "₹",
                "payment_method": "offline",
                "taxable": true,
                "tax_apply": {
                    "country": "india",
                    "tax_id": "",
                    "exempt_tax": []
                },
                "gateway_type": "offline",
                "payment_terms": "net0",
                "custom_fields": [],
                "requested_ip": "2402:e280:3e2d:3a7:51b2:2c63:86b5:16b5",
                "createdAt": "2022-11-09T10:30:57.583Z",
                "updatedAt": "2022-11-09T10:30:57.609Z",
                "id": "636b81610963064bb69bb45d",
                "customer_id": "636a51b918e49912836939af",
                "product_id": "636a3d6f6673cf11c7bc3ba2",
                "plan_id": "636a463a18e4991283693807",
                "amount": 40,
                "email_id": "ronoh@inboxkitten.com",
                "status": "pending",
                "quantity": 1,
                "starts_at": "2022-11-09T10:30:57.575Z",
                "activation_date": "",
                "expiry_date": "2122-11-09T10:30:57.575Z",
                "trial_days": 0,
                "trial_expiry_date": "",
                "next_billing_date": "",
                "last_billing_date": "",
                "canceled_date": null
            },
            "invoice_link": "https://payments.pabbly.com/secureinvoice/5fd0a9c43979a81ddafa0aa3/?cinvoice_id=a7d9a7c1dcd91c6ba1d1593b18340e87:f9f5472b555b61bc572e5c9eda2582c09424263a311defc9a30bc8e8e13ba66496c036f720f8bc29e3037af1d182bacf2d7f3eb9fa7515a7ef9e33f0ffaf59f1cb57bf8dc6ff503bb729e3c69edd644a"
        }
    }
}
```

**Code examples:**

_cURL_

```curl
curl -X POST https://payments.pabbly.com/api/v1/subscription \
  -u {{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}} \
  -H "Content-Type: application/json" \
  -d '{
    "first_name": "john",
    "last_name": "smith",
    "email": "jhonsmith@xxxxx.com",
    "card_number": "4111111111111111",
    "month": "11",
    "year": "2020",
    "cvv": "423",
    "gateway_type": "test",
    "gateway_id": "5ae0243aec4b151d26bbfe90",
    "street": "arera colony",
    "city": "Bhopal",
    "state": "MP",
    "zip_code": "462016",
    "country": "IN",
    "plan_id": "5e3bf8b8db85462760295d2f",
    "coupon_code": "PER",
    "redirect_to": "https://www.pabbly.com/",
    "plan_amount": "10",
    "quantity": "8",
    "is_affiliate": true,
    "tax_id": "taxid",
    "addons": {
      "5e3aac363c92e44b424b6dfc": {
        "checked": true,
        "quantity": 1
      },
      "5e3aac9424b63d4b28410d4e": {
        "checked": false,
        "quantity": 1
      }
    }
  }'
```

_Ruby_

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

uri = URI('https://payments.pabbly.com/api/v1/subscription')
request = Net::HTTP::Post.new(uri)
request.basic_auth '{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'
request['Content-Type'] = 'application/json'
request.body = "{\"first_name\":\"john\",\"last_name\":\"smith\",\"email\":\"jhonsmith@xxxxx.com\",\"card_number\":\"4111111111111111\",\"month\":\"11\",\"year\":\"2020\",\"cvv\":\"423\",\"gateway_type\":\"test\",\"gateway_id\":\"5ae0243aec4b151d26bbfe90\",\"street\":\"arera colony\",\"city\":\"Bhopal\",\"state\":\"MP\",\"zip_code\":\"462016\",\"country\":\"IN\",\"plan_id\":\"5e3bf8b8db85462760295d2f\",\"coupon_code\":\"PER\",\"redirect_to\":\"https://www.pabbly.com/\",\"plan_amount\":\"10\",\"quantity\":\"8\",\"is_affiliate\":true,\"tax_id\":\"taxid\",\"addons\":{\"5e3aac363c92e44b424b6dfc\":{\"checked\":true,\"quantity\":1},\"5e3aac9424b63d4b28410d4e\":{\"checked\":false,\"quantity\":1}}}"

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',
    auth=HTTPBasicAuth('{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'),
    json={
    'first_name': 'john',
    'last_name': 'smith',
    'email': 'jhonsmith@xxxxx.com',
    'card_number': '4111111111111111',
    'month': '11',
    'year': '2020',
    'cvv': '423',
    'gateway_type': 'test',
    'gateway_id': '5ae0243aec4b151d26bbfe90',
    'street': 'arera colony',
    'city': 'Bhopal',
    'state': 'MP',
    'zip_code': '462016',
    'country': 'IN',
    'plan_id': '5e3bf8b8db85462760295d2f',
    'coupon_code': 'PER',
    'redirect_to': 'https://www.pabbly.com/',
    'plan_amount': '10',
    'quantity': '8',
    'is_affiliate': True,
    'tax_id': 'taxid',
    'addons': {
        '5e3aac363c92e44b424b6dfc': {
            'checked': True,
            'quantity': 1
        },
        '5e3aac9424b63d4b28410d4e': {
            'checked': False,
            'quantity': 1
        }
    }
},
)

data = response.json()
```

_PHP_

```php
<?php
$ch = curl_init('https://payments.pabbly.com/api/v1/subscription');
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, '{"first_name":"john","last_name":"smith","email":"jhonsmith@xxxxx.com","card_number":"4111111111111111","month":"11","year":"2020","cvv":"423","gateway_type":"test","gateway_id":"5ae0243aec4b151d26bbfe90","street":"arera colony","city":"Bhopal","state":"MP","zip_code":"462016","country":"IN","plan_id":"5e3bf8b8db85462760295d2f","coupon_code":"PER","redirect_to":"https://www.pabbly.com/","plan_amount":"10","quantity":"8","is_affiliate":true,"tax_id":"taxid","addons":{"5e3aac363c92e44b424b6dfc":{"checked":true,"quantity":1},"5e3aac9424b63d4b28410d4e":{"checked":false,"quantity":1}}}');

$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"))
    .header("Authorization", "Basic " + credentials)
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("{\"first_name\":\"john\",\"last_name\":\"smith\",\"email\":\"jhonsmith@xxxxx.com\",\"card_number\":\"4111111111111111\",\"month\":\"11\",\"year\":\"2020\",\"cvv\":\"423\",\"gateway_type\":\"test\",\"gateway_id\":\"5ae0243aec4b151d26bbfe90\",\"street\":\"arera colony\",\"city\":\"Bhopal\",\"state\":\"MP\",\"zip_code\":\"462016\",\"country\":\"IN\",\"plan_id\":\"5e3bf8b8db85462760295d2f\",\"coupon_code\":\"PER\",\"redirect_to\":\"https://www.pabbly.com/\",\"plan_amount\":\"10\",\"quantity\":\"8\",\"is_affiliate\":true,\"tax_id\":\"taxid\",\"addons\":{\"5e3aac363c92e44b424b6dfc\":{\"checked\":true,\"quantity\":1},\"5e3aac9424b63d4b28410d4e\":{\"checked\":false,\"quantity\":1}}}"));

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', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${credentials}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "first_name": "john",
    "last_name": "smith",
    "email": "jhonsmith@xxxxx.com",
    "card_number": "4111111111111111",
    "month": "11",
    "year": "2020",
    "cvv": "423",
    "gateway_type": "test",
    "gateway_id": "5ae0243aec4b151d26bbfe90",
    "street": "arera colony",
    "city": "Bhopal",
    "state": "MP",
    "zip_code": "462016",
    "country": "IN",
    "plan_id": "5e3bf8b8db85462760295d2f",
    "coupon_code": "PER",
    "redirect_to": "https://www.pabbly.com/",
    "plan_amount": "10",
    "quantity": "8",
    "is_affiliate": true,
    "tax_id": "taxid",
    "addons": {
      "5e3aac363c92e44b424b6dfc": {
        "checked": true,
        "quantity": 1
      },
      "5e3aac9424b63d4b28410d4e": {
        "checked": false,
        "quantity": 1
      }
    }
  }),
});

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

_Go_

```go
package main

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

func main() {
    payload := strings.NewReader("{\"first_name\":\"john\",\"last_name\":\"smith\",\"email\":\"jhonsmith@xxxxx.com\",\"card_number\":\"4111111111111111\",\"month\":\"11\",\"year\":\"2020\",\"cvv\":\"423\",\"gateway_type\":\"test\",\"gateway_id\":\"5ae0243aec4b151d26bbfe90\",\"street\":\"arera colony\",\"city\":\"Bhopal\",\"state\":\"MP\",\"zip_code\":\"462016\",\"country\":\"IN\",\"plan_id\":\"5e3bf8b8db85462760295d2f\",\"coupon_code\":\"PER\",\"redirect_to\":\"https://www.pabbly.com/\",\"plan_amount\":\"10\",\"quantity\":\"8\",\"is_affiliate\":true,\"tax_id\":\"taxid\",\"addons\":{\"5e3aac363c92e44b424b6dfc\":{\"checked\":true,\"quantity\":1},\"5e3aac9424b63d4b28410d4e\":{\"checked\":false,\"quantity\":1}}}")
    req, _ := http.NewRequest("POST", "https://payments.pabbly.com/api/v1/subscription", 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");
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {credentials}");
request.Content = new StringContent("{\"first_name\":\"john\",\"last_name\":\"smith\",\"email\":\"jhonsmith@xxxxx.com\",\"card_number\":\"4111111111111111\",\"month\":\"11\",\"year\":\"2020\",\"cvv\":\"423\",\"gateway_type\":\"test\",\"gateway_id\":\"5ae0243aec4b151d26bbfe90\",\"street\":\"arera colony\",\"city\":\"Bhopal\",\"state\":\"MP\",\"zip_code\":\"462016\",\"country\":\"IN\",\"plan_id\":\"5e3bf8b8db85462760295d2f\",\"coupon_code\":\"PER\",\"redirect_to\":\"https://www.pabbly.com/\",\"plan_amount\":\"10\",\"quantity\":\"8\",\"is_affiliate\":true,\"tax_id\":\"taxid\",\"addons\":{\"5e3aac363c92e44b424b6dfc\":{\"checked\":true,\"quantity\":1},\"5e3aac9424b63d4b28410d4e\":{\"checked\":false,\"quantity\":1}}}");
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 Customers:**

- [GET /customer/{{customer_id}} — Get Single Customer via Customer ID](/subscription-billing/customers/get-single-customer-via-customer-id)
- [GET /customer/ — Get Single Customer via Customer Email](/subscription-billing/customers/get-single-customer-via-customer-email)
- [GET /customer/purchase-info/{{customer_id}} — Get Customer Purchase Information](/subscription-billing/customers/get-customer-purchase-information)
- [GET /customers — List All Customers](/subscription-billing/customers/list-all-customers)
- [PUT /customer/{{customer_id}} — Update Customer Detail](/subscription-billing/customers/update-customer-detail)
- [DELETE /customers/{{customer_id}} — Delete Customer](/subscription-billing/customers/delete-customer)
- [POST /customer — Create Customer](/subscription-billing/customers/create-customer)

