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.

Syntax

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.

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*

An XAsyncBlock defining the asynchronous work being done. The XAsyncBlock can be used to poll for the call's status and retrieve call results. See 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 after calling this function. To retrieve the size of the user's collection ID call 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.

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->context = 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;
    }

    // Wait a while for the callbacks to run
    Sleep(5000);
}

Requirements

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

Library: xgameruntime.lib

Supported platforms: Windows, Xbox One family consoles and Xbox Series consoles

See also

XStore
XStoreGetUserCollectionsIdResult
Manage products from your services