> ## 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.

# Using publisher data

> Share configuration and player key-value data across multiple titles in a PlayFab studio using SetPublisherData, GetPublisherData, and related APIs.

This tutorial describes how to create and use namespace-scoped data through the Publisher data APIs.

Publisher data is static data that spans more than one title in a PlayFab namespace, such as when multiple games need to share common information. **Publisher** is the older API term for the namespace scope, and the Publisher ID identifies the namespace. A namespace is distinct from a studio, which is the administrative grouping for titles, users, permissions, and billing. For more information, see [PlayFab concepts](/services/playfab/get-started/concepts#studios-namespaces-and-titles).

<Note>
  This category also includes data for players that spans multiple games. PlayFab stores data as Key/Value Pairs (KVPs).
</Note>

Most of these APIs are server APIs that your program must call from a dedicated server, or through a CloudScript function within the PlayFab service.

* Use the server APIs **[SetPublisherData](xref:titleid.playfabapi.com.server.title-widedatamanagement.setpublisherdata)** to update, and **[GetPublisherData](xref:titleid.playfabapi.com.server.title-widedatamanagement.getpublisherdata)** to retrieve, Publisher-specific custom KVPs.
* Use **[UpdateUserPublisherData](xref:titleid.playfabapi.com.client.playerdatamanagement.updateuserpublisherdata)** to create or update, and **[GetUserPublisherData](xref:titleid.playfabapi.com.client.playerdatamanagement.getuserpublisherdata)** to retrieve, Publisher-specific custom KVPs for the player.
* Use the server API **[UpdateUserPublisherReadOnlyData](xref:titleid.playfabapi.com.server.playerdatamanagement.updateuserpublisherreadonlydata)** to update, and the client API **[GetUserPublisherReadOnlyData](xref:titleid.playfabapi.com.client.playerdatamanagement.getuserpublisherreadonlydata)** to retrieve, the read-only Publisher-specific custom KVPs for the user.
* Use the server APIs **[UpdateUserPublisherInternalData](xref:titleid.playfabapi.com.server.playerdatamanagement.updateuserpublisherinternaldata)** to update, and **[GetUserPublisherInternalData](xref:titleid.playfabapi.com.server.playerdatamanagement.getuserpublisherinternaldata)** to retrieve, the internal Publisher-specific custom KVPs for the user.

You must call the server APIs from a dedicated server or through a CloudScript function through the PlayFab service. This is by design, as the PlayFab server APIs require that you supply your secret key.

<Tip>
  We *do not recommend* using server APIs from within a game client. If you need to make use of a server API, use CloudScript for this type of functionality.
</Tip>

Publisher data values are copied and distributed to potentially *hundreds* of machines in the PlayFab cluster server. As part of this process, this data is cached and changes may take up to *fifteen minutes* to refresh in those caches.

<Note>
  Publisher data is best suited for *global constant/static data* and *isn't* suitable or reliable as *global variables*.
</Note>

## Publisher data

Publisher data is used to store static data for the titles in a namespace. Each entry *isn't bound* to a player entity (as opposed to [user publisher data](#user-publisher-data)).

### Setting Publisher data

The following snippet demonstrates how to set Publisher data using the Server API.

<Note>
  There is an admin API counterpart for this operation.
</Note>

```csharp theme={null}
public void ServerSetPublisherData() {
    PlayFabServerAPI.SetPublisherData(new SetPublisherDataRequest() {
            Key = "SomeKey",
            Value = "SomeValue"
        },
        result => Debug.Log("Complete setting publisher data"),
        error => {
            Debug.Log("Got error setting publisher data");
            Debug.Log(error.GenerateErrorReport());
        }
    );
}
```

### Getting Publisher data

The following snippet demonstrates getting Publisher data using the Client API.

<Note>
  There are server and admin API counterparts for this operation.
</Note>

```csharp theme={null}
public void ClientGetPublisherData() {
    PlayFabClientAPI.GetPublisherData(new GetPublisherDataRequest(),
    result => {
        if (result.Data == null || !result.Data.ContainsKey("SomeKey")) Debug.Log("No SomeKey");
        else Debug.Log("SomeKey: " + result.Data["SomeKey"]);
    },
    error => {
        Debug.Log("Got error getting publisher data");
        Debug.Log(error.GenerateErrorReport());
    });
}
```

## User Publisher data

User Publisher data can be used to introduce Publisher data that is bound to a PlayFab user (player).

Unlike regular Publisher data, it is possible for a Client application to alter user Publisher data.

PlayFab exposes 3 protection levels for user Publisher data from the Client API point of view:

1. Regular user Publisher data exposes read and write access for client applications.

   * Set via Client, Server, and Admin API.
   * Get via Client, Server, and Admin API.
   * The Client API may only set Publisher data for a player who is currently logged in.

2. Read-only user Publisher data exposes read access for client applications.

   * Set via Server and Admin API.
   * Get via Client, Server, and Admin API.

3. Internal user Publisher data exposes no access for client applications, and is used to store the secret portion of user data.

   * Set via Server and Admin API.
   * Get via Server and Admin API.

### Setting user Publisher data

The following snippet demonstrates how to set all 3 kinds of Publisher data using Client and Server APIs.

```csharp theme={null}
// Use Client API to set User Publisher Data for current user
public void ClientSetUserPublisherData() {
    PlayFabClientAPI.UpdateUserPublisherData(new UpdateUserDataRequest() {
         Data  = new Dictionary<string, string>() {
             { "SomeKey", "SomeValue" }
         }
    },
    result => Debug.Log("Complete setting Regular User Publisher Data"),
    error =>
    {
        Debug.Log("Error setting Regular User Publisher Data");
        Debug.Log(error.GenerateErrorReport());
    });
}

// Use Server API to set Read-Only User Publisher Data for selected user
public void ServerSetUserPublisherReadOnlyData() {
    PlayFabServerAPI.UpdateUserPublisherReadOnlyData(new UpdateUserDataRequest() {
         PlayFabId = "< PlayFab Player Id >",
         Data  = new Dictionary<string, string>() {
             { "SomeKey", "SomeValue" }
         }
    },
    result => Debug.Log("Complete setting Read-Only User Publisher Data"),
    error =>
    {
        Debug.Log("Error setting Read-Only User Publisher Data");
        Debug.Log(error.GenerateErrorReport());
    });
}

// Use Server API to set Internal User Publisher Data for selected user
public void ServerSetUserPublisherInternalData() {
    PlayFabServerAPI.UpdateUserPublisherInternalData(new UpdateUserInternalDataRequest() {
         PlayFabId = "< PlayFab Player Id >",
         Data  = new Dictionary<string, string>() {
             { "SomeKey", "SomeValue" }
         }
    },
    result => Debug.Log("Complete setting Internal User Publisher Data"),
    error =>
    {
        Debug.Log("Error setting Internal User Publisher Data");
        Debug.Log(error.GenerateErrorReport());
    });
}
```

### Getting user Publisher data

The following snippet demonstrates how to get all 3 kinds of Publisher data using Client and Server APIs.

```csharp theme={null}
// Use Client API to get Regular User Publisher Data for selected user
public void ClientGetUserPublisherData() {
    PlayFabClientAPI.GetUserPublisherData(new GetUserDataRequest() {
        PlayFabId = "<PlayFab Player Id>"
    }, result => {
        if (result.Data == null || !result.Data.ContainsKey("SomeKey")) Debug.Log("No SomeKey");
        else Debug.Log("SomeKey: " + result.Data["SomeKey"]);
    },
    error => {
        Debug.Log("Got error getting Regular Publisher Data:");
        Debug.Log(error.GenerateErrorReport());
    });
}

// Use Client API to get Read-Only User Publisher Data for selected user
public void ClientGetUserPublisherReadOnlyData() {
    PlayFabClientAPI.GetUserPublisherReadOnlyData(new GetUserDataRequest() {
        PlayFabId = "<PlayFab Player Id>"
    }, result => {
        if (result.Data == null || !result.Data.ContainsKey("SomeKey")) Debug.Log("No SomeKey");
        else Debug.Log("SomeKey: " + result.Data["SomeKey"]);
    },
    error => {
        Debug.Log("Got error getting Read-Only Publisher Data:");
        Debug.Log(error.GenerateErrorReport());
    });
}

// Use Server API to get Internal User Publisher Data for selected user
public void ServerGetUserPublisherInternalData() {
    PlayFabServerAPI.GetUserPublisherInternalData(new GetUserDataRequest() {
        PlayFabId = "<PlayFab Player Id>"
    }, result => {
        if (result.Data == null || !result.Data.ContainsKey("SomeKey")) Debug.Log("No SomeKey");
        else Debug.Log("SomeKey: " + result.Data["SomeKey"]);
    },
    error => {
        Debug.Log("Got error getting Internal Publisher Data:");
        Debug.Log(error.GenerateErrorReport());
    });
}
```

## See also

* [Title Data quickstart](/services/playfab/live-service-management/game-configuration/titledata/quickstart)
* [CloudScript quickstart](/services/playfab/live-service-management/service-gateway/automation/cloudscript/quickstart))


## Related topics

- [Title Data](/services/playfab/live-service-management/game-configuration/titledata/index.md)
- [Title Data quickstart](/services/playfab/live-service-management/game-configuration/titledata/quickstart.md)
- [Quickstart Player Data](/services/playfab/player-progression/player-data/quickstart.md)
- [PFTitleDataManagementServerGetPublisherDataAsync](/services/playfab/api-references/c/pftitledatamanagement/functions/pftitledatamanagementservergetpublisherdataasync.md)
- [PFTitleDataManagementServerSetPublisherDataAsync](/services/playfab/api-references/c/pftitledatamanagement/functions/pftitledatamanagementserversetpublisherdataasync.md)
