> 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)
        );
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tebex.io/developers/unity-engine/examples/using-headlessapi-directly-advanced.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
