Skip to main content
To retrieve your SDK connection details ensure you have first:
  1. Created A Ditto Portal Account - Creating a Ditto Account
  2. Created A Ditto Database - Creating a New Database
After you’ve created your database, select it from the list. On the Connect tab, you will see the following details under Big peer connection information:
  • Database ID - The unique identifier for your database.
  • Auth URL - This is the URL you will need to pass to your SDK to authenticate.
  • Websocket URL - This is the URL you will need to pass to your SDK to initiate replication via Websocket to Ditto Server.
On the Connect tab, under Authentication Mode, if you are still using the default authentication settings, you will also see the Online Playground Authentication Token. This token is used to authenticate your SDK to Ditto Server It allows you to explore Ditto platform features and functionality without the hassle of setting up your own authentication mechanism.

Offline License Tokens

Offline license tokens allow your application to operate without connectivity to Ditto’s cloud. They are available on the Connect tab for your database in the Portal. Offline license tokens have an expiration period. The default expiration is 30 days, but you can customize this when creating a new token.

Required Permissions

To view offline license tokens, your Portal role must include the Access offline-only licenses permission. To create or manage offline license tokens, your role must also include the Request offline-only licenses permission. For details on configuring roles, see Role-Based Access Control.
If you do not see the offline license token section on the Connect tab, your role may not have the required permissions. Contact your organization admin to request the Access offline-only licenses and/or Request offline-only licenses permissions, or reach out to Ditto support to have tokens generated on your behalf.

Connecting an SDK

Below are some examples of how to connect an SDK to Ditto Server:
ditto = Ditto(
  identity: DittoIdentity.onlinePlayground(
    appID: "REPLACE_ME_WITH_YOUR_APP_ID",
    token: "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN",
    enableDittoCloudSync: false, // This is required to be set to false to use the correct URLs
    customAuthURL: URL(string: "REPLACE_ME_WITH_YOUR_AUTH_URL")
  )
)

ditto.updateTransportConfig { transportConfig in
  // Set the Ditto Websocket URL
  transportConfig.connect.webSocketURLs.insert("wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL")
}

// Disable DQL strict mode so that collection definitions are not required in DQL queries
try await ditto.store.execute("ALTER SYSTEM SET DQL_STRICT_MODE = false")

do {
  try ditto.startSync()
} catch {
  print(error.localizedDescription)
}
try {
    val androidDependencies = DefaultAndroidDittoDependencies(applicationContext)
    val identity =
        DittoIdentity.OnlinePlayground(
            dependencies = androidDependencies,
            appId = "REPLACE_ME_WITH_YOUR_APP_ID",
            token = "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN",
            customAuthUrl = "REPLACE_ME_WITH_YOUR_AUTH_URL",
            enableDittoCloudSync = false  // This is required to be set to false to use the correct URLs
        )

    ditto = Ditto(androidDependencies, identity)

    ditto?.updateTransportConfig { config ->
        config.connect.websocketUrls.add("REPLACE_ME_WITH_YOUR_WEBSOCKET_URL")
    }

    // Disable DQL strict mode so that collection definitions are not required in DQL queries
    ditto.store.execute("ALTER SYSTEM SET DQL_STRICT_MODE = false")
    
    ditto.startSync()
} catch (e: DittoError) {
    Log.e("Ditto error", e.message!!)
}

await Ditto.init();

final identity = OnlinePlaygroundIdentity(
    appId: "REPLACE_ME_WITH_YOUR_APP_ID",
    token: "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN",
    customAuthUrl: "REPLACE_ME_WITH_YOUR_AUTH_URL",
    enableDittoCloudSync: false // This is required to be set to false to use the correct URLs
);
final ditto = await Ditto.open(identity);

ditto.updateTransportConfig((config) {
  // Set the Ditto Websocket URL
  config.connect.webSocketUrls.add("wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL");
});

// Disable DQL strict mode so that collection definitions are not required in DQL queries
await ditto.store.execute("ALTER SYSTEM SET DQL_STRICT_MODE = false");

ditto.startSync();
JavaScript
await init();

const ditto = new Ditto({
  type: "onlinePlayground",
  appID: "REPLACE_ME_WITH_YOUR_APP_ID",
  token: "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN",
  customAuthURL: "REPLACE_ME_WITH_YOUR_AUTH_URL",
  enableDittoCloudSync: false, // This is required to be set to false to use the correct URLs
});

ditto.updateTransportConfig((config) => {
  config.connect.websocketURLs.push(
    'wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL'
  );
});

// Disable DQL strict mode so that collection definitions are not required in DQL queries
await ditto.store.execute("ALTER SYSTEM SET DQL_STRICT_MODE = false");

ditto.startSync();
TypeScript
import { init, Ditto, TransportConfig } from '@dittolive/ditto';

await init();

const ditto: Ditto = new Ditto({
  type: "onlinePlayground",
  appID: "REPLACE_ME_WITH_YOUR_APP_ID",
  token: "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN",
  customAuthURL: "REPLACE_ME_WITH_YOUR_AUTH_URL",
  enableDittoCloudSync: false, // This is required to be set to false to use the correct URLs
});

ditto.updateTransportConfig((config: TransportConfig) => {
  config.connect.websocketURLs.push(
    'wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL'
  );
});

// Disable DQL strict mode so that collection definitions are not required in DQL queries
await ditto.store.execute("ALTER SYSTEM SET DQL_STRICT_MODE = false");

