# Create plugin subscription

`POST /api/plugins/{pluginId}/subscriptions`

Authentication: no security requirement declared for this operation.

Parameters:

- `pluginId` (path, string, uuid, required) - Plugin ID
  Type: string, uuid

Request body: application/json (required)

Type: object

Schema: [PurchasePluginSubscriptionDTO](https://sourcey-gauzy.pages.dev/api-reference/models/purchasepluginsubscriptiondto/index.md)

- `pluginId` (required)
  Type: string
  
  Plugin ID

- `planId` (optional)
  Type: string
  
  Plan ID

- `scope` (required)
  Type: string
  
  Subscription scope
  
  enum: ["tenant","organization","user"]

- `autoRenew` (required)
  Type: boolean
  
  Auto-renewal enabled

- `paymentMethod` (optional)
  Type: string
  
  Payment method

- `promoCode` (optional)
  Type: string
  
  Promo code

- `metadata` (optional)
  Type: object
  
  Additional metadata

Responses:

- 201: Plugin subscription created successfully

Content type: application/json

Type: object

Schema: [PluginSubscription_1](https://sourcey-gauzy.pages.dev/api-reference/models/pluginsubscription-1/index.md)

- `deletedAt` (optional)
  Type: string, date-time
  
  Example:
  
  ```json
  "2018-11-21T06:20:32.232Z"
  ```

- `createdAt` (optional)
  Type: string, date-time
  
  The creation timestamp of the entity.
  
  Example:
  
  ```json
  "2018-11-21T06:20:32.232Z"
  ```

- `updatedAt` (optional)
  Type: string, date-time
  
  The last update timestamp of the entity.
  
  Example:
  
  ```json
  "2018-11-21T06:20:32.232Z"
  ```

- `id` (optional)
  Type: string

- `isActive` (optional)
  Type: boolean
  
  default: true

- `isArchived` (optional)
  Type: boolean
  
  default: false

- `archivedAt` (optional)
  Type: string, date-time
  
  Example:
  
  ```json
  "2018-11-21T06:20:32.232Z"
  ```

- `tenantId` (optional)
  Type: string

- `organizationId` (optional)
  Type: string

- `status` (required)
  Type: string
  
  Subscription status
  
  enum: ["active","cancelled","expired","trial","past_due","suspended","pending"]

- `scope` (required)
  Type: string
  
  Subscription scope
  
  enum: ["tenant","organization","user"]

- `startDate` (required)
  Type: string, date-time
  
  Start date of subscription

- `endDate` (optional)
  Type: string, date-time
  
  End date of subscription

- `trialEndDate` (optional)
  Type: string, date-time
  
  Trial end date

- `autoRenew` (required)
  Type: boolean
  
  Whether auto-renewal is enabled

- `cancelledAt` (optional)
  Type: string, date-time
  
  Cancellation date

- `cancellationReason` (optional)
  Type: string
  
  Cancellation reason

- `metadata` (optional)
  Type: object
  
  Subscription metadata for additional data

- `externalSubscriptionId` (optional)
  Type: string
  
  External subscription ID from payment provider

- `pluginId` (required)
  Type: string
  
  Plugin ID

- `pluginTenantId` (required)
  Type: string
  
  Plugin Tenant ID

- `planId` (optional)
  Type: string
  
  Subscription plan ID

- `subscriberId` (optional)
  Type: string
  
  Subscriber user ID for user-specific subscriptions

- `parentId` (optional)
  Type: string
  
  Parent subscription ID for hierarchical subscriptions

- `parent` (optional)
  Type: unknown
  
  Parent subscription (for subscriptions created through assignment)
  
  allOf:
    Reference: [PluginSubscription_1](https://sourcey-gauzy.pages.dev/api-reference/models/pluginsubscription-1/index.md); Type: PluginSubscription_1

- `children` (optional)
  Type: array
  
  Child subscriptions (user subscriptions created through assignment)
  
  Items:
    Reference: [PluginSubscription_1](https://sourcey-gauzy.pages.dev/api-reference/models/pluginsubscription-1/index.md); Type: PluginSubscription_1

- `billings` (optional)
  Type: array
  
  Plugin billings for this subscription
  
  Items:
    Type: string

## Examples

### cURL

```bash
curl -X POST 'http://localhost:3000/api/plugins/550e8400-e29b-41d4-a716-446655440000/subscriptions' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "pluginId": "string",
  "planId": "string",
  "scope": "tenant",
  "autoRenew": true,
  "paymentMethod": "string",
  "promoCode": "string",
  "metadata": {}
}'
```

### JavaScript

```javascript
const body = `{
  "pluginId": "string",
  "planId": "string",
  "scope": "tenant",
  "autoRenew": true,
  "paymentMethod": "string",
  "promoCode": "string",
  "metadata": {}
}`;

const response = await fetch('http://localhost:3000/api/plugins/550e8400-e29b-41d4-a716-446655440000/subscriptions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "pluginId": "string",
  "planId": "string",
  "scope": "tenant",
  "autoRenew": true,
  "paymentMethod": "string",
  "promoCode": "string",
  "metadata": {}
}'''

response = requests.post(
    'http://localhost:3000/api/plugins/550e8400-e29b-41d4-a716-446655440000/subscriptions',
    data=body.encode('utf-8'),
    headers={
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
