# Litmus UNS/Security - LE, LEM, LUNS API Docs

## Get Accounts

**POST** `{{uns_url}}/mqtt/gql`

list of generic MQTT accounts

### Request Body

**GraphQL Query**

```graphql
query Account {
    account {
        clients {
            id
            connected
            protoLevel
            remote
            lastSeen
        }
        id
        username
        acType
        enabled
        rules {
            id
            path
            perm
        }
    }
}
```

### Response

**Status**: 200 OK

```json
{
    "data": {
        "account": [
            {
                "clients": null,
                "id": "5ACB74CE-FFBF-43B2-87D2-E422931F6035",
                "username": "ide-ui",
                "acType": "General",
                "enabled": true,
                "rules": [
                    {
                        "id": "4F39EFA4-3A77-473C-906A-361FB2B5CB68",
                        "path": "bh",
                        "perm": "Sub"
                    },
                    {
                        "id": "E2FB1031-C2A8-4F65-B8B4-895F294E7295",
                        "path": "topicName",
                        "perm": "Sub"
                    },
                    {
                        "id": "86887A4B-E5A6-47DA-9AE6-8ABDA303DC4D",
                        "path": "topicName",
                        "perm": "Sub"
                    },
                    {
                        "id": "2A38CD43-DB5D-41BA-A9D7-E13CF347196F",
                        "path": "topicName",
                        "perm": "PubSub"
                    },
                    {
                        "id": "6F9793FB-645A-4DCE-8FD7-ABB213095A55",
                        "path": "topicName",
                        "perm": "PubSub"
                    }
                ]
            },
            {
                "clients": null,
                "id": "F5A9FA13-1781-4ADD-9C0E-D0463CCCD833",
                "username": "APIclient",
                "acType": "General",
                "enabled": true,
                "rules": null
            }
        ]
    }
}
```

---

## Create Account

**POST** `{{uns_url}}/mqtt/gql`

create a new account

### Request Body

**GraphQL Query**

```graphql
mutation accountCreate($input: AccountCreateInput!) {
    accountCreate(input: $input) {
        password
        account {
            username
            acType
        }
    }
}
```

**Variables**

```json
{
    "input": {
        "username": "{{uns_account_name}}",
        "acType": "General"
    }
}
```

### Response

**Status**: 200 OK

```json
{
    "data": {
        "accountCreate": {
            "password": "@A-uMa4GtC3YYMs_N",
            "account": {
                "username": "apiAccount",
                "acType": "General"
            }
        }
    }
}
```

---

## Account Details

**POST** `{{uns_url}}/mqtt/gql`

more details of an account

### Request Body

**GraphQL Query**

```graphql
query AccountDetails($input: UUID!) {
    account(id: $input) {
        clients {
            id
            connected
            protoLevel
            remote
            lastSeen
        }
        id
        username
        acType
        enabled
        rules {
            id
            path
            perm
        }
    }
}
```

**Variables**

```json
{
    "input": "{{uns_account_id}}"
}
```

### Response

**Status**: 200 OK

```json
{
    "data": {
        "account": [
            {
                "clients": null,
                "id": "F5A9FA13-1781-4ADD-9C0E-D0463CCCD833",
                "username": "APIclient",
                "acType": "General",
                "enabled": true,
                "rules": null
            }
        ]
    }
}
```

---

## Enable Account

**POST** `{{uns_url}}/mqtt/gql`

enable mentioned account

### Request Body

**GraphQL Query**

```graphql
mutation accountEnable($input: AccountEnableInput!) {
    accountEnable(input: $input) {
        account {
            username
            enabled
        }
    }
}
```

**Variables**

```json
{
    "input": {
        "acctId": "{{uns_account_id}}"
    }
}
```

### Response

**Status**: 200 OK

```json
{
    "data": {
        "accountEnable": {
            "account": {
                "username": "APIclient",
                "enabled": true
            }
        }
    }
}
```

---

## Disable Account

**POST** `{{uns_url}}/mqtt/gql`

disable mentioned account

### Request Body

**GraphQL Query**

```graphql
mutation accountDisable($input: AccountDisableInput!) {
    accountDisable(input: $input) {
        account {
            username
            enabled
        }
    }
}
```

**Variables**

```json
{
    "input": {
        "acctId": "{{uns_account_id}}"
    }
}
```

### Response

**Status**: 200 OK

