> For the complete documentation index, see [llms.txt](https://docs.tebex.io/developers/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tebex.io/developers/headless-api/guides/baskets/create-a-basket.md). Agents can also search and read this documentation through its [MCP server](https://docs.tebex.io/developers/~gitbook/mcp).

# Create a Basket

For most stores, you can create a basket without any required parameters. For certain store types you may need to provide additional information.

### Backend Servers

{% hint style="warning" %}
If you are creating a basket on your backend server, you must provide an `ip_address`  on creation, otherwise the basket will be incorrectly attributed to your server's IP.
{% endhint %}

It is **required** to provide the customer's real IP address if a basket is created by your server.

### Minecraft and Overwolf Stores

You must provide the `username` parameter as part of the basket creation request so that the basket is attributed to the correct user.

The returned basket will contain a `username_id` which can safely be added to the user's session. It is required for use with certain endpoints across Tebex APIs.

### Universal Stores

No `username` is required for your basket. Depending on your package **Deliverables** you may need to provide `variable_data` per each Package so that it is attributed to the correct user. See [Add Package to Basket](https://docs.tebex.io/developers/headless-api/guides/baskets/add-package-to-basket.md).

```json
{
  "complete_url": "https://example.tebex.io/thank-you",
  "cancel_url": "https://tebex.io/",
  "custom": {
    "foo": "bar"
  },
  "complete_auto_redirect": true,
  "ip_address": "127.0.0.1"
}
```

## Create a new basket

> Creates a new basket for use during checkout.

```json
{"openapi":"3.1.0","info":{"title":"Tebex Headless API","version":"2.1.0"},"tags":[{"description":"Main API scoped to public token","name":"Headless"}],"servers":[{"description":"Main API scoped to public token","url":"https://headless.tebex.io/api/accounts/{token}","variables":{"token":{"default":"YOUR_PUBLIC_TOKEN","description":"The store's public token"}}}],"paths":{"/baskets":{"post":{"description":"Creates a new basket for use during checkout.","operationId":"createBasket","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/createBasket_request"}}}},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BasketResponse"}}},"description":"Successful response returns the basket information."},"422":{"description":"The provided webstore ID is invalid."}},"summary":"Create a new basket","tags":["Headless"]}}},"components":{"schemas":{"createBasket_request":{"properties":{"username":{"description":"The username of the player the basket is being created for.","maxLength":255,"type":"string","nullable":true},"username_id":{"description":"The platform ID of the player the basket is being created for. Requires basic authentication (private key).","type":"string","nullable":true},"email":{"description":"The email address to associate with the basket.","format":"email","type":"string","nullable":true},"email_immutable":{"description":"If true, the user will not be able to change the email address during checkout.","type":"boolean","nullable":true},"ip_address":{"description":"The IP address of the user the basket is being created for. Must be a valid IPv4 or IPv6 address. Requires basic authentication (private key).","type":"string","nullable":true},"complete_url":{"description":"A URL the user can return to when checkout is completed.","type":"string"},"cancel_url":{"description":"A URL the user can return to when cancelling checkout.","type":"string"},"custom":{"description":"Custom data you wish to associate with the basket. This data will be included with webhook responses and GET requests associated with the Basket.","type":"object"},"complete_auto_redirect":{"description":"True if the user should automatically be redirected to the relevant complete/cancel URL","type":"boolean"}}},"BasketResponse":{"properties":{"data":{"$ref":"#/components/schemas/Basket"}}},"Basket":{"properties":{"id":{"type":"string"},"ident":{"type":"string"},"complete":{"type":"boolean"},"email":{"type":"string","nullable":true},"username":{"type":"string","nullable":true},"coupons":{"items":{"$ref":"#/components/schemas/Coupon"},"type":"array"},"giftcards":{"items":{"$ref":"#/components/schemas/GiftCard"},"type":"array"},"creator_code":{"description":"The creator code is used to share a percentage of the payment with another party. See more about creator codes at https://docs.tebex.io/creators/tebex-control-panel/engagement/creator-codes","type":"string"},"cancel_url":{"type":"string"},"complete_url":{"type":"string","nullable":true},"complete_auto_redirect":{"type":"boolean"},"country":{"description":"A two-character country code","type":"string"},"ip":{"type":"string"},"username_id":{"type":"integer"},"base_price":{"format":"float","type":"number"},"sales_tax":{"format":"float","type":"number"},"total_price":{"format":"float","type":"number"},"currency":{"description":"A 3 character currency code","type":"string"},"packages":{"items":{"$ref":"#/components/schemas/BasketPackage"},"type":"array"},"custom":{"type":"object","nullable":true},"links":{"$ref":"#/components/schemas/BasketLinks"}}},"Coupon":{"properties":{"code":{"type":"string"}}},"GiftCard":{"properties":{"card_number":{"type":"string"}}},"BasketPackage":{"description":"A package within an existing basket.","properties":{"id":{"description":"The package ID","type":"integer"},"description":{"type":"string"},"image":{"type":"string"},"name":{"type":"string"},"slug":{"type":"string"},"in_basket":{"$ref":"#/components/schemas/BasketPackage_in_basket"},"type":{"description":"The type of payment, either `single` for one-time payments or `subscription`.","enum":["single","subscription"],"type":"string"},"revenue_share":{"description":"An array of payment destination objects describing how the purchase should be split between multiple wallets. **Only available with pre-agreement from Tebex.**","items":{"$ref":"#/components/schemas/RevenueShare"},"type":"array"},"is_recurring":{"description":"Whether this package is a recurring (subscription) purchase.","type":"boolean"}}},"BasketPackage_in_basket":{"properties":{"quantity":{"description":"The quantity of `package` in this basket. This is not the total quantity of overall items in the basket.","type":"integer"},"price":{"format":"float","type":"number"},"gift_username_id":{"description":"The username id of the user this package is gifted to","type":"string"},"gift_username":{"description":"The username of the user this package is gifted to.","type":"string"}}},"RevenueShare":{"properties":{"wallet_ref":{"type":"string"},"amount":{"description":"A float (decimal) value representing the amount of this payment in your account currency that is credited to the `wallet_ref`","type":"number"},"gateway_fee_percent":{"description":"A float (decimal) value representing the percentage of the gateway fee that should be dedicated from this wallet’s revenue share. This optional value can be anywhere between 0 - 100.","type":"number"}}},"BasketLinks":{"properties":{"payment":{"description":"The `links.payment` property is only returned if the basket has been paid for and a payment exists with the `complete`,`refund`, or `chargeback` status.","type":"string"},"checkout":{"description":"The `links.checkout` property is only returned if the basket has not been paid, and is the URL to send the customer to make payment","type":"string"}}}}}}
```
