> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.afternoon.co/llms.txt.
> For full documentation content, see https://docs.afternoon.co/llms-full.txt.

# Create a subscription signup link

POST https://api.afternoon.co/v1/subscription-signup-links
Content-Type: application/json

Generates a tokenised signup link that allows a specific customer to subscribe to a plan. Use `plan_code` to identify the plan. The returned token can be appended to your subscribe page URL (e.g. /subscribe/{token}). The token expires after 24 hours.

Reference: https://docs.afternoon.co/api-reference/afternoon-events-api/subscription-signup-links/create

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Afternoon Events API
  version: 1.0.0
paths:
  /v1/subscription-signup-links:
    post:
      operationId: create
      summary: Create a subscription signup link
      description: >-
        Generates a tokenised signup link that allows a specific customer to
        subscribe to a plan. Use `plan_code` to identify the plan. The returned
        token can be appended to your subscribe page URL (e.g.
        /subscribe/{token}). The token expires after 24 hours.
      tags:
        - subpackage_subscriptionSignupLinks
      parameters:
        - name: Authorization
          in: header
          description: API key obtained from the Afternoon dashboard
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Signup link created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubscriptionSignupLinkResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Subscription Signup Link not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSubscriptionSignupLinkRequest'
servers:
  - url: https://api.afternoon.co
  - url: http://localhost:8787
components:
  schemas:
    CreateSubscriptionSignupLinkRequestChangeTimingMode:
      type: string
      enum:
        - now
        - end_of_period
      description: >-
        Required when previous_subscription_id is provided. Use "now" or
        "end_of_period".
      title: CreateSubscriptionSignupLinkRequestChangeTimingMode
    CreateSubscriptionSignupLinkRequestCancelNowPrepaidRefundPolicy:
      type: string
      enum:
        - no_refund_prepaid_fixed_fees
        - refund_prorated_prepaid_fixed_fees
      description: >-
        Only allowed when change_timing_mode is "now". Controls prepaid
        fixed-fee refunds.
      title: CreateSubscriptionSignupLinkRequestCancelNowPrepaidRefundPolicy
    CreateSubscriptionSignupLinkRequest:
      type: object
      properties:
        customer_id:
          type: string
          format: cuid
          description: Customer ID
        plan_code:
          type: string
          description: Plan code
        success_url:
          type: string
          format: uri
          description: URL to redirect to after successful signup
        back_url:
          type: string
          format: uri
          description: URL to go back to when customer clicks Back
        previous_subscription_id:
          type: string
          format: cuid
          description: >-
            Existing subscription ID to change from. If omitted, link creates a
            new subscription.
        change_timing_mode:
          $ref: >-
            #/components/schemas/CreateSubscriptionSignupLinkRequestChangeTimingMode
          description: >-
            Required when previous_subscription_id is provided. Use "now" or
            "end_of_period".
        cancel_now_prepaid_refund_policy:
          $ref: >-
            #/components/schemas/CreateSubscriptionSignupLinkRequestCancelNowPrepaidRefundPolicy
          description: >-
            Only allowed when change_timing_mode is "now". Controls prepaid
            fixed-fee refunds.
      required:
        - customer_id
        - plan_code
      title: CreateSubscriptionSignupLinkRequest
    SubscriptionSignupLink:
      type: object
      properties:
        id:
          type: string
        customer_id:
          type: string
        plan_id:
          type: string
        plan_code:
          type:
            - string
            - 'null'
          description: Human-readable plan code
        url:
          type: string
          description: >-
            Full subscribe page URL for the customer. Share this link with the
            customer to allow them to sign up for the plan.
        token_expiration:
          type: string
          description: ISO 8601 expiration timestamp for the token
        success_url:
          type:
            - string
            - 'null'
          description: URL to redirect to after successful signup
        back_url:
          type:
            - string
            - 'null'
          description: URL to go back to when customer clicks Back
        previous_subscription_id:
          type:
            - string
            - 'null'
          description: >-
            Existing subscription to change from. When provided, the checkout
            flow updates this subscription to the target plan instead of
            creating a net-new subscription.
        change_timing_mode:
          type:
            - string
            - 'null'
          description: >-
            Plan-change timing mode. "now" changes immediately. "end_of_period"
            schedules a transition at period end.
        cancel_now_prepaid_refund_policy:
          type:
            - string
            - 'null'
          description: >-
            When `change_timing_mode` is "now", controls how prepaid fixed fees
            are handled.
        created_at:
          type: string
          description: ISO 8601 creation timestamp
      required:
        - id
        - customer_id
        - plan_id
        - plan_code
        - url
        - token_expiration
        - success_url
        - back_url
        - previous_subscription_id
        - change_timing_mode
        - cancel_now_prepaid_refund_policy
        - created_at
      title: SubscriptionSignupLink
    SubscriptionSignupLinkResponse:
      type: object
      properties:
        success:
          type: boolean
        subscription_signup_link:
          $ref: '#/components/schemas/SubscriptionSignupLink'
        request_id:
          type: string
      required:
        - success
        - subscription_signup_link
        - request_id
      title: SubscriptionSignupLinkResponse
    ErrorResponseError:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
        details:
          oneOf:
            - description: Any type
            - type: 'null'
      required:
        - code
        - message
      title: ErrorResponseError
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
        error:
          $ref: '#/components/schemas/ErrorResponseError'
        request_id:
          type: string
          description: Request ID for tracing
      required:
        - success
        - error
      title: ErrorResponse
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key obtained from the Afternoon dashboard

```

## SDK Code Examples

```typescript
import { AfternoonClient } from "afternoon-sdk";

async function main() {
    const client = new AfternoonClient({
        token: "YOUR_TOKEN_HERE",
    });
    await client.subscriptionSignupLinks.create({
        customerId: "cm5x9z8nv0001h85r7l9p2k2m",
        planCode: "starter_plan",
    });
}
main();

```

```python
import requests

url = "https://api.afternoon.co/v1/subscription-signup-links"

payload = {
    "customer_id": "cm5x9z8nv0001h85r7l9p2k2m",
    "plan_code": "starter_plan"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```go
package main

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

func main() {

	url := "https://api.afternoon.co/v1/subscription-signup-links"

	payload := strings.NewReader("{\n  \"customer_id\": \"cm5x9z8nv0001h85r7l9p2k2m\",\n  \"plan_code\": \"starter_plan\"\n}")

	req, _ := http.NewRequest("POST", 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.afternoon.co/v1/subscription-signup-links")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"customer_id\": \"cm5x9z8nv0001h85r7l9p2k2m\",\n  \"plan_code\": \"starter_plan\"\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.post("https://api.afternoon.co/v1/subscription-signup-links")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"customer_id\": \"cm5x9z8nv0001h85r7l9p2k2m\",\n  \"plan_code\": \"starter_plan\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.afternoon.co/v1/subscription-signup-links', [
  'body' => '{
  "customer_id": "cm5x9z8nv0001h85r7l9p2k2m",
  "plan_code": "starter_plan"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.afternoon.co/v1/subscription-signup-links");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"customer_id\": \"cm5x9z8nv0001h85r7l9p2k2m\",\n  \"plan_code\": \"starter_plan\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "customer_id": "cm5x9z8nv0001h85r7l9p2k2m",
  "plan_code": "starter_plan"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.afternoon.co/v1/subscription-signup-links")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
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()
```