Mutations

GraphQL mutations for device configuration and management

Overview

Mutations allow you to create, update, and delete resources in Haltian IoT. Available mutations depend on your user role.

Device Management

Update Device Name

mutation UpdateDeviceName($id: uuid!, $name: String!) {
  updateDevice(pk_columns: {id: $id}, _set: {name: $name}) {
    id
    name
    updatedAt
  }
}

Assign Device to Space

mutation AssignDeviceToSpace($deviceId: uuid!, $spaceId: uuid!) {
  updateDevice(pk_columns: {id: $deviceId}, _set: {spaceId: $spaceId}) {
    id
    spaceId
    updatedAt
  }
}

Space Management

Create Space

mutation CreateSpace($name: String!, $spaceType: String!, $parentId: uuid, $organizationId: uuid!) {
  insertSpace(object: {
    name: $name,
    spaceType: $spaceType,
    parentId: $parentId,
    organizationId: $organizationId
  }) {
    id
    name
    spaceType
    createdAt
  }
}

Update Space

mutation UpdateSpace($id: uuid!, $name: String!) {
  updateSpace(pk_columns: {id: $id}, _set: {name: $name}) {
    id
    name
    updatedAt
  }
}

Asset Management

Create Asset

mutation CreateAsset($name: String!, $assetType: String!, $spaceId: uuid!) {
  insertAsset(object: {
    name: $name,
    assetType: $assetType,
    spaceId: $spaceId
  }) {
    id
    name
    assetType
    createdAt
  }
}

Assign Device to Asset

mutation AssignDeviceToAsset($assetId: uuid!, $deviceId: uuid!) {
  insertAssetDevice(object: {
    assetId: $assetId,
    deviceId: $deviceId
  }) {
    assetId
    deviceId
  }
}

File Attachments

Haltian IoT API supports file attachments for various objects.

Attachment Types

ObjectUse Case
DeviceInstallation images, videos
AssetThumbnail, avatar
SpaceFloorplan images
OrganizationLogo

Upload Attachment

  1. Request a pre-signed upload URL:
mutation GetUploadUrl($objectType: String!, $objectId: uuid!, $filename: String!) {
  generateUploadUrl(input: {
    objectType: $objectType,
    objectId: $objectId,
    filename: $filename
  }) {
    uploadUrl
    expiresAt
  }
}
  1. Upload the file to the pre-signed URL using HTTP PUT

Download Attachment

Request a pre-signed download URL:

mutation GetDownloadUrl($objectType: String!, $objectId: uuid!, $filename: String!) {
  generateDownloadUrl(input: {
    objectType: $objectType,
    objectId: $objectId,
    filename: $filename
  }) {
    downloadUrl
    expiresAt
  }
}

User Management

(Available to Organization Manager role)

Create User

mutation CreateUser($email: String!, $role: String!, $organizationId: uuid!) {
  insertUser(object: {
    email: $email,
    role: $role,
    organizationId: $organizationId
  }) {
    id
    email
    role
    createdAt
  }
}

Update User Role

mutation UpdateUserRole($userId: uuid!, $role: String!) {
  updateUser(pk_columns: {id: $userId}, _set: {role: $role}) {
    id
    email
    role
    updatedAt
  }
}

Best Practices

  1. Validate inputs before submitting mutations
  2. Handle errors gracefully - check for validation errors in the response
  3. Use transactions when multiple related changes are needed
  4. Refresh data after mutations to ensure UI consistency
  5. Log changes for audit purposes

Role-Based Access

Mutation availability depends on your role:

RoleAvailable Mutations
ManagerAll mutations
DesignerSpace and asset management
InstallerDevice assignment, limited updates
ViewerNone (read-only)

Next Steps