Warning: This version (v1) of the API will be deprecated on May 1st 2015

Persistent Data Storage

How cool would it be if your game's players could make progress from their desktop, and finish the game later on their mobile phone? With our Persistent Data Storage, we make it easy to store game-save data that is accessible from all devices!

The data you store on our server can be a JavaScript object, array, number or string. It is stored associated with either 1) the logged in Clay.io user (which they can access later on from another computer) or 2) if they're not logged in, it is stored based on a combination of their IP address and a cookie. With this, they cannot access the same data from another computer.

You can optionally force the player to login before storing data by using Clay.Player.requireLogin() and passing what is below as a closure.

To save data, use:

// {a: 'okay'} can be an object, number or string
// 'someKey' is a unique identifier key for this data
Clay.Player.saveUserData( 'someKey', {a: 'okay'}, function( response ) {
    // response.success is a boolean of whether or not it was successfully stored
    console.log( response );
} );

To fetch that data later, use:

// 'someKey' is the unique identifier key for this data
Clay.Player.fetchUserData( 'someKey', function( response ) {
    // The JavaScript object you stored will be in response.data
    console.log( response );
} );

You can also store and fetch data by property name if you're storing a large JavaScript object. Say you store the object obj = { test: 1, test2: 2, test3: 3 }. You can change the stored value of *only* obj.test by using the key 'obj.test'.

Note: you cannot save data under the keys "user", "game", or "_id"

Provide Feedback

We take customer support, and the quality of our developer tools and documentation very seriously. We want to hear how you think we can improve our documentation! Let us know if anything is missing, or unclear on this documentation page, and we'll get that fixed!