For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

1

Prerequisites

As part of user creation, you will need the following:

  1. Sentiance API Key A valid Sentiance API key with the user_link permission. Refer to the API key creation guide to generate a key and give it the correct permission.

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

2

Request an Authentication Code

  1. From your app, send a user creation request to your own backend.

  2. 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>
}
  1. 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.

Complete Nodejs (Express) endpoint code sample
const USER_LINK_API_KEY = "ABCDEF123456789...."; 
const authUrl = "https://api.sentiance.com/users/auth-code";

app.post("/sentiance-user-create", await (req,res) =>{
// validate the request and identify the user
  const externalID = "customer_id_001";  // Identifier for this particular user
  try {
      const sentianceRsponse = await fetch(authURL, {
        method: "POST",
        headers: {
          "Authorization": `Bearer ${USER_LINK_API_KEY}`,
          "Content-Type": "application/json",
          "Accept": "application/json"
        },
        body: JSON.stringify({
          external_id: externalID
        })
      });
    
      // validate the response to the sentiance platform
      const data = await sentianceRsponse.json();
      res.send(data["authentication_code");
  } catch (error) {
    console.error("Error getting auth code:", error);
      // respond with 4xx
  }
});

Complete Python (Flask) endpoint code sample

UserCreation Data Flow

3

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",
    ),
);
4

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