# Magistrala CLI ## Build From the project root: ```bash make cli ``` ## Usage ### Service #### Get Magistrala Services Health Check ```bash magistrala-cli health ``` ### Users management #### Create User ```bash magistrala-cli users create magistrala-cli users create ``` #### Login User ```bash magistrala-cli users token ``` #### Get User ```bash magistrala-cli users get ``` #### Get Users ```bash magistrala-cli users get all ``` #### Update User Metadata ```bash magistrala-cli users update '{"name":"value1", "metadata":{"value2": "value3"}}' ``` #### Update User Password ```bash magistrala-cli users password ``` #### Enable User ```bash magistrala-cli users enable ``` #### Disable User ```bash magistrala-cli users disable ``` ### System Provisioning #### Create Client ```bash magistrala-cli clients create '{"name":"myClient"}' ``` #### Create Client with metadata ```bash magistrala-cli clients create '{"name":"myClient", "metadata": {"key1":"value1"}}' ``` #### Update Client ```bash magistrala-cli clients update '{"name":"value1", "metadata":{"key1": "value2"}}' ``` #### Identify Client ```bash magistrala-cli clients identify ``` #### Enable Client ```bash magistrala-cli clients enable ``` #### Disable Client ```bash magistrala-cli clients disable ``` #### Get Client ```bash magistrala-cli clients get ``` #### Get Clients ```bash magistrala-cli clients get all ``` #### Get a subset list of provisioned Clients ```bash magistrala-cli clients get all --offset=1 --limit=5 ``` #### Create Channel ```bash magistrala-cli channels create '{"name":"myChannel"}' ``` #### Bulk Provision Channels ```bash magistrala-cli provision channels ``` - `file` - A CSV or JSON file containing channel names (must have extension `.csv` or `.json`) - `user_token` - A valid user auth token for the current system An example CSV file might be: ```csv , , , ``` in which the first column is channel names. A comparable JSON file would be ```json [ { "name": "", "description": "", "status": "enabled" }, { "name": "", "description": "", "status": "disabled" }, { "name": "", "description": "", "status": "enabled" } ] ``` With JSON you can be able to specify more fields of the channels you want to create #### Update Channel ```bash magistrala-cli channels update '{"id":"","name":"myNewName"}' ``` #### Enable Channel ```bash magistrala-cli channels enable ``` #### Disable Channel ```bash magistrala-cli channels disable ``` #### Get Channel ```bash magistrala-cli channels get ``` #### Get Channels ```bash magistrala-cli channels get all ``` #### Get a subset list of provisioned Channels ```bash magistrala-cli channels get all --offset=1 --limit=5 ``` ### Access control #### Connect Client to Channel ```bash magistrala-cli clients connect ``` #### Bulk Connect Clients to Channels ```bash magistrala-cli provision connect ``` - `file` - A CSV or JSON file containing client and channel ids (must have extension `.csv` or `.json`) - `user_token` - A valid user auth token for the current system An example CSV file might be ```csv , , ``` in which the first column is client IDs and the second column is channel IDs. A connection will be created for each client to each channel. This example would result in 4 connections being created. A comparable JSON file would be ```json { "client_ids": ["", ""], "group_ids": ["", ""] } ``` #### Disconnect Client from Channel ```bash magistrala-cli clients disconnect ``` #### Get a subset list of Channels connected to Client ```bash magistrala-cli clients connections ``` #### Get a subset list of Clients connected to Channel ```bash magistrala-cli channels connections ``` ### Messaging #### Send a message over HTTP ```bash magistrala-cli messages send '[{"bn":"Dev1","n":"temp","v":20}, {"n":"hum","v":40}, {"bn":"Dev2", "n":"temp","v":20}, {"n":"hum","v":40}]' ``` ### Groups #### Create Group ```bash magistrala-cli groups create '{"name":"","description":"","parentID":"","metadata":""}' ``` #### Get Group ```bash magistrala-cli groups get ``` #### Get Groups ```bash magistrala-cli groups get all ``` #### Get Group Members ```bash magistrala-cli groups members ``` #### Get Memberships ```bash magistrala-cli groups membership ``` #### Assign Members to Group ```bash magistrala-cli groups assign ``` #### Unassign Members to Group ```bash magistrala-cli groups unassign ``` #### Enable Group ```bash magistrala-cli groups enable ``` #### Disable Group ```bash magistrala-cli groups disable ```