---
title: Create
slug: payments/wpn77ubzkkpv8xkdvd5qv
description: Learn how to create a subscription using Apex code with this comprehensive guide. Explore the step-by-step process, including initializing request data and making a request to the Breadwinner Global API. Discover valuable insights on the response, includi
docTags: 
createdAt: 2023-11-29T11:35:11.215Z
---

To create a Subscription in Stripe, use the action “CreateSubscription” and pass the Subscription data in the RequestJSON under “subscriptions.”

:::hint{type="info"}
Note: You can only create one record at a time.
:::

Here is an example of creating a Subscription where we are setting every possible field(See[﻿](https://app.archbee.io/docs/-LIHUUnv_7XNQrtzHsKkC/hnjmkN99QxWdEafyYIFSq)﻿ [Subscription - Stripe](docId:2RpaKAnLE63bThFXEufQG) for all the available fields). The response will return the response back from Stripe, which includes the Subscription ID (*internalId*) plus the newly created Salesforce Subscription ID (*salesforceId*).

:::CodeblockTabs
```apex
Map<String, Object> subscriptionData = new Map<String, Object>();
subscriptionData.put('processorCustomerId', 'processorCustomerId'); 
subscriptionData.put('collectionMethod', 'charge_automatically'); 
subscriptionData.put('processorPaymentMethodId', 'processorPaymentMethodId'); 

List<object> items = new List<object>();
Map<String, Object> itemData = new Map<String, Object>();
itemData.put('processorPriceId', 'processorPriceId'); 
itemData.put('quantity', 2); 
items.add(itemData);
subscriptionData.put('items', items); 

//  Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('subscriptions', new List<Object>{subscriptionData});
String reqJSON = JSON.serialize(requestJSONMap);

Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version','1.0');
reqObj.put('action','CreateSubscription');
reqObj.put('processorId', 'processorId');
reqObj.put('requestJSON',reqJSON);

//  Placing a request to Breadwinner Global API
Map<String,Object> resp = bw_payments.BreadwinnerPaymentsAPI.call(reqObj);
System.debug(resp);
```

```json
{
  Action=CreateSubscription,
  validRequest=true,
  timestamp=1674648707968,
  version=1.0, 
  statusCode=200,
  responseJSON={
    "subscriptions": [
      {
        "trialPeriodDays": null,
        "trialFromPlan": null,
        "trialEnd": null,
        "subscriptionMetadata": null,
        "status": "Active",
        "startDate": null,
        "salesforceId": "salesforceSubscriptionId",
        "salesforceContact": null,
        "salesforceAccount": "salesforceAccountId",
        "prorationBehavior": null,
        "promotionCode": null,
        "processorSubscriptionId": "processorSubscriptionId",
        "processorPaymentMethodId": null,
        "processorOrgId": "processorOrgId",
        "processorCustomerId": null,
        "paymentBehaviour": null,
        "metadata": null,
        "latestInvoice": "latestInvoice",
        "items": [
          {
            "unitAmountDecimal": 100.00,
            "unitAmount": 100.00,
            "salesforceSubscriptionId": "salesforceSubscriptionId",
            "salesforceId": "salesforceSubscriptionItemId",
            "quantity": 2,
            "processorSubscriptionId": "processorSubscriptionId",
            "processorPriceId": null,
            "processorId": "processorItemId",
            "salesforcePriceId": "salesforcePriceId",
            "name": null,
            "invoice": null,
            "errorMessage": null,
            "description": null,
            "chargeCurrency": "USD",
            "amount": 200.00
          }
        ],
        "errorMessage": null,
        "description": null,
        "daysUntilDue": null,
        "salesforceCustomerId": "salesforceCustomerId",
        "currentPeriodStartDate": "2023-01-25T12:11:42.000Z",
        "currentPeriodEndDate": "2023-02-25T12:11:42.000Z",
        "createdVia": "Breadwinner",
        "createdDateInProcessor": "2023-01-25T12:11:42.000Z",
        "coupon": null,
        "collectionMethod": "Charge Automatically",
        "cancelImmediately": null,
        "cancelAtPeriodEnd": null,
        "cancelAt": null,
        "billingCycleAnchor": null,
        "backDateStartDate": null
      }
    ]
  }
}
```
:::

