Skip to content
StatusSupportDashboard

Create webapp SDK session

client_sessions.create_session(**kwargs) -> ClientSessionCreateSessionResponse { sdk_script_url, session_token }
POST/v1/sessions

Create a browser-safe SafetyKit webapp SDK session token from server-side code before rendering pages that load the browser SDK. Provide at least one of customer_user_id or customer_session_hash. When customer_user_id is present, use the same canonical user ID string that you send as user_id in SafetyKit server-to-server events. The request must be authenticated with a valid Bearer token.

ParametersExpand Collapse
body: UnionMember0{ customer_user_id, customer_session_hash} | UnionMember1{ customer_session_hash, customer_user_id}

Request body for creating a browser-safe webapp SDK session token from server-side code. Provide at least one of customer_user_id or customer_session_hash.

One of the following:
class UnionMember0 { customer_user_id, customer_session_hash }
customer_user_id: String

Customer user identifier associated with the browser SDK session. Use the same canonical user ID string that you send as user_id in SafetyKit server-to-server events.

minLength1
maxLength512
customer_session_hash: String

Stable opaque customer session hash associated with the browser SDK session.

minLength1
maxLength512
class UnionMember1 { customer_session_hash, customer_user_id }
customer_session_hash: String

Stable opaque customer session hash associated with the browser SDK session.

minLength1
maxLength512
customer_user_id: String

Customer user identifier associated with the browser SDK session. Use the same canonical user ID string that you send as user_id in SafetyKit server-to-server events.

minLength1
maxLength512
ReturnsExpand Collapse
class ClientSessionCreateSessionResponse { sdk_script_url, session_token }

Response containing the browser-safe webapp SDK session token and hosted SDK script URL.

sdk_script_url: String

SafetyKit-hosted browser SDK script URL to render as the script src.

formaturi
session_token: String

Browser-safe webapp SDK session token to pass to the browser SDK.

Create webapp SDK session

require "safety_kit"

safetykit = SafetyKit::Client.new(api_key: "My API Key")

response = safetykit.client_sessions.create_session(body: {customer_user_id: "user_12345"})

puts(response)
{
  "sdk_script_url": "https://cdn.sk-diagnostics.com/web/v1/sdk.js",
  "session_token": "skst_v2_eyJ..."
}
Returns Examples
{
  "sdk_script_url": "https://cdn.sk-diagnostics.com/web/v1/sdk.js",
  "session_token": "skst_v2_eyJ..."
}