👤 Users
The Users
module provides a comprehensive suite of functionalities to manage user data effectively, ranging from user creation, updates, to deletions. Below is a breakdown of its methods and their usage:
1. Get started
If you haven't already, install the Damoov-Admin SDK for Python.
pip install damoov-admin
Begin by importing the User management module and finalizing the authentication process.
from damoov_admin import users
email="[email protected]"
password="YOUR PASSWORD"
user_mngt = users.DamoovAuth(email=email, password=password)
2. Methods
Syntaxes:
instanceid
: The instance ID for the user.instancekey
: The instance Key for the user.ClientId
: A unique identifier assigned by the client for the user.FirstName
: First name of the user.LastName
: Last name of the user.Nickname
: Nickname for the user.Phone
: Phone number of the user.Email
: Email address of the user.CreateAccessToken
: If set to True, a user's access token will be created.
create_user
create_user
Creates a new user based on the given parameters.
Parameters
instanceid
: Required.instancekey
: Required.FirstName
: Optional.LastName
: Optional.Nickname
: Optional.Phone
: Optional.Email
: Optional.ClientId
: Optional.CreateAccessToken
: Optional.
Example:
Request:
new_user=users_mgnt.create_user(
instanceid='your_instance_id',
instancekey='your_instance_key',
FirstName='FirstName',
LastName='LastName',
Nickname='Nickname',
Phone='123456789',
)
Response:
DeviceToken is an old name for UserId
{
"Result": {
"DeviceToken": "user_devicetoken/userid", // DeviceToekn is the same as UserId
"AccessToken": null,
"RefreshToken": null
},
"Status": 200,
"Title": "",
"Errors": []
}
update_user
update_user
Updates user details based on the given parameters.
Parameters
userid
: Required. User's unique identifier.ClientId
: Optional. Client ID for the user.FirstName
: Optional. Updated first name of the user.LastName
: Optional. Updated last name of the user.Nickname
: Optional. Updated nickname for the user.Phone
: Optional. Updated phone number of the user.Email
: Optional. Updated email address of the user.
Example:
Request:
user=users_mgnt.update_user(
userid='User_Id',
FirstName='Tim',
LastName='Plumber',
Nickname='Tim-tim',
Phone='123456789',
ClientId='12-34-56789'
)
Response:
{
"Status": 200,
"Title": "",
"Errors": []
}
delete_user
delete_user
Parameters:
Example:
Request:
delete_user=users_mgnt.delete_user(
userid='User_devicetoken/userid'
)
Response:
{
"Status": 200,
"Title": "",
"Errors": []
}
get_user_details
get_user_details
Parameters:
Example:
Request:
user_details=users_mgnt.get_user_details(
userid='User_devicetoken/userid'
)
Response:
{
"UserProfile": {
"FirstName": "",
"LastName": "",
"Gender": "",
"Birthday": null,
"MaritalStatus": null,
"ChildrenCount": null,
"Address": null,
"Country": null,
"District": null,
"City": null,
"Nickname": null,
"Email": null,
"Phone": null,
},
"MobileDevice": {
"MobileUid": null,
"DeviceModel": null,
"OsType": null,
"OsVersion": null,
"SdkVersion": null,
"AppVersion": null,
"VirtualImei": ""
},
"AccountInfo": {
"CompanyId": "",
"CompanyName":"" ,
"ApplicationId": "",
"ApplicationName": "",
"InstanceId": "",
"InstanceName": ""
},
"UserWallets": [],
"UserFields": [
{
"ClientId": "",
"EnableLogging": false,
"EnableRealTimeLocation": false,
"EnableTracking": true,
"Enabled": true
}
]
}
3. Note
- In all methods, if there's a HTTPError, the error will be printed, and the response will be handled accordingly.
4. Response
The UsersResponse
class is tailored to process and provide convenient access to specific parts of the data returned from user-related operations. Here's an in-depth breakdown of its properties and methods:
devicetoken
devicetoken
Returns the DeviceToken
from the response's Result
section. It provides the device token/ UseId associated with the user.
Return Type: Depends on data (e.g., str
, None
)
userid
userid
Returns the user ID from the response's Result
section. It provides the device token/ UseId associated with the user.
Return Type: Depends on data (e.g., str
, None
)
status
status
Extracts the 'Status' of the response. This typically indicates the success or failure of the operation and might contain relevant status codes or messages.
Return Type: dict
5. Usage
After conducting operations related to users, you can pass the returned data to UsersResponse
to further process and effortlessly access specific parts of the response.
# Import and initial initialization
from damoov_admin import users
email="[email protected]"
password="YOUR PASSWORD"
user_mngt = users.DamoovAuth(email=email, password=password)
# Use methods to create and manage users
new_user=users.create_user(
instanceid='your_instance_id',
instancekey='your_instance_key',,
)
print(new_user)
print(new_user.devicetoken)
print(new_user.status)
print(new_user.userid)
user=users_mgnt.update_user(
userid='User_Id',
FirstName='Tim',
LastName='Plumber',
Nickname='Tim-tim',
Phone='123456789',
ClientId='12-34-56789'
)
print(user)
print(user.status)
Updated about 1 month ago