Adding user via ThoughtSpot API

Is there a way to add a user to ThoughtSpot programmatically without first logging in via SAML? Can we do this with a Trusted Auth token or some other means instead to verify the user making the request?

6replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Yes.  There are web services APIs you can use to add users.  You would have to authenticate somehow for the user doing the syncing (admin user), so as long as that authentication works.  

    See sync operations here: https://docs.thoughtspot.com/5.2/app-integrate/reference/user-api.html

    Reply Like
  • What are the options to authenticate to be able to use these calls? Are we able to use an auth token to make these calls? What would something like that look like?

    Reply Like
  • I ended up solving this by using the POST /session/login call and passing the cookie returned back from this to the POST /session/user/create call. Seems to work well

    Reply Like
  • if it helps, I use their python API called tsAPI (which should be on your ts appliance already).  

     

    I have my ldap users put into a csv file, and then this python script reads the users from csv, and adds them into TS

     

    # python script..: \\myserver\Thoughtspot\bin\indot_create_TS_users_from_LDAP_csv.py
    # author.........: Michael Dockery (mdockery1@indot.in.gov)
    # purpose........: Thoughtspot user sync (called by a linux shell)
    # Logic..........: Read/Loop the daily LDAP_CSV (\\mysvr\Thoughtspot$\data\AD_USERS.csv) records/lines
    #                  attempt to add each TS user (quietly ignore Constants.USER_ALREADY_EXISTS errors)
    # Used by........: \\mysvr\ODI_INDOT_SCRIPTS\ThoughtSpot\ADD_TS_USERS_FROM_AD_CSV.bat
    # col formatting.:
    #    ts_username    = 'someuser@indot.IN.gov'; ...so the actual email. upn -user_principal_name (or sAMaccountName)
    #    ts_displayname = 'someuser';
    #******************************************************************************************************
    import tsApi    #...Wrapper.login
    import logging  #for logging debug messages
    from globalClasses import Constants
    logging.basicConfig(level=logging.CRITICAL)
    print("Starting...");
    try:
        print("Logging into TS");
        ts_handle = tsApi.TSApiWrapper('DISABLE_SSL');
        result = ts_handle.login(
            'https://10.1.1.2',
            'MY_BOGUS_LDAPSYNC_ACCOUNT@indot.in.gov',
            'myboguspassword'
        )
        file = open("/mnt/indot/data/AD_USERS.csv", "r");

    for line in file: 
            words = line.split('~');
            ts_acntname=words[0];
            ts_username=words[1];
            ts_dispname=words[2].strip();
            logging.debug("Processing user %s",ts_username);

            result = ts_handle.create_user(
                ts_username, ts_dispname,
                ts_handle.LDAP_USER,
                None,  # password
                None   # prop
            )
            if result.status == Constants.OPERATION_SUCCESS:
                logging.debug("User created: {}\n".format(ts_username))
                msg="User created " + ts_username
                print(msg);
            elif result.status == Constants.USER_ALREADY_EXISTS:
                logging.info("User exists: {}\n".format(ts_username))
            else:            
                reason = str(result.data) if result.data is not None else ""
                msg = "Failed to create user " + ts_username + " " + ts_dispname + " reason:" + reason
                logging.debug(msg)
                print(msg);
        file.close();
    except Exception as e:
        logging.error(e.message);
    print("Finished...");
     

    Reply Like 1
  • I believe the path to the python api's is here:  /usr/local/scaligent/release/callosum/utilities/ldap_sync_python_api

    Reply Like
  • here is a short/simple example of how to add TS users to a TS group:

     

    # python script..: \\mysvr\Thoughtspot$\bin\indot_add_ts_user_to_ts_group.py
    # author.........: mdockery
    # purpose........: add ts user to ts group
    # ts_hostport....: 'https://10.1.1.2'
    # ts_uname.......: MY_BOGUS_LDAPSYNC_ACCOUNT@indot.in.gov
    # ts_pass........: myboguspassword
    # TS user.type...: LOCAL_USER or LDAP_USER
    #******************************************************************************************************
    import tsApi    #...Wrapper.login
    import logging
    from globalClasses import Constants
    logging.basicConfig(level=logging.DEBUG)
    print("Starting...");
    print("Logging into TS");
    ts_handle = tsApi.TSApiWrapper('DISABLE_SSL');
    result = ts_handle.login(
                'https://10.1.1.2',
            'MY_BOGUS_LDAPSYNC_ACCOUNT@indot.in.gov',
            'myboguspassword'
            )
    ts_username = 'MDockery1@indot.IN.gov';
    try:
        ts_group_gid = ts_handle.get_groupid_with_name('INDOT_Current_Exchange_Users').data
        logging.debug("ts_group_gid: {}\n".format(ts_group_gid))
        print("ts_group_gid");
        print(ts_group_gid);

    ts_user_uid = ts_handle.get_userid_with_name(ts_username).data
        logging.debug("ts_user_uid: {}\n".format(ts_user_uid))
        print("ts_user_uid");
        print(ts_user_uid);

    logging.debug("adding user to group...")
        ts_handle.add_user_to_group(ts_user_uid, ts_group_gid)
    except Exception as e:
        logging.error(e.message);

    print("Finished...");
     

    Reply Like 1
Like Follow
  • Status Answered
  • 4 mths agoLast active
  • 6Replies
  • 63Views
  • 3 Following