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 = "user_001";  // Identifier for this particular user: (email, phone number, userID)
  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
import requests
from flask import Blueprint, jsonify, current_app

auth_bp = Blueprint("auth_bp", __name__)

@auth_bp.route("/get-auth-code", methods=["GET"])
def get_auth_code():

    ## DONT PUT YOUR API KEY ON YOUR APP -- SAMPLE ONLY
    USER_LINK_API_KEY = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    EXTERNAL_ID = "customer_id_001"
    sentiance_url = "https://api.sentiance.com/users/auth-code"


    ## Where api_key is the USER_LINK API Key you generated in ICT
    headers = {
        "Authorization": f"Bearer {USER_LINK_API_KEY}",
        "Content-Type": "application/json",
        "Accept": "application/json"
    }

    ## Where EXTERNAL_ID is user identifier you choose to assign
    ## (e.g., email address, userID, etc.).
    payload = {
        "external_id": EXTERNAL_ID
    }

    ## Send the "POST" request to Sentiance URL
    response = requests.post(
        sentiance_url,
        headers=headers,
        json=payload
    )
    return response.json()

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)")
}

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"
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