```json
{
    "data": {
        "accountDisable": {
            "account": {
                "username": "APIclient",
                "enabled": false
            }
        }
    }
}
```

---

## Create LitmusEdge Activation Token

**POST** `{{uns_url}}/mqtt/gql`

create activation token for LE

### Request Body

**GraphQL Query**

```graphql
mutation CreateToken($input: CreateTokenRequest!) {
    createToken(input: $input) {
        token
    }
}
```

**Variables**

```json
{
    "input": {
        "accountId": null,
        "publicURL": "{{uns_url}}"
    }
}
```

### Response

**Status**: 200 OK

```json
{
    "data": {
        "createToken": {
            "token": "eyJvbmVUaW1lVG9rZW4iOiI3NzZhN2U0NS00MDAyLTQ3ZTMtOWVmZi1hYTNiYTNjNDI4YzkiLCJwdWJsaWNVUkwiOiJodHRwczovLzEwLjE3LjExLjkzL2FwaS92MS9qb2luIn0="
        }
    }
}
```

---

## Reset Account Password

**POST** `{{uns_url}}/mqtt/gql`

reset account password

This is used because the account password is shown only once, and there is no way to retreive it once copied

### Request Body

**GraphQL Query**

```graphql
mutation accountUpdate($input: AccountUpdateInput!) {
    accountUpdate(input: $input) {
        password
        account {
            username
            }
    }
}
```

**Variables**

```json
{
    "input": {
        "acctId": "{{uns_account_id}}"
    }
}
```

### Response

**Status**: 200 OK

```json
{
    "data": {
        "accountUpdate": {
            "password": "rdRXu-VwQgZDaZAWb",
            "account": {
                "username": "APIclient"
            }
        }
    }
}
```

---

## Add Account Rules

**POST** `{{uns_url}}/mqtt/gql`

add rule to an account

### Request Body

**GraphQL Query**

```graphql
mutation accountAddRules($input: AccountAddRulesInput!) {
    accountAddRules(input: $input) {
        account {
            id
            username
            rules {
                id
                path
                perm
            }
        }
    }
}
```

**Variables**

```json
{
    "input": {
        "acctId": "{{uns_account_id}}",
        "rules": [
            {
                "path": "{{uns_topic}}",
                "perm": "Sub"
            }
        ]
    }
}
```

### Response

**Status**: 200 OK

```json
{
    "data": {
        "accountAddRules": {
            "account": {
                "id": "F5A9FA13-1781-4ADD-9C0E-D0463CCCD833",
                "username": "APIclient",
                "rules": [
                    {
                        "id": "8A78DEB0-B7AE-4ED5-A7FB-2429E0977995",
                        "path": "apiTopic",
                        "perm": "Deny"
                    },
                    {
                        "id": "0FD2AB85-0B86-4081-B35A-80B266F6D2FF",
                        "path": "apiTopic",
                        "perm": "Deny"
                    }
                ]
            }
        }
    }
}
```

---

## Remove Account Rules

**POST** `{{uns_url}}/mqtt/gql`

remove rule/s from an account

### Request Body

**GraphQL Query**

```graphql
mutation accountRemoveRules($input: AccountRemoveRulesInput!) {
    accountRemoveRules(input: $input) {
        account {
            id
            username
            rules {
                id
                path
                perm
            }
        }
    }
}
```

**Variables**

```json
{
    "input": {
        "acctId": "{{uns_account_id}}",
        "ruleIds": [
            "320D4C1E-05DB-4E3E-9D40-99DE3F79AB94"
        ]
    }
}
```

### Response

**Status**: 200 OK

```json
{
    "data": {
        "accountRemoveRules": {
            "account": {
                "id": "F5A9FA13-1781-4ADD-9C0E-D0463CCCD833",
                "username": "APIclient",
                "rules": null
            }
        }
    }
}
```

---

## Remove Account

**POST** `{{uns_url}}/mqtt/gql`

remove an account

### Request Body

**GraphQL Query**

```graphql
mutation accountDelete($input: AccountDeleteInput!) {
    accountDelete(input: $input) {
        __typename
    }
}
```

**Variables**

```json
{
    "input": {
        "acctId": "{{uns_account_id}}"
    }
}
```

### Response

**Status**: 200 OK

```json
{
    "data": {
        "accountDelete": {
            "__typename": "AccountDeletePayload"
        }
    }
}
```

---

