4. User Creation
Learn how to create and link a user to enable the Sentiance SDK's core functionality.
Please checkout SDK and User Management to understand what a Sentiance user is and how the SDK manages users and devices.
Steps
Prerequisites
As part of user creation, you will need the following:
Sentiance API Key A valid Sentiance API key with the
user_linkpermission. Refer to the API key creation guide to generate a key and give it the correct permission.User Creation Endpoint An API endpoint on your backend that accepts user creation requests from your app, and forwards them to Sentiance. It should use the Sentiance API Key for authentication.
Request an Authentication Code
From your app, send a user creation request to your own backend.
Forward this request to Sentiance by making an HTTP POST request to obtain an authentication code. The request must include a unique app-user identifier. Sentiance’s default (Europe) API endpoint is
https://api.sentiance.com. If you have specific regional requirements, contact Sentiance.
POST /users/auth-code
Content-Type: application/json
Authorization: Bearer <sentiance-api-key>
{
external_id: <unique-app-user-identifier>
}The Sentiance API will respond with a json object containing an
authentication_code. This code is valid for 10 minutes. Forward it to your app, and use it to create a Sentiance user.
Here are code samples in Express (Nodejs) and Flask (Python) for handling user creation requests on your backend.
UserCreation Data Flow

Create a User
Create a user by calling the SDK's createUser() method, and passing it the authentication code that you received from Sentiance.
import SENTSDK
let options = SENTUserCreationOptions(authenticationCode: authCode)
Sentiance.shared.createUser(options: options) { result, error in
guard let result = result else {
NSLog("User creation failed with reason \(error!.failureReason)")
return
}
NSLog("Created a user with ID: \(result.userInfo.userId)")
}import com.sentiance.sdk.Sentiance
import com.sentiance.sdk.usercreation.UserCreationOptions
val options = UserCreationOptions.Builder(authenticationCode).build()
Sentiance.getInstance(context).createUser(options).addOnCompleteListener { operation ->
if (operation.isSuccessful) {
val userInfo = operation.result.userInfo
Log.d(TAG, "Created a user with ID: ${userInfo.userId}")
} else {
val error = operation.error
Log.e(TAG, "User creation failed with reason ${error.reason.name}. Details: ${error.details}")
}
}Specifying a Sentiance API Endpoint
If your Sentiance account is not located in the default Europe region, you must specify the corresponding Sentiance API endpoint when creating a user. Here's an example.
let userCreationOptions = SENTUserCreationOptions(authenticationCode: authCode)
userCreationOptions.platformUrl = "https://api.p15.sentiance.com"val createOptions = UserCreationOptions.Builder(authCode)
.setPlatformUrl("https://api.p15.sentiance.com")
.build()await SentianceCore.createUser({
platformUrl: "https://api.p15.sentiance.com",
authCode
})await sentiance.createUser(
CreateUserOptions(
authCode: authCode,
platformUrl: "https://api.p15.sentiance.com",
),
);Next: Enabling Detections
After having successfully created a Sentiance user, you can proceed to enable SDK detections. To do so, follow the instructions on this page.
Last updated