ditto.startSync();
import { init, Ditto, TransportConfig } from '@dittolive/ditto'

await init()

const ditto = new Ditto({
  type: "onlinePlayground",
  appID: "REPLACE_ME_WITH_YOUR_APP_ID",
  token: "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN",
  customAuthURL: "REPLACE_ME_WITH_YOUR_AUTH_URL",
  enableDittoCloudSync: false, // This is required to be set to false to use the correct URLs
})

ditto.updateTransportConfig((config: TransportConfig): void => {
  config.connect.websocketURLs.push(
    'wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL'
  )
})

// Disable DQL strict mode so that collection definitions are not required in DQL queries
await ditto.store.execute("ALTER SYSTEM SET DQL_STRICT_MODE = false")

ditto.startSync()
import com.ditto.java.Ditto;
import com.ditto.java.DittoFactory;
import com.ditto.java.DittoConfig;
import com.ditto.java.DittoAuthenticationProvider;

try {
    // Configure Ditto with playground settings
    DittoConfig config = new DittoConfig.Builder("REPLACE_ME_WITH_YOUR_APP_ID")
        .connect(new DittoConfig.Connect.Server("wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL"))
        .build();

    Ditto ditto = DittoFactory.create(config);

    // Set up authentication with playground token
    ditto.getAuth().login(
        "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN",
        DittoAuthenticationProvider.playground()
    ).thenAccept(clientInfo -> {
        // Disable DQL strict mode so that collection definitions are not required in DQL queries
        ditto.getStore().execute("ALTER SYSTEM SET DQL_STRICT_MODE = false");

        ditto.startSync();
    }).exceptionally(error -> {
        // Handle authentication error
        return null;
    });
} catch (DittoError e) {
    // Handle error in Ditto initialization
}
var identity = DittoIdentity.OnlinePlayground(
    appId, 
    playgroundToken, 
    false, // This is required to be set to false to use the correct URLs
    authUrl);

ditto = new Ditto(identity, tempDir);

ditto.UpdateTransportConfig(config =>
{
    // Set the Ditto Websocket URL
    config.Connect.WebSocketUrls.Add("wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL");
});

// Disable DQL strict mode so that collection definitions are not required in DQL queries
await ditto.Store.ExecuteAsync("ALTER SYSTEM SET DQL_STRICT_MODE = false");

ditto.StartSync();

const auto identity = ditto::Identity::OnlinePlayground(
    std::move(app_id),
    std::move(online_playground_token),
    enable_cloud_sync,                  // This is required to be set to false to use the correct URLs
    std::move(custom_url)
);

ditto->update_transport_config([&](ditto::TransportConfig &config) {
    config.enable_all_peer_to_peer();
    config.connect.websocket_urls.insert(websocket_url);
});
// Required for compatibility with DQL.
ditto->disable_sync_with_v3();

// Disable DQL strict mode so that collection definitions are not required in DQL queries
ditto->get_store().execute("ALTER SYSTEM SET DQL_STRICT_MODE = false");

ditto->start_sync();
use dittolive_ditto::prelude::*;
use std::time::Duration;

// Initialize with DittoConfig using database_id (was app_id in v4).
// Copy the "URL" and "Database ID" from the Ditto Portal (Connect via SDK).
let database_id = DatabaseId::from_str("REPLACE_ME_WITH_YOUR_DATABASE_ID")?;
let config = DittoConfig::new(
    database_id.clone(),
    DittoConnect::Server {
        url: "REPLACE_ME_WITH_YOUR_URL".to_string()
    }
);

let ditto = Ditto::open(config)?;

// Set up authentication expiration handler
ditto.auth().set_expiration_handler(|ditto, seconds_remaining| {
    ditto.auth().login(
        "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN",
        Authenticator::development_provider(),
        |result| {
            if let Err(e) = result {
                eprintln!("Auth error: {}", e);
            }
        }
    );
});

// Configure transport (optional)
ditto.set_transport_config({
    let mut config = TransportConfig::new();
    config
        .connect
        .websocket_urls
        // Your Portal URL with the scheme changed from https:// to wss:// (host only)
        .insert("wss://REPLACE_ME_WITH_YOUR_URL_HOST".to_string());
    config
});

// Start sync (was ditto.start_sync() in v4)
ditto.sync().start()?;
const endpoint = "REPLACE_ME_WITH_YOUR_URL"
const id       = "REPLACE_ME_WITH_YOUR_DATABASE_ID"
const token    = "REPLACE_ME_WITH_YOUR_DEVELOPMENT_TOKEN"

config := ditto.DefaultDittoConfig().
    WithDatabaseID(id).
    WithConnect(&ditto.DittoConfigConnectServer{URL: endpoint})

dit, err := ditto.Open(config)
if err != nil {
    log.Fatalf("error: failed to open Ditto: %v", err)
}
defer dit.Close()

// Set up authentication expiration handler (required for server connections)
dit.Auth().SetExpirationHandler(
    func(d *ditto.Ditto, timeUntilExpiration time.Duration) {
        _, err := d.Auth().Login(token, ditto.DevelopmentAuthenticationProvider())
        if err != nil {
            log.Errorf("Authentication failed: %v", err)
        } else {
            log.Printf("Authentication succeeded")
        }
    })

if err := dit.Sync().Start(); err != nil {
    log.Errorf("error: failed to start sync: %v", err)
}