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

Upload a file attachment directly to an object:

mutation UploadAttachment(
  $objectType: String!,
  $objectId: String!,
  $fileName: String!,
  $file: String!,
  $contentType: String,
  $description: String
) {
  uploadFileAttachment(uploadFileAttachmentInput: {
    objectType: $objectType,
    objectId: $objectId,
    fileName: $fileName,
    file: $file,
    contentType: $contentType,
    description: $description
  })
}

The mutation returns the UUID of the created attachment.

Input FieldTypeRequiredDescription
objectTypeStringYesType of object (e.g., “device”, “asset”, “space”)
objectIdStringYesUUID of the parent object
fileNameStringYesName of the file
fileStringYesBase64 encoded file content
contentTypeStringNoMIME type of the file
descriptionStringNoOptional description

User Management

(Available to Organization Manager role)

Create User

mutation CreateUser($email: String!, $organizationId: String, $password: String) {
  createUser(createUserInput: {
    email: $email,
    organizationId: $organizationId,
    password: $password
  }) {
    id
    email
    organizationId
    createdAt
  }
}
Input FieldTypeRequiredDescription
emailStringYesUser’s email address
organizationIdStringNoOrganization to assign user to
passwordStringNoInitial password (auto-generated if not provided)

Delete User

mutation DeleteUser($userId: String!) {
  deleteUser(deleteUserInput: {
    userId: $userId
  }) {
    message
  }
}

Change User Password

mutation ChangePassword($currentPassword: String!, $newPassword: String!) {
  changeUserPassword(changeUserPasswordInput: {
    currentPassword: $currentPassword,
    newPassword: $newPassword
  }) {
    message
  }
}

Integration & API Key Management

Manage MQTT streaming integrations and API keys programmatically. For a complete step-by-step walkthrough, see the MQTT API Key Management Guide.

Create MQTT Subscription Integration

mutation CreateMqttIntegration($description: String) {
  createMqttSubscriptionIntegration(object: {
    description: $description,
    mqttSubscriptionState: "active"
  }) {
    id
    description
    mqttSubscriptionState
    organizationId
    createdAt
    updatedAt
  }
}

Create API Key

The token is only returned at creation time and expires after 90 days.

mutation CreateApiKey($name: String!) {
  createApiKey(createApiKeyInput: {
    name: $name
  }) {
    id
    name
    organizationId
    createdAt
    token {
      token
      issuedAt
      expiresAt
    }
  }
}

Assign API Key Role

mutation AssignApiKeyRole($apiKeyId: uuid!) {
  assignApiKeyOrganizationRole(object: {
    roleName: "MqttIntegrator",
    apiKeyId: $apiKeyId
  }) {
    apiKeyId
    roleName
    organizationId
  }
}
mutation AssignApiKeyToMqttIntegration($mqttSubscriptionId: uuid!, $apiKeyId: uuid!) {
  assignMqttSubscriptionIntegrationApiKey(object: {
    mqttSubscriptionId: $mqttSubscriptionId,
    apiKeyId: $apiKeyId
  }) {
    mqttSubscriptionId
    apiKeyId
  }
}

Refresh API Key Token

Regenerate the token before the 90-day expiration. The key ID stays the same.

mutation RefreshApiKey($apiKeyId: uuid!) {
  refreshApiKeyToken(refreshApiKeyTokenInput: {
    apikeyId: $apiKeyId
  }) {
    id
    organizationId
    token {
      token
      issuedAt
      expiresAt
    }
  }
}

Delete API Key

mutation DeleteApiKey($apiKeyId: uuid!) {
  deleteApiKey(deleteApiKeyInput: {
    apikeyId: $apiKeyId
  }) {
    message
  }
}

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