> 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/unity-engine/examples/using-headlessapi-directly-advanced.md).

# Using HeadlessAPI directly (advanced)

If you need basket operations outside of the pre-built components, we provide all mappings for **HeadlessAPI** and **PluginAPI**. See their dedicated sections for more details.

```csharp
using Tebex.Headless;
using UnityEngine;

public class CustomStoreFlow : MonoBehaviour
{
    HeadlessApi api;

    async void Start()
    {
        api = HeadlessApi.GetInstance(new UnityHeadlessAdapter(), "your-public-token");

        // Fetch all categories with their packages
        await api.GetAllCategoriesIncludingPackagesAsync(
            onSuccess: categories =>
            {
                foreach (var cat in categories)
                    Debug.Log($"{cat.name}: {cat.packages.Count} packages");
            },
            onApiError: err => Debug.LogError($"API Error: {err.detail}"),
            onServerError: err => Debug.LogError($"Server Error {err.Code}: {err.Body}")
        );

        // Create a basket for a player
        var payload = new CreateBasketPayload
        {
            username = "PlayerOne",
            complete_url = "https://yoursite.com/thanks",
            cancel_url = "https://yoursite.com/store"
        };

        await api.CreateBasketAsync(
            payload: payload,
            onSuccess: basket =>
            {
                Debug.Log($"Basket created: {basket.ident}");
                Debug.Log($"Checkout: {basket.links.checkout}");
            },
            onApiError: err => Debug.LogError(err.detail),
            onServerError: err => Debug.LogError(err.Body)
        );
    }
}
```
