CreateUser
Creates a new user within the authenticated group context.
The user will be created with the provided email and group ownership, with system-generated unique identifier and ownership hierarchy. Additional roles can be assigned after creation.
- Overview
- Protobuf
Method Options​
Authorisation specification of the CreateUser method.
| Type | METHOD_TYPE_WRITE |
|---|---|
| Access Level | METHOD_ACCESS_LEVEL_AUTHORISED |
| Roles |
|
Parameters​
Request and response parameter message overview:
Input: CreateUserRequest Message​
| Field | Type | Required | Description |
|---|---|---|---|
User |
| True | The user resource to create. The name field will be ignored and assigned by the server. |
Returns: User Message​
syntax = "proto3";
package meshtrade.iam.user.v1;
import "buf/validate/validate.proto";
import "meshtrade/iam/user/v1/user.proto";
import "meshtrade/option/method_options/v1/method_options.proto";
import "meshtrade/type/v1/sorting.proto";
option go_package = "github.com/meshtrade/api/go/iam/user/v1;user_v1";
option java_package = "co.meshtrade.api.iam.user.v1";
/*
UserService manages user lifecycle and identity operations within groups.
Users are individual identity entities that belong to specific groups and have
assigned roles that determine their permissions within that group context.
Each user has a unique email address and can be assigned multiple roles
across the group hierarchy for fine-grained access control.
All operations require appropriate IAM domain permissions and operate within
the authenticated group context.
*/
service UserService {
/*
Assign roles to an existing user within the authenticated group context.
The role assignment enables the user to perform operations according
to the permissions associated with that role within the group hierarchy.
*/
rpc AssignRolesToUser(AssignRolesToUserRequest) returns (meshtrade.iam.user.v1.User) {
option (meshtrade.option.method_options.v1.method_options) = {
type: METHOD_TYPE_WRITE
access_level: METHOD_ACCESS_LEVEL_AUTHORISED
roles: [
ROLE_IAM_ADMIN,
ROLE_IAM_USER_ADMIN
]
};
}
/*
Revoke roles from an existing user within the authenticated group context.
The role revocation removes the permissions associated with that role from
the user within the group hierarchy. The user will no longer be able
to perform operations that require the revoked role.
*/
rpc RevokeRolesFromUser(RevokeRolesFromUserRequest) returns (meshtrade.iam.user.v1.User) {
option (meshtrade.option.method_options.v1.method_options) = {
type: METHOD_TYPE_WRITE
access_level: METHOD_ACCESS_LEVEL_AUTHORISED
roles: [
ROLE_IAM_ADMIN,
ROLE_IAM_USER_ADMIN
]
};
}
/*
Retrieves a single user by their unique identifier.
Returns user details including name, email, ownership information,
and assigned roles within the authenticated group's access scope.
*/
rpc GetUser(GetUserRequest) returns (meshtrade.iam.user.v1.User) {
option (meshtrade.option.method_options.v1.method_options) = {
type: METHOD_TYPE_READ
access_level: METHOD_ACCESS_LEVEL_AUTHORISED
roles: [
ROLE_IAM_ADMIN,
ROLE_IAM_VIEWER,
ROLE_IAM_USER_ADMIN,
ROLE_IAM_USER_VIEWER
]
};
}
/*
Retrieves a single user by their email address.
Returns user details including name, email, ownership information,
and assigned roles within the authenticated group's access scope.
*/
rpc GetUserByEmail(GetUserByEmailRequest) returns (meshtrade.iam.user.v1.User) {
option (meshtrade.option.method_options.v1.method_options) = {
type: METHOD_TYPE_READ
access_level: METHOD_ACCESS_LEVEL_AUTHORISED
roles: [
ROLE_IAM_ADMIN,
ROLE_IAM_VIEWER,
ROLE_IAM_USER_ADMIN,
ROLE_IAM_USER_VIEWER
]
};
}
/*
Returns all users accessible within the authenticated group's hierarchy.
Results include users directly owned and those accessible through the
group's hierarchical permissions, optionally sorted by email address.
*/
rpc ListUsers(ListUsersRequest) returns (ListUsersResponse) {
option (meshtrade.option.method_options.v1.method_options) = {
type: METHOD_TYPE_READ
access_level: METHOD_ACCESS_LEVEL_AUTHORISED
roles: [
ROLE_IAM_ADMIN,
ROLE_IAM_VIEWER,
ROLE_IAM_USER_ADMIN,
ROLE_IAM_USER_VIEWER
]
};
}
/*
Searches for users by email substring within the authenticated group's hierarchy.
Returns users whose email addresses contain the provided search string,
useful for type-ahead and fuzzy-matching use cases.
*/
rpc SearchUsers(SearchUsersRequest) returns (SearchUsersResponse) {
option (meshtrade.option.method_options.v1.method_options) = {
type: METHOD_TYPE_READ
access_level: METHOD_ACCESS_LEVEL_AUTHORISED
roles: [
ROLE_IAM_ADMIN,
ROLE_IAM_VIEWER,
ROLE_IAM_USER_ADMIN,
ROLE_IAM_USER_VIEWER
]
};
}
/*
Creates a new user within the authenticated group context.
The user will be created with the provided email and group ownership,
with system-generated unique identifier and ownership hierarchy.
Additional roles can be assigned after creation.
*/
rpc CreateUser(CreateUserRequest) returns (meshtrade.iam.user.v1.User) {
option (meshtrade.option.method_options.v1.method_options) = {
type: METHOD_TYPE_WRITE
access_level: METHOD_ACCESS_LEVEL_AUTHORISED
roles: [
ROLE_IAM_ADMIN,
ROLE_IAM_USER_ADMIN
]
};
}
/*
Updates an existing user with modified field values.
Only mutable fields can be updated while preserving system-generated
identifiers and ownership relationships. Role modifications should
use dedicated role management operations.
*/
rpc UpdateUser(UpdateUserRequest) returns (meshtrade.iam.user.v1.User) {
option (meshtrade.option.method_options.v1.method_options) = {
type: METHOD_TYPE_WRITE
access_level: METHOD_ACCESS_LEVEL_AUTHORISED
roles: [
ROLE_IAM_ADMIN,
ROLE_IAM_USER_ADMIN
]
};
}
}
message AssignRolesToUserRequest {
/*
Name of the user to assign roles to in the format users/{ULIDv2}.
*/
string name = 1 [(buf.validate.field) = {
required: true
string: {
len: 32
pattern: "^users/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$"
}
}];
/*
Roles to assign to the user in the format groups/{ULIDv2}/roles/{role_id}.
The role_id corresponds to a value from the meshtrade.iam.role.v1.Role enum.
*/
repeated string roles = 2 [(buf.validate.field) = {
required: true
repeated: {
items: {
string: {
min_len: 47
max_len: 48
pattern: "^groups/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}/roles/[1-9][0-9]{6,7}$"
}
}
}
}];
}
message RevokeRolesFromUserRequest {
/*
Name of the user to revoke roles from in the format users/{ULIDv2}.
*/
string name = 1 [(buf.validate.field) = {
required: true
string: {
len: 32
pattern: "^users/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$"
}
}];
/*
Roles to revoke from the user in the format groups/{ULIDv2}/roles/{role_id}.
The role_id corresponds to a value from the meshtrade.iam.role.v1.Role enum.
*/
repeated string roles = 2 [(buf.validate.field) = {
required: true
repeated: {
items: {
string: {
min_len: 47
max_len: 48
pattern: "^groups/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}/roles/[1-9][0-9]{6,7}$"
}
}
}
}];
}
message GetUserRequest {
/*
Name of the user to retrieve.
Format: users/{ULIDv2}
*/
string name = 1 [(buf.validate.field) = {
required: true
string: {
len: 32
pattern: "^users/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$"
}
}];
}
message GetUserByEmailRequest {
/*
Email address of the user to retrieve.
Must be a valid email address format.
*/
string email = 1 [(buf.validate.field) = {
required: true
string: {email: true}
}];
}
message ListUsersRequest {
message Sorting {
/*
Field to sort by (e.g., "email").
*/
string field = 1 [(buf.validate.field) = {
string: {
in: [
"",
"email"
]
}
cel: {
id: "field.valid"
message: "field must be one of: email, or empty"
expression: "this in ['', 'email']"
}
}];
/*
Sort order for results.
*/
meshtrade.type.v1.SortingOrder order = 2;
}
/*
Optional sorting configuration.
*/
Sorting sorting = 1;
}
message ListUsersResponse {
repeated meshtrade.iam.user.v1.User users = 1;
}
message SearchUsersRequest {
/*
Optional Substring to match against user email addresses.
The search is case-insensitive.
*/
string email = 1 [(buf.validate.field) = {
string: {max_len: 100}
}];
}
message SearchUsersResponse {
repeated meshtrade.iam.user.v1.User users = 1;
}
message CreateUserRequest {
/*
The user resource to create.
The name field will be ignored and assigned by the server.
*/
meshtrade.iam.user.v1.User user = 1 [(buf.validate.field) = {required: true}];
}
message UpdateUserRequest {
/*
Complete user resource with updated fields.
Only mutable fields can be modified.
*/
meshtrade.iam.user.v1.User user = 1 [(buf.validate.field) = {required: true}];
}
Code Examples​
Select supported SDK in the language of your choice for a full example of how to invoke the this method:
- Go
- Python
- Java
package main
import (
"context"
"log"
rolev1 "github.com/meshtrade/api/go/iam/role/v1"
userv1 "github.com/meshtrade/api/go/iam/user/v1"
)
func main() {
ctx := context.Background()
// Default configuration is used and credentials come from MESH_API_CREDENTIALS
// environment variable or default discovery methods. Zero config required
// unless you want custom configuration.
service, err := userv1.NewUserService()
if err != nil {
log.Fatalf("Failed to create service: %v", err)
}
defer service.Close()
// Create request with user configuration
request := &userv1.CreateUserRequest{
User: &userv1.User{
Owner: service.Group(), // Current authenticated group becomes the owner
Email: "sarah.thompson@company.com", // Unique email address
Roles: []string{
rolev1.Role_ROLE_WALLET_VIEWER.FullResourceNameFromGroupName(service.Group()),
rolev1.Role_ROLE_TRADING_VIEWER.FullResourceNameFromGroupName(service.Group()),
},
},
}
// Call the CreateUser method
user, err := service.CreateUser(ctx, request)
if err != nil {
log.Fatalf("CreateUser failed: %v", err)
}
// Use the newly created user
log.Printf("User created successfully:")
log.Printf(" Name: %s", user.Name)
log.Printf(" Email: %s", user.Email)
log.Printf(" Owner: %s", user.Owner)
log.Printf(" Roles: %v", user.Roles)
// The user is ready for authentication and resource access
log.Printf("User is ready for authentication with %d assigned roles", len(user.Roles))
}
from meshtrade.api.iam.role.v1.role import full_resource_name_from_group_name
from meshtrade.api.iam.role.v1.role_pb2 import Role
from meshtrade.iam.user.v1 import (
CreateUserRequest,
User,
UserService,
)
def main():
# Default configuration is used and credentials come from MESH_API_CREDENTIALS
# environment variable or default discovery methods. Zero config required
# unless you want custom configuration.
service = UserService()
with service:
# Create request with user configuration
request = CreateUserRequest(
user=User(
owner=service.group(), # Current authenticated group becomes the owner
email="sarah.thompson@company.com", # Unique email address
roles=[
full_resource_name_from_group_name(Role.ROLE_IAM_VIEWER, service.group()),
full_resource_name_from_group_name(Role.ROLE_TRADING_VIEWER, service.group()),
],
)
)
# Call the CreateUser method
user = service.create_user(request)
# Use the newly created user
print("User created successfully:")
print(f" Name: {user.name}")
print(f" Email: {user.email}")
print(f" Owner: {user.owner}")
print(f" Roles: {user.roles}")
print(f"User is ready for authentication with {len(user.roles)} assigned roles")
if __name__ == "__main__":
main()
import co.meshtrade.api.iam.role.v1.RoleUtils;
import co.meshtrade.api.iam.role.v1.RoleOuterClass.Role;
import co.meshtrade.api.iam.user.v1.UserService;
import co.meshtrade.api.iam.user.v1.Service.CreateUserRequest;
import co.meshtrade.api.iam.user.v1.User.User;
import java.util.Optional;
public class CreateUserExample {
public static void main(String[] args) {
// Default configuration is used and credentials come from MESH_API_CREDENTIALS
// environment variable or default discovery methods. Zero config required
// unless you want custom configuration.
try (UserService service = new UserService()) {
// Create request with user configuration
CreateUserRequest request = CreateUserRequest.newBuilder()
.setUser(User.newBuilder()
.setOwner(service.getGroup()) // Current authenticated group becomes the owner
.setEmail("sarah.thompson@company.com") // Unique email address
.addRoles(RoleUtils.fullResourceNameFromGroupName(Role.ROLE_WALLET_VIEWER, service.getGroup()))
.addRoles(RoleUtils.fullResourceNameFromGroupName(Role.ROLE_TRADING_VIEWER, service.getGroup()))
.build())
.build();
// Call the CreateUser method
User user = service.createUser(request, Optional.empty());
// Use the newly created user
System.out.println("User created successfully:");
System.out.println(" Name: " + user.getName());
System.out.println(" Email: " + user.getEmail());
System.out.println(" Owner: " + user.getOwner());
System.out.println(" Roles: " + user.getRolesList());
System.out.println("User is ready for authentication with " + user.getRolesCount() + " assigned roles");
} catch (Exception e) {
System.err.println("CreateUser failed: " + e.getMessage());
e.printStackTrace();
}
}
}
Advanced Configuration​
For advanced client configuration options (custom endpoints, TLS settings, timeouts), see the SDK Configuration Guide.
Other Methods​
- Iam User v1 Method List - For Other methods