> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XStoreGetUserCollectionsIdAsync

> XStoreGetUserCollectionsIdAsync

# XStoreGetUserCollectionsIdAsync

Gets a customer collections ID.  This ID can then be used to validate a user's entitlement from your own service with a B2B call.  This API is used in the flow outlined in [Manage products from your services](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav).

## Syntax

```cpp theme={null}
HRESULT XStoreGetUserCollectionsIdAsync(  
         const XStoreContextHandle storeContextHandle,  
         const char* serviceTicket,  
         const char* publisherUserId,  
         XAsyncBlock* async  
)  
```

### Parameters

*storeContextHandle*   \_In\_\
Type: XStoreContextHandle

The store context handle for the user returned by [XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext).

*serviceTicket*   \_In\_z\_\
Type: char\*

An Azure ticket that can be used by the back end service to authorize the user and service. This lets you get a ticket back from the service, that you can relay to your own servers. Then your server can store this and use it for B2B calls to either check ownership or grant access.

*publisherUserId*   \_In\_z\_\
Type: char\*

A string generated by the developer meant to identify the current user as a member or guest of a service which belongs to the game, the developer, or publisher. The contents of this string are determined by the developer and may be left blank.

*async*   \_Inout\_\
Type: [XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

An [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) defining the asynchronous work being done. The [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) can be used to poll for the call's status and retrieve call results. See [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) for more information.

### Return value

Type: HRESULT

HRESULT success or error code.

## Remarks

On PC this API will return info for the user currently signed into the store and not necessarily the user playing your game if XBOX services is enabled. If your title is on the XBOX console or XBOX services enabled on the PC, we recommend doing B2B calls to the collections and license preview endpoints using XSTS delegated authorization to ensure you are checking entitlements for the active playing user.

To retrieve the user's collection ID as well as the execution result of this function call [XStoreGetUserCollectionsIdResult](/reference/system/xstore/functions/xstoregetusercollectionsidresult) after calling this function. To retrieve the size of the user's collection ID call [XStoreGetUserCollectionsIdResultSize](/reference/system/xstore/functions/xstoregetusercollectionsidresultsize). Knowing the size of the result will allow you to retrieve it more efficiently.

The following code snippet shows an example of retrieving a customer collections ID.

```cpp theme={null}
void CALLBACK GetUserCollectionsIdCallback(XAsyncBlock* asyncBlock)
{
    size_t size;
    HRESULT hr = XStoreGetUserCollectionsIdResultSize(
        asyncBlock,
        &size);

    if (FAILED(hr))
    {
        printf("Failed retrieve the user collection ID size: 0x%x\r\n", hr);
        return;
    }

    char* result = new char[size];
    hr = XStoreGetUserCollectionsIdResult(
        asyncBlock,
        size,
        result);

    if (FAILED(hr))
    {
        printf("Failed retrieve the user collection ID result: 0x%x\r\n", hr);
        delete[] result;
        return;
    }

    printf("result: %s\r\n", result);

    delete[] result;
}

void GetUserCollectionsId(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char* serviceTicket, const char* publisherUserId)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = GetUserCollectionsIdCallback;

    HRESULT hr = XStoreGetUserCollectionsIdAsync(
        storeContextHandle,
        serviceTicket,
        publisherUserId,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to get user collections ID: 0x%x\r\n", hr);
        return;
    }
}
```

## Requirements

**Header:** XStore.h (included in XGameRuntime.h)

**Library:** xgameruntime.lib

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## Conceptual documentation

* [Requesting a User Store ID for service-to-service authentication](/publishing/xstore-commerce/xstore-requesting-userstoreid)

## See also

[XStore](/reference/system/xstore/xstore_members)\
[XStoreGetUserCollectionsIdResult](/reference/system/xstore/functions/xstoregetusercollectionsidresult)\
[Manage products from your services](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)


## Related topics

- [XStoreGetUserCollectionsIdResult](/reference/system/xstore/functions/xstoregetusercollectionsidresult.md)
- [XStoreGetUserCollectionsIdResultSize](/reference/system/xstore/functions/xstoregetusercollectionsidresultsize.md)
- [Request a User Store ID for service-to-service auth](/publishing/xstore-commerce/xstore-requesting-userstoreid.md)
- [XStore commerce overview](/publishing/xstore-commerce/xstore-commerce-overview.md)
- [XStore](/reference/system/xstore/xstore_members.md)
