Magistrala
Dev GuideServices

Clients

Client management service for Magistrala — provision devices and applications, manage credentials, connect them to channels, and control access via role-based policies.

The Clients service manages the devices and applications that connect to Magistrala. A client represents any entity that publishes or subscribes to messages. The service handles client provisioning, credential management, channel connections, and role-based access control. It exposes both HTTP and gRPC APIs.

Configuration

VariableDescriptionDefault
MG_CLIENTS_LOG_LEVELLog level (debug, info, warn, error)info
MG_CLIENTS_HTTP_HOSTHTTP hostlocalhost
MG_CLIENTS_HTTP_PORTHTTP port9006
MG_CLIENTS_GRPC_HOSTgRPC hostlocalhost
MG_CLIENTS_GRPC_PORTgRPC port7000
MG_CLIENTS_DB_HOSTDatabase hostlocalhost
MG_CLIENTS_DB_PORTDatabase port5432
MG_CLIENTS_DB_USERDatabase usermagistrala
MG_CLIENTS_DB_PASSDatabase passwordmagistrala
MG_CLIENTS_DB_NAMEDatabase nameclients
MG_CLIENTS_DB_SSL_MODESSL mode (disable, require, verify-ca, verify-full)disable
MG_CLIENTS_CACHE_URLRedis cache URLredis://localhost:6379/0
MG_CLIENTS_CACHE_KEY_DURATIONCache TTL in seconds3600
MG_CLIENTS_ES_URLEvent store URLlocalhost:6379
MG_AUTH_GRPC_URLAuth service gRPC URLlocalhost:7001
MG_AUTH_GRPC_TIMEOUTAuth gRPC timeout1s
MG_JAEGER_URLJaeger tracing endpointhttp://jaeger:4318/v1/traces
MG_SEND_TELEMETRYSend telemetry to Magistrala call-home servertrue

Standalone mode: set MG_CLIENTS_STANDALONE_ID and MG_CLIENTS_STANDALONE_TOKEN to run without the Auth service (useful for edge deployments).

Database Schema

clients table

ColumnTypeDescription
idVARCHAR(36)UUID primary key
nameVARCHAR(1024)Human-readable name
domain_idVARCHAR(36)Owning domain
parent_group_idVARCHAR(36)Optional parent group for hierarchical scoping
identityVARCHAR(254)Login identity
secretVARCHAR(4096)Hashed authentication secret
tagsTEXT[]Arbitrary tags
metadataJSONBFree-form structured metadata
statusSMALLINT0 = enabled, 1 = disabled

connections table

ColumnTypeDescription
channel_idVARCHAR(36)Channel UUID
domain_idVARCHAR(36)Domain of both client and channel
client_idVARCHAR(36)Client UUID
typeSMALLINT1 = Publish, 2 = Subscribe

Deployment

git clone https://github.com/absmach/magistrala
cd magistrala

make clients
make install

MG_CLIENTS_LOG_LEVEL=info \
MG_CLIENTS_HTTP_HOST=localhost \
MG_CLIENTS_HTTP_PORT=9006 \
MG_CLIENTS_DB_HOST=localhost \
MG_CLIENTS_DB_PORT=5432 \
MG_CLIENTS_DB_USER=magistrala \
MG_CLIENTS_DB_PASS=magistrala \
MG_CLIENTS_DB_NAME=clients \
MG_CLIENTS_CACHE_URL=redis://localhost:6379/0 \
MG_AUTH_GRPC_URL=localhost:7001 \
$GOBIN/magistrala-clients

HTTP API

Base URL defaults to http://localhost:9006. All endpoints require Authorization: Bearer <token> and a <domainID> path prefix.

OperationDescription
createProvision one or more clients
getRetrieve a client by ID
listPage and filter clients in a domain
updateUpdate name, metadata, or tags
deletePermanently remove a client
enable / disableToggle client active state
set-parent-groupAssign a parent group
remove-parent-groupDetach from parent group
create-roleCreate an RBAC role for the client
list-rolesList all roles on a client
add-role-memberAdd users to a client role

Create a client

curl -X POST "http://localhost:9006/<domainID>/clients" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "temperature-sensor-01",
    "tags": ["edge", "sensor"],
    "metadata": { "model": "DS18B20", "location": "warehouse" }
  }'

List clients

curl "http://localhost:9006/<domainID>/clients?limit=10&status=enabled" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

Update a client

curl -X PATCH "http://localhost:9006/<domainID>/clients/<clientID>" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "name": "updated-name", "metadata": { "firmware": "v2.1" } }'

Disable a client

curl -X POST "http://localhost:9006/<domainID>/clients/<clientID>/disable" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

Health check

curl http://localhost:9006/health

Best Practices

  • Use metadata for device attributes (model, firmware version, location) to enable rich filtering.
  • Rotate client secrets periodically; use disable rather than delete when decommissioning temporarily.
  • Prefer standalone mode for edge deployments where the Auth service is not reachable.
  • Review client roles and channel connections regularly to audit access.

For the full API reference, see the API documentation.

On this page