# Create Subscription — Stripe

> Create a subscription. See the documentation.

- Key: `stripe-create-subscription`
- Type: Action (Write)
- Version: 0.1.7
- App: Stripe (`stripe`) — https://pipedream.com/apps/stripe.md
- This page (HTML): https://pipedream.com/apps/stripe/actions/create-subscription
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/stripe/actions/create-subscription/create-subscription.mjs

## Description

Create a subscription. [See the documentation](https://stripe.com/docs/api/subscriptions/create).

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `customer` | `string` | Yes | Example: cus_Jz4ErxGo9t1agg Options are loaded from the connected account. |
| `items` | `string[]` | Yes | Example: price_0HuVAoGHO3mdGsgAi0l1fEtm Options are loaded from the connected account. |
| `country` | `string` | No | Two-letter ISO country code Options are loaded from the connected account. |
| `currency` | `string` | No | Three-letter ISO currency code, in lowercase; must be a supported currency Options are loaded from the connected account. |
| `description` | `string` | No | An arbitrary string that you can attach to a the object eg. customer, invoice, etc. |
| `collectionMethod` | `string` | No | Either charge_automatically, or send_invoice. When charging automatically, Stripe will attempt to pay this subscription at the end of the cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as active. Defaults to charge_automatically. |
| `daysUntilDue` | `integer` | No | Number of days a customer has to pay invoices generated by this subscription. Valid only for subscriptions where collection_method is set to send_invoice. |
| `paymentType` | `string` | No | Payment method types that may be used |
| `defaultPaymentMethod` | `string` | No | Must belong to the customer associated with the invoice. If not set, defaults to the subscription’s default payment method, if any, or to the default payment method in the customer’s invoice settings. Options are loaded from the connected account. |
| `metadata` | `object` | No | Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to metadata. |
| `automaticTaxEnabled` | `boolean` | No | Enabled automatic tax calculation which will automatically compute tax rates on all invoices generated by the subscription. |
| `automaticTaxLiabilityType` | `string` | No | Type of the account referenced in the request. |
| `automaticTaxLiabilityAccount` | `string` | No | The connected account being referenced when Automatic Tax - Liability - Type is account. |
| `paymentBehavior` | `string` | No | Specifies whether to create the subscription in the incomplete or active state. Only applies to subscriptions when Collection Method is set to charge_automatically. See the documentation. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "stripe",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "stripe-create-subscription",
  arguments: {
    customer: "Customer ID",
    items: ["Price ID"],
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "stripe-create-subscription",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    stripe: { authProvisionId: "apn_xxxxxxx" },
    customer: "Customer ID",
    items: ["Price ID"],
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "stripe-create-subscription",
    "configured_props": {
      "stripe": { "authProvisionId": "apn_xxxxxxx" },
      "customer": "Customer ID",
      "items": ["Price ID"]
    }
  }'
```

---

- App: https://pipedream.com/apps/stripe.md · All apps: https://pipedream.com/apps
