Update User Object¶
Description¶
User property values of the logged in users can be updated with an API operation described below. This operation is useful if an application needs to provide to the users the functionality for updating user profiles and registration properties. A user must be logged in to update his registration properties.
Method¶
- (void)updateWithUser:(BackendlessUser * _Nonnull)user responseHandler:^(BackendlessUser * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func update(user: BackendlessUser, responseHandler: ((BackendlessUser) -> Void)!, errorHandler: ((Fault) -> Void)!)
where
Argument | Description |
---|---|
user |
The BackendlessUser object which contains property values to update the user account with. |
responseHandler |
Handles successful result of an asynchronous call. |
errorHandler |
Handles fault result of an asynchronous call. |
Return Value¶
The BackendlessUser
object containing updated user data. The object has the values for all the properties stored in the Users data table.
Example¶
The example below updates the value of the "phoneNumber"
property in the BackendlessUser
object to "5551212"
and sends it to the server.
[Backendless.shared.userService loginWithIdentity:@"james.bond@mi6.co.uk" password:@"iAmWatchingU" responseHandler:^(BackendlessUser *loggedInUser) {
[loggedInUser setPropertyWithPropertyName:@"phoneNumber" propertyValue:@"5551212"];
[Backendless.shared.userService updateWithUser:loggedInUser responseHandler:^(BackendlessUser *updatedUser) {
NSLog(@"User has been updated");
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
Backendless.shared.userService.login(identity: "james.bond@mi6.co.uk", password: "iAmWatchingU", responseHandler: { loggedInUser in
loggedInUser.setProperty(propertyName: "phoneNumber", propertyValue: "5551212")
Backendless.shared.userService.update(user: loggedInUser, responseHandler: { updatedUser in
print("User has been updated")
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
Errors¶
The following errors may occur during the Update User Properties API call. See the Error Handling section for details on how to retrieve the error code when the server returns an error.
Error Code |
Description |
---|---|
2002 |
Version is disabled or provided wrong application info (application id or secret key) |
3018 |
The property marked as "identity" is being updated and another user already has the specified value which must be unique. |
3024 |
General "update registration" error. Error message should contain additional details. |
3028 |
User is not logged in. |
3029 |
Cannot modify properties of another user. Returned when one user is logged and the call attempts to modify properties of another user. |
3030 |
Unable to locate user account - invalid user id. |
3031 |
A new "dynamic" property is being added, but dynamic property definition is disabled. |
3045 |
Required properties in the provided object do not contain values. |
Codeless Reference¶
Returns the BackendlessUser
object containing updated user data. The object has the values for all the properties stored in Users data table.
Consider the following record in the Users
data table:
The example below logs in as "alice@yourmail.com"
to obtain the user-token. Then it updates the contents of the email
and address
columns in the Users
data table. Note that you have to use the objectId
in the operation to update the user.
The result of this operation is the new email "alice@newmail.com"
and address "27 Rose Street"
.