Devices and Services

Remote.it Insomnia Collection

We have developed an example set of GraphQL queries and mutations in a collection that you can import directly into insomnia to get started. You will still need to install the authentication plug-in here and create your access keys in your account before getting started.

$ git clone https://github.com/remoteit/code_samples.git

Application Types

Application types are service type definitions which are used as parameters for Get Devices By An Attribute and in services. In the case of services only the ID is returned so you will reference this response.

query {
  applicationTypes {
   id
   name
   description
   port
   protocol
   proxy
  }
}

Response Example

{
  "data": {
    "applicationTypes": [
      {
        "id": 1,
        "name": "TCP",
        "description": "Generic TCP",
        "port": null,
        "protocol": "TCP",
        "proxy": false
      },
      {
        "id": 4,
        "name": "VNC",
        "description": "VNC remote desktop",
        "port": 5900,
        "protocol": "TCP",
        "proxy": false
      },
      ...
    ]
  }
}      

Get Your Devices

In this example we will be fetching your devices using graphQL. If you wish to get devices which meet a certain criteria like inactive devices, use the Attribute Query. Devices uses pagination for the result set. Please refer to the pagination explanation for more on working with these results.

This example only shows some of the variables and available attributes for the device and service collections.

#Query
query getDevices($size: Int, $from: Int, $sort: String) {
  login {
  # account(id:"######") {
  # use account when organization results are needed and the user credentials are not the org owner
  # org user results are based on permissions
    devices(size: $size, from: $from, sort: $sort) {
      total
      hasMore
      items {
        id
        name
        hardwareId
        created
        services {
          id
          name
        }
      }
    }
  }
  #} if org used
}
#Variables
{
  "size": 1000,
  "from": 0,
  "sort": 'name',
}

Response Example

{
  "data": {
    "login": {
      "devices": {
        "total": 1200,
        "hasMore": true,
        "items": [
          {
            "id": "8X:XX:XX:00:29:01:8e:ed",
            "name": "bento",
            "hardwareId": "dc:a6:32:19:8b:a3-xWoYf46uJ6QdtPXTloLb",
            "created": "2019-12-20T22:13:46.000Z",
            "services": [
              {
                "id": "8X:XX:XX:00:29:01:8e:ed",
                "name": "ssh service"
              }
            ]
          },
        ...
        ]
      }
    }
  }
}    

Parameters

Get Devices By An Attribute

In this example we will be fetching all devices with "tim" in the name using graphQL. This will return all devices with "tim" in the name and is not case sensitive. You can use any number of combinations of available attributes to narrow your result set further.

Other available parameters available:

Additional attributes will become available over time. Please refer to the schema documentation for the extensive list.

This example only shows some of the variables and available attributes for the device and service collections.

#Query
query getDevices($size: Int, $from: Int, $sort: String, $state: String, $name: String) {
  login {
    devices(size: $size, from: $from, sort: $sort, state: $state, name: $name) {
      total
      hasMore
      items {
        id
        name
        hardwareId
        created
        services {
          id
          name
        }
      }
    }
  }
}
#Variables
{
  "size": 1000,
  "from": 0,
  "sort": 'name',
  "state": "inactive",
  "name": "tim"
}

Once you get the results, if the hasMore response returns true you know to do another fetch and in this case the from will increment to 1001 to fetch the next set, you could also determine this by iteration until you get to the total. Size is limited to 1000 max in each return.

Response Example

{
  "data": {
    "login": {
      "devices": {
        "total": 1200,
        "hasMore": true,
        "items": [
          {
            "id": "8X:XX:XX:00:29:01:8e:ed",
            "name": "Bento Time Machine",
            "hardwareId": "dc:a6:32:19:8b:a3-xWoYf46uJ6QdtPXTloLb",
            "created": "2019-12-20T22:13:46.000Z",
            "services": [
              {
                "id": "8X:XX:XX:00:29:01:8e:ed",
                "name": "ssh service"
              }
            ]
          },
        ...
        ]
      }
    }
  }
}    

Update a Device/Service Name

Only the owner of the device or an admin on the organization owning the device can update the name of the device or service.

mutation {
  renameService(
    serviceId: "80:00:00:01:23:45:67:89",
    name: "New Name"
  )
}

Query Response

{
  "data": {
    "renameService": true
  }
}

Update a Device or Service

Only the owner of the device or an admin on the organization owning the device can update a device.

mutation {
    updateDevice(
     deviceId: "80:00:00:98:01:23:45:67",
     refresh: true,
     name: "New Name",
     port: 22
    )
}

Query Response

{
  "data": {
    "updateDevice": true
  }
}

Delete Device

Only the owner of the device or an admin on the organization owning the device can delete a device. Devices can only be deleted when the state is inactive.

mutation {
  deleteDevice(
    deviceId: "80:00:00:98:01:23:45:67"
  )
}

Query Response

{
  "data": {
    "deleteDevice": true
  }
}

Remove a Service

Only the owner of the device or an admin on the organization owning the device can remove a service from a device.

Services will be removed even if active and in use

mutation {
  removeService(
    id:"80:00:00:98:01:23:45:67"
    )
}

Query Response

{
  "data": {
    "removeService": true
  }
}

Last updated