> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.paymentkit.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.paymentkit.com/_mcp/server.

# Add Line Item

POST https://app.paymentkit.com/api/{account_id}/checkout-sessions/{external_id}/line-items
Content-Type: application/json

Add a line item to a checkout session.

Works for both User and API Key authentication.
Account access is automatically validated via endpoint dependency.

Reference: https://docs.paymentkit.com/api-reference/api-reference/checkout-sessions/add-line-item

## Authentication

- `Authorization` header (bearer token, required)

## Servers

- `https://app.paymentkit.com` (Production, default)
- `https://staging.paymentkit.com` (Staging)

## Request

### Path parameters

- `external_id` (string, required)
- `account_id` (string, required)

### Body (application/json)

- `price_id` (string, required) — Price Identifier
- `quantity` (integer, optional, default: 1) — Quantity of items
- `description` (string, optional, nullable) — Line item description

## Response

### 200

Successful Response

- `id` (string, required) — Unique line item identifier
- `product_id` (string, required) — Product Identifier
- `price_id` (string, required) — Price Identifier
- `quantity` (integer, required) — Quantity of items
- `created_at` (datetime, required) — When the line item was created
- `updated_at` (datetime, required) — When the line item was last updated
- `description` (string, optional, nullable) — Line item description

## Examples

**Request**

```json
{
  "price_id": "price_prod_9f8d7c6b"
}
```

**Response**

```json
{
  "id": "csli_prod_9f8d7c6b1a2b",
  "product_id": "product_prod_4e5f6a7b",
  "price_id": "price_prod_9f8d7c6b",
  "quantity": 1,
  "created_at": "2024-04-20T14:45:00Z",
  "updated_at": "2024-04-20T14:45:00Z",
  "description": "Premium subscription plan"
}
```

**SDK Code**

```python
from payment_kit import PaymentKit

client = PaymentKit(
    token="YOUR_TOKEN_HERE",
)

client.checkout_sessions.add_line_item(
    account_id="account_id",
    external_id="external_id",
    price_id="price_prod_9f8d7c6b",
)

```

```javascript
const url = 'https://app.paymentkit.com/api/account_id/checkout-sessions/external_id/line-items';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"price_id":"price_prod_9f8d7c6b"}'
};

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://app.paymentkit.com/api/account_id/checkout-sessions/external_id/line-items"

	payload := strings.NewReader("{\n  \"price_id\": \"price_prod_9f8d7c6b\"\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://app.paymentkit.com/api/account_id/checkout-sessions/external_id/line-items")

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  \"price_id\": \"price_prod_9f8d7c6b\"\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://app.paymentkit.com/api/account_id/checkout-sessions/external_id/line-items")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"price_id\": \"price_prod_9f8d7c6b\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.paymentkit.com/api/account_id/checkout-sessions/external_id/line-items', [
  'body' => '{
  "price_id": "price_prod_9f8d7c6b"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.paymentkit.com/api/account_id/checkout-sessions/external_id/line-items");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"price_id\": \"price_prod_9f8d7c6b\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["price_id": "price_prod_9f8d7c6b"] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.paymentkit.com/api/account_id/checkout-sessions/external_id/line-items")! 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()
```