> 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/release-note/25-04-2025/attributes.md).

# Attributes

## UpsertAttributes

Lưu attributes với **key**, **value** vào thiết bị với **id** tương ứng

<pre class="language-typescript"><code class="lang-typescript"><strong>Thing(id: string).UpsertAttributes(attrs: {[key: string]: any}, {logged: boolean})
</strong></code></pre>

<details>

<summary>Ví dụ</summary>

```typescript
var attrs = {};
let logged = false
attrs['Led'] = 'ON;
await Thing('036116ed-38fc-458b-b91f-b3f774706247').UpsertAttributes(attrs, {logged: logged});

```

</details>

## GetAttributesLatest

Lấy giá trị của các attributes với **keys** của thiết bị với **id** tương ứng, trả về [entitiesList](#entitieslist)

```typescript
GetAttributesLatest(req: {keys: string[], ids: string[], entityType: string})
```

<details>

<summary>Phiên bản cũ</summary>

```typescript
let arrayKeys = ["led", "data"];
let arrayIDs = ["bba8dd8e-4932-11ee-be56-0242ac120002", "c6134e44-4932-11ee-be56-0242ac120002"]
let data = await Things().GetAttributesLatest({ ids: arrayIDs, entityType: "DEVICE", keys: arrayKeys });
```

</details>

<details>

<summary>Phiên bản mới</summary>

```typescript
let arrayKeys = ["led", "data"];
let arrayIDs = ["bba8dd8e-4932-11ee-be56-0242ac120002", "c6134e44-4932-11ee-be56-0242ac120002"]
let res = await Things().GetAttributesLatest({ ids: arrayIDs, entityType: "DEVICE", keys: arrayKeys });
if (res.success){
  // Lấy dữ liệu thành công
}else{
  // Lấy dữ liệu tthất bại hoặc không tồn tại
}
```

</details>

## Type

### entitiesList

<pre class="language-typescript"><code class="lang-typescript"><strong>{
</strong><strong>    entitiesList: entity[];
</strong><strong>}
</strong></code></pre>

### entity

```typescript
{
    attributesList: attribute[];
    entityId: string;
    entityType: string;
}
```

### attribute

```typescript
{
    key: string;
    logged: boolean;
    ts: number;
    value: string | Uint8Array;
    valueAsString: string;
    valueType: string
}
```
