> For the complete documentation index, see [llms.txt](https://innoway.gitbook.io/innoway/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://innoway.gitbook.io/innoway/tai-lieu/sdk/device.md).

# Device

## Function

### IdentifyInfoByKey

Kiểm tra thiết bị với **key** tương ứng có tồn tại trong dự án hay không. Trả về [DeviceInfo](#deviceinfo)

{% code fullWidth="false" %}

```typescript
Device().IdentifyInfoByKey({key: string})
```

{% endcode %}

<details>

<summary>Ví dụ</summary>

```typescript
let res = await Device().IdentifyInfoByKey({ key: '0000000'});
if (res.success){
  // Thiết bị tồn tại 
  let deviceInfo = res.data;
}else{
  // Thiết bị không tồn tại
}
```

</details>

### IdentifyInfoByKeyWithAd

Kiểm tra thiết bị với thông tin **key**, **projectId** có tồn tại hay không. Trả về [DeviceInfo](#deviceinfo)

```typescript
Device().IdentifyInfoByKeyWithAd({key: string, projectId: string})
```

<details>

<summary>Ví dụ</summary>

```typescript
let res = await Device().IdentifyInfoByKeyWithAd({ key: '0000000', projectId: 'c53f1597-d04a-470f-9f76-3c40a11e43b2'});
if (res.success){
  // Thiết bị tồn tại
  let deviceInfo = res.data;
}else{
  // Thiết bị không tồn tại
}
```

</details>

### CreateDevice

Tạo thiết bị với các thông tin tương ứng, trường **name** bắt buộc, còn lại có thể để trống. Nếu tìm thấy trả về [DeviceInfo](#deviceinfo), nếu không Throw Exception

<pre class="language-typescript"><code class="lang-typescript"><strong>Device().CreateDevice({name: string, key: string, templateId: string, orgId: string, groupId: string})
</strong></code></pre>

{% hint style="info" %}
Có thể dùng trường key để lưu định danh thiết bị (imei, serial,...)
{% endhint %}

<details>

<summary>Ví dụ</summary>

```typescript
let createDevice = await Device().CreateDevice({ name: 'new_device', key: '00000');
if (createDevice.success){
  // Tạo thiết bị thành công
  let deviceInfo = createDevice.data;
}else{
  // Tạo thiết không bị thành công
}
```

</details>

### IdentifyInfo

Tìm thiết bị với id tương ứng. Nếu tìm thấy trả về [DeviceInfo](#deviceinfo), nếu không Throw Exception

<pre class="language-typescript"><code class="lang-typescript"><strong>Device().IdentifyInfo({id: string})
</strong></code></pre>

<details>

<summary>Ví dụ</summary>

```typescript
let res = await Device().IdentifyInfo({id: 'c53f1597-d04a-470f-9f76-3c40a11e43b2'})
if (res.success){
  // Thiết bị tồn tại
  deviceInfo = res.data;
}else{
  // Thiết bị không tồn tại
}
```

</details>

## Type

### DeviceInfo

```typescript
{
    id: string,
    name: string,
    owner: string,
    group: string,
    groupname: string,
    type: string,
    typename: string,
    status: string,
    metadata: Uint8Array | string,
    variablesList: Array<string>,
    orgid: string,
    orgname: string,
    createby: string,
    projectid: string,
    templateid: string,
    key: string,
    thingid: string,
    handlemsgsvc: string,
    additionalinfo: Uint8Array | string,
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://innoway.gitbook.io/innoway/tai-lieu/sdk/device.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
