# Add a plan to a product

> Adds a plan to an existing product. The plan body is the same shape `createProduct` accepts inside `plans`.

Source: https://help.boltapp.com/api-reference/subscriptions/plans-v1/createplan

`POST /v1/subscriptions/products/{productId}/plans`

## OpenAPI definition

This endpoint as it appears in the OpenAPI document, with every schema it references included.

```json
{
  "openapi": "3.2.0",
  "info": {
    "title": "Subscriptions API",
    "version": "v1",
    "description": "API for managing subscriptions and products."
  },
  "servers": [
    {
      "url": "https://api.boltapp.com",
      "description": "The Production URL (Live Data)."
    },
    {
      "url": "https://api-sandbox.boltapp.com",
      "description": "The Sandbox URL (Test Data)."
    },
    {
      "url": "https://api-staging.boltapp.com",
      "description": "The Staging URL (Staged Data)."
    }
  ],
  "security": [
    {
      "X-API-Key": []
    },
    {
      "X-Publishable-Key": []
    }
  ],
  "paths": {
    "/v1/subscriptions/products/{productId}/plans": {
      "post": {
        "operationId": "createPlan",
        "summary": "Add a plan to a product",
        "description": "Adds a plan to an existing product. The plan body is the same shape `createProduct` accepts inside `plans`.",
        "tags": [
          "Plans v1"
        ],
        "security": [
          {
            "X-API-Key": []
          },
          {
            "X-Publishable-Key": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "productId",
            "schema": {
              "type": "string"
            },
            "required": true,
            "description": "ID of the product to add the plan to.",
            "examples": {
              "default": {
                "value": "sp_Tlj0Osm0N76T"
              }
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "frequency",
                  "frequency_unit"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "examples": [
                      "Monthly"
                    ]
                  },
                  "sku": {
                    "type": "string"
                  },
                  "frequency": {
                    "type": "integer",
                    "examples": [
                      1
                    ]
                  },
                  "frequency_unit": {
                    "type": "string",
                    "enum": [
                      "day",
                      "week",
                      "month",
                      "year"
                    ],
                    "examples": [
                      "month"
                    ]
                  },
                  "base_price": {
                    "type": "string",
                    "description": "The plan's recurring charge in major units (for example `\"30.00\"`). Required together with `currency` for usage-billed plans."
                  },
                  "currency": {
                    "type": "string"
                  },
                  "ubb": {
                    "type": "boolean",
                    "description": "Marks the plan as usage-billed. Must be `true` exactly when `usage` is supplied."
                  },
                  "usage": {
                    "$ref": "#/components/schemas/PlanUsageInput"
                  },
                  "trial": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "properties": {
                      "trial_days": {
                        "type": "integer",
                        "format": "int64"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created plan.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Plan"
                }
              }
            }
          },
          "400": {
            "description": "Bad request."
          },
          "401": {
            "description": "Unauthorized - Invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Product not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PlanUsageInput": {
        "type": [
          "object",
          "null"
        ],
        "description": "Metering and pricing for one usage-billed plan. Supply exactly one of `meter_id` (reuse a division meter) or `meter` (create one inline).",
        "properties": {
          "meter_id": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "description": "An existing meter's ID."
          },
          "meter": {
            "type": [
              "object",
              "null"
            ],
            "description": "A meter to create inline.",
            "properties": {
              "display_name": {
                "type": "string"
              },
              "event_type": {
                "type": "string"
              },
              "aggregation_type": {
                "type": "string",
                "enum": [
                  "sum",
                  "count"
                ]
              },
              "filter": {
                "type": "object"
              }
            }
          },
          "charge_model": {
            "type": "string",
            "description": "The pricing shape (e.g. `per_unit`, `graduated`, `capped`)."
          },
          "charge_config": {
            "type": "object",
            "description": "The shape's configuration. Amounts are decimal strings in major units."
          },
          "sessions": {
            "type": "array",
            "description": "Optional rolling session windows and alert thresholds.",
            "items": {
              "type": "object",
              "properties": {
                "duration": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "format": "int64"
                },
                "duration_unit": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "alert_threshold": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "description": "Usage total that triggers a `subscription_usage_alert` webhook, as a decimal string."
                }
              }
            }
          }
        }
      },
      "Plan": {
        "type": "object",
        "required": [
          "id",
          "name",
          "sku",
          "created_at",
          "updated_at",
          "frequency",
          "frequency_unit",
          "product_id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "unique identifier for the plan.",
            "examples": [
              "spl_ba_PpkW16oIW"
            ]
          },
          "name": {
            "type": "string",
            "description": "Name of the plan.",
            "examples": [
              "Monthly Subscription"
            ]
          },
          "sku": {
            "type": "string",
            "description": "SKU of the product.",
            "examples": [
              "BOLT-12345"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "examples": [
              "2023-10-01T12:00:00Z"
            ]
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "examples": [
              "2023-10-01T12:00:00Z"
            ]
          },
          "frequency": {
            "type": "integer",
            "format": "int64",
            "description": "The number of `frequency_unit`s between each billing cycle.",
            "examples": [
              1
            ]
          },
          "product_id": {
            "type": "string",
            "description": "ID of the product associated with the plan.",
            "examples": [
              "sp_Tlj0Osm0N76T"
            ]
          },
          "frequency_unit": {
            "type": "string",
            "description": "Unit of frequency (e.g., week, month).",
            "enum": [
              "day",
              "week",
              "month",
              "year"
            ],
            "examples": [
              "month"
            ]
          },
          "initial_period": {
            "type": [
              "object",
              "null"
            ],
            "description": "How long the initial period lasts before we move over to the regular plan.",
            "required": [
              "frequency",
              "frequency_unit"
            ],
            "properties": {
              "frequency": {
                "type": "integer",
                "format": "int64",
                "description": "Number of units the initial period lasts.",
                "examples": [
                  2
                ]
              },
              "frequency_unit": {
                "type": "string",
                "enum": [
                  "day",
                  "week",
                  "month",
                  "year"
                ],
                "description": "Unit of the initial period (e.g. week, month).",
                "examples": [
                  "week"
                ]
              }
            }
          },
          "checkout_link": {
            "type": "string",
            "description": "Checkout link for the plan, when available.",
            "examples": [
              "https://your_site.c.boltapp.com/g?merchant_product_id=37&merchant_variant_id=67&publishable_key=BQ9PKQksUGtj.Q9LwVLfV3WF4.32122926f7b9651a416a5099dc92dc2b4c87c8b922c114229f83b345d65f1195"
            ]
          },
          "base_price": {
            "type": "integer",
            "format": "int64",
            "description": "The plan's recurring charge in cents. `0` for a plan billed purely on usage.",
            "examples": [
              3000
            ]
          },
          "ubb": {
            "type": "boolean",
            "description": "Whether the plan is usage-billed."
          },
          "usage_pricing": {
            "type": "array",
            "description": "One entry per meter a usage-billed plan charges on top of `base_price`. Absent for a flat plan.",
            "items": {
              "$ref": "#/components/schemas/PlanUsagePricing"
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "archived"
            ],
            "description": "The plan's lifecycle status. Catalog divisions only."
          },
          "currency": {
            "type": [
              "string",
              "null"
            ],
            "description": "ISO4217 currency code for `base_price`. Catalog divisions only.",
            "examples": [
              "USD"
            ]
          },
          "trial": {
            "type": [
              "object",
              "null"
            ],
            "description": "The plan's free-trial terms, or `null` when it has none. Catalog divisions only.",
            "properties": {
              "trial_days": {
                "type": "integer",
                "format": "int64",
                "examples": [
                  14
                ]
              }
            }
          },
          "usage": {
            "type": [
              "object",
              "null"
            ],
            "description": "The usage block the plan was written with. Catalog divisions only; absent for a flat plan.",
            "properties": {
              "meter_id": {
                "type": "integer",
                "format": "int64"
              },
              "charge_model": {
                "type": "string"
              },
              "charge_config": {
                "type": "object"
              },
              "sessions": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "duration": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "format": "int64"
                    },
                    "duration_unit": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "alert_threshold": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "PlanUsagePricing": {
        "type": "object",
        "description": "How one meter prices a usage-billed plan's consumption. Amounts inside `charge_config` are decimal strings in the plan currency's major units.",
        "properties": {
          "meter_name": {
            "type": "string",
            "examples": [
              "API Calls"
            ]
          },
          "event_type": {
            "type": "string",
            "examples": [
              "api_call"
            ]
          },
          "aggregation_type": {
            "type": "string",
            "enum": [
              "sum",
              "count"
            ]
          },
          "charge_model": {
            "type": "string",
            "description": "The pricing shape (e.g. `per_unit`, `graduated`, `capped`).",
            "examples": [
              "per_unit"
            ]
          },
          "charge_config": {
            "type": "object",
            "description": "The shape's configuration. Amounts are decimal strings in major units."
          },
          "currency": {
            "type": "string",
            "examples": [
              "USD"
            ]
          }
        }
      },
      "ApiErrorResponse": {
        "type": "object",
        "description": "Standard error envelope returned by every non-2xx response.",
        "required": [
          "result",
          "errors"
        ],
        "properties": {
          "result": {
            "type": "object",
            "properties": {
              "success": {
                "type": "boolean",
                "description": "Always `false` on an error.",
                "examples": [
                  false
                ]
              }
            }
          },
          "errors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        },
        "examples": [
          {
            "result": {
              "success": false
            },
            "errors": [
              {
                "code": 15,
                "message": "A valid value must be provided.",
                "field": "frequency"
              }
            ]
          }
        ]
      },
      "ApiError": {
        "type": "object",
        "description": "One error of a failed request.",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "integer",
            "description": "Bolt error code.",
            "examples": [
              15
            ]
          },
          "message": {
            "type": "string",
            "description": "What went wrong.",
            "examples": [
              "A valid value must be provided."
            ]
          },
          "field": {
            "type": "string",
            "description": "Path of the request field the error is about, such as `product.taxable` or `plans[1].sku`. Absent when the error is not about one field.",
            "examples": [
              "frequency"
            ]
          }
        }
      }
    },
    "securitySchemes": {
      "X-API-Key": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Admins and Developers can obtain their Bolt API key from the Bolt Merchant Dashboard. Send it together with `X-Publishable-Key`."
      },
      "X-Publishable-Key": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Publishable-Key",
        "description": "The publicly viewable identifier used to identify a merchant division. This key is found in the Developer > API section of the Bolt Merchant Dashboard. Required. Send it together with `X-API-Key`."
      }
    }
  }
}
```
