For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see https://docs.prolifi.io/endpoints/subscriptions/llms.txt. For full documentation content, see https://docs.prolifi.io/endpoints/subscriptions/llms-full.txt.

# Cancel a subscription

DELETE https://api.prolifi.co/api/v1/public/subscriptions/{id}
Content-Type: application/json

Cancels a subscription. By default, the subscription continues until the end of the current billing period. Set `cancel_at` to `"immediately"` for immediate cancellation.


Reference: https://docs.prolifi.io/endpoints/subscriptions/cancel-subscription

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Prolifi Public API
  version: 1.0.0
paths:
  /subscriptions/{id}:
    delete:
      operationId: cancel-subscription
      summary: Cancel a subscription
      description: >
        Cancels a subscription. By default, the subscription continues until the
        end of the current billing period. Set `cancel_at` to `"immediately"`
        for immediate cancellation.
      tags:
        - subpackage_subscriptions
      parameters:
        - name: id
          in: path
          description: The unique identifier of the subscription.
          required: true
          schema:
            type: string
            format: uuid
        - name: Authorization
          in: header
          description: >
            Use a secret key (`sk_test_*` or `sk_live_*`) for full read/write
            access, or a public key (`pk_test_*` or `pk_live_*`) for read-only
            access.
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Subscription cancelled successfully
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/Subscriptions_cancelSubscription_Response_200
        '401':
          description: Authentication failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CancelSubscriptionRequest'
servers:
  - url: https://api.prolifi.co/api/v1/public
  - url: https://sandbox.prolifi.co/api/v1/public
components:
  schemas:
    CancelSubscriptionRequestCancelAt:
      type: string
      enum:
        - end_of_period
        - immediately
      default: end_of_period
      description: When the cancellation takes effect.
      title: CancelSubscriptionRequestCancelAt
    CancelSubscriptionRequest:
      type: object
      properties:
        cancel_at:
          $ref: '#/components/schemas/CancelSubscriptionRequestCancelAt'
          description: When the cancellation takes effect.
        reason:
          type:
            - string
            - 'null'
          description: Cancellation reason (for records and analytics).
      title: CancelSubscriptionRequest
    SubscriptionStatus:
      type: string
      enum:
        - active
        - cancelled
        - paused
        - pending
        - expired
      title: SubscriptionStatus
    SubscriptionPricing:
      type: object
      properties:
        amount:
          type:
            - number
            - 'null'
          format: double
          description: Subscription amount in minor units.
        currency:
          type:
            - string
            - 'null'
          description: ISO 4217 currency code.
        pricing_scheme_id:
          type:
            - string
            - 'null'
          format: uuid
      title: SubscriptionPricing
    SubscriptionMetadata:
      type: object
      properties: {}
      title: SubscriptionMetadata
    Subscription:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Unique identifier.
        customer_id:
          type: string
          format: uuid
        plan_id:
          type: string
          format: uuid
          description: The plan (product) this subscription is for.
        plan_name:
          type:
            - string
            - 'null'
        status:
          $ref: '#/components/schemas/SubscriptionStatus'
        billing_cycle:
          type:
            - string
            - 'null'
          description: Current billing cycle name (e.g., monthly, yearly).
        current_period_start:
          type:
            - string
            - 'null'
          format: date
        current_period_end:
          type:
            - string
            - 'null'
          format: date
        start_date:
          type:
            - string
            - 'null'
          format: date
        billing_date:
          type:
            - string
            - 'null'
          format: date
        cancel_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When the subscription is scheduled to cancel.
        canceled_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When the subscription was cancelled.
        pause_start:
          type:
            - string
            - 'null'
          format: date-time
        pause_end:
          type:
            - string
            - 'null'
          format: date-time
        pricing:
          $ref: '#/components/schemas/SubscriptionPricing'
        metadata:
          oneOf:
            - $ref: '#/components/schemas/SubscriptionMetadata'
            - type: 'null'
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      title: Subscription
    Subscriptions_cancelSubscription_Response_200:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/Subscription'
      title: Subscriptions_cancelSubscription_Response_200
    ErrorResponseErrorType:
      type: string
      enum:
        - authentication_error
        - permission_error
        - validation_error
        - not_found
        - invalid_request
        - rate_limit_error
        - ip_restricted
        - conflict
        - api_error
      description: Machine-readable error type.
      title: ErrorResponseErrorType
    ErrorResponseErrorErrorsItems:
      type: object
      properties:
        field:
          type: string
          description: The field that failed validation.
        message:
          type: string
          description: The validation error message.
      title: ErrorResponseErrorErrorsItems
    ErrorResponseError:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/ErrorResponseErrorType'
          description: Machine-readable error type.
        message:
          type: string
          description: Human-readable error description.
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ErrorResponseErrorErrorsItems'
          description: >-
            Field-level validation errors (only present for `validation_error`
            type).
      required:
        - type
        - message
      title: ErrorResponseError
    ErrorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/ErrorResponseError'
      title: ErrorResponse
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >
        Use a secret key (`sk_test_*` or `sk_live_*`) for full read/write
        access, or a public key (`pk_test_*` or `pk_live_*`) for read-only
        access.

```

## SDK Code Examples

```python Cancel immediately
import requests

url = "https://api.prolifi.co/api/v1/public/subscriptions/id"

payload = {
    "cancel_at": "immediately",
    "reason": "Duplicate subscription"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.delete(url, json=payload, headers=headers)

print(response.json())
```

```javascript Cancel immediately
const url = 'https://api.prolifi.co/api/v1/public/subscriptions/id';
const options = {
  method: 'DELETE',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"cancel_at":"immediately","reason":"Duplicate subscription"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Cancel immediately
package main

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

func main() {

	url := "https://api.prolifi.co/api/v1/public/subscriptions/id"

	payload := strings.NewReader("{\n  \"cancel_at\": \"immediately\",\n  \"reason\": \"Duplicate subscription\"\n}")

	req, _ := http.NewRequest("DELETE", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Cancel immediately
require 'uri'
require 'net/http'

url = URI("https://api.prolifi.co/api/v1/public/subscriptions/id")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Delete.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"cancel_at\": \"immediately\",\n  \"reason\": \"Duplicate subscription\"\n}"

response = http.request(request)
puts response.read_body
```

```java Cancel immediately
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.delete("https://api.prolifi.co/api/v1/public/subscriptions/id")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"cancel_at\": \"immediately\",\n  \"reason\": \"Duplicate subscription\"\n}")
  .asString();
```

```php Cancel immediately
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('DELETE', 'https://api.prolifi.co/api/v1/public/subscriptions/id', [
  'body' => '{
  "cancel_at": "immediately",
  "reason": "Duplicate subscription"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Cancel immediately
using RestSharp;

var client = new RestClient("https://api.prolifi.co/api/v1/public/subscriptions/id");
var request = new RestRequest(Method.DELETE);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"cancel_at\": \"immediately\",\n  \"reason\": \"Duplicate subscription\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Cancel immediately
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "cancel_at": "immediately",
  "reason": "Duplicate subscription"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.prolifi.co/api/v1/public/subscriptions/id")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "DELETE"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

```python
import requests

url = "https://api.prolifi.co/api/v1/public/subscriptions/id"

payload = {
    "cancel_at": "end_of_period",
    "reason": "Customer no longer needs the service"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.delete(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.prolifi.co/api/v1/public/subscriptions/id';
const options = {
  method: 'DELETE',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"cancel_at":"end_of_period","reason":"Customer no longer needs the service"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.prolifi.co/api/v1/public/subscriptions/id"

	payload := strings.NewReader("{\n  \"cancel_at\": \"end_of_period\",\n  \"reason\": \"Customer no longer needs the service\"\n}")

	req, _ := http.NewRequest("DELETE", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.prolifi.co/api/v1/public/subscriptions/id")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Delete.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"cancel_at\": \"end_of_period\",\n  \"reason\": \"Customer no longer needs the service\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.delete("https://api.prolifi.co/api/v1/public/subscriptions/id")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"cancel_at\": \"end_of_period\",\n  \"reason\": \"Customer no longer needs the service\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('DELETE', 'https://api.prolifi.co/api/v1/public/subscriptions/id', [
  'body' => '{
  "cancel_at": "end_of_period",
  "reason": "Customer no longer needs the service"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.prolifi.co/api/v1/public/subscriptions/id");
var request = new RestRequest(Method.DELETE);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"cancel_at\": \"end_of_period\",\n  \"reason\": \"Customer no longer needs the service\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "cancel_at": "end_of_period",
  "reason": "Customer no longer needs the service"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.prolifi.co/api/v1/public/subscriptions/id")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "DELETE"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```