sample of adding new record and also adding it to shared folder
# Example showing how to add a new or existing record
# to an existing shared folder.
#
+import os
-from keepercommander.params import KeeperParams
from keepercommander import api
+from keepercommander.__main__ import get_params_from_config
from keepercommander.commands.record import RecordAddCommand
+from keepercommander.params import KeeperParams
-params = KeeperParams()
-# Inputs - hard coded for demo purposes
-params.user = 'your_keeper_email'
-params.password = 'your_keeper_password'
-shared_folder_uid = 'your_shared_folder_uid'
+def login(
+ email,
+ password=None,
+ keeper_server='https://keepersecurity.com/api/v2/',
+ config_file='myconfig.json'):
-# Login and sync
+ if os.path.exists(config_file):
+ params = get_params_from_config(config_file)
+ else:
+ params = KeeperParams()
+ params.config_filename = config_file
+ params.user = email
+ params.password = password if password else ''
+ params.server = keeper_server
+ params.config['server'] = params.server
+
+ api.login(params)
api.sync_down(params)
+ return params
+
+
+def create_new_record(params):
+ shared_folder_uid = 'UID'
+
command = RecordAddCommand()
-record_uid = command.execute(params, title='Test Record', login='someone@company.com', url='https://google.com', folder=shared_folder_uid, generate=True, force=True)
-print('Added record to shared folder')
+ # Inputs - hard coded for demo purposes
+ record_uid = command.execute(
+ params,
+ title='Test Record',
+ login='someone@company.com',
+ url='https://google.com',
+ folder=shared_folder_uid,
+ generate=True,
+ # force=True disables asking for missing fields
+ force=True)
+
+ print('Added record %s to shared folder uid=%s' % (record_uid, shared_folder_uid))
+
+
+if __name__ == '__main__':
+
+ # Login and sync
+ params = login("user@email.com", password="password")
+
+ create_new_record(params)
