> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# エコノミー

> Economy v2 のインベントリ アイテム、コレクション、トランザクションを調査および変更し、バッチ処理されたインベントリ操作を実行します。

`playfab economy inventory` を使用して、PlayFab Economy v2 のインベントリを読み取り、変更します。これには、
コレクション、トランザクション履歴、バッチ処理されたインベントリ操作が含まれます。

インベントリ コマンドは、`--entity-id` と `--entity-type` の両方を渡さない限り、呼び出し元のエンティティを
対象とします。プレイヤーの場合は、マスター プレイヤー アカウント ID ではなく、タイトル プレイヤー アカウント ID を
`--entity-type title_player_account` と共に渡します。この ID は、
[`playfab player account get`](https://docs.xbox.com/ja-jp/tools/xbox-cli/commands/playfab/player) から
`UserInfo.TitleInfo.TitlePlayerAccount.Id` として返されます。`--collection-id` は、`default` 以外のインベントリ
コレクションを選択します。

`operation execute` は、`--confirm` (`--yes`、`-y`) を渡さない限り、ターミナルであっても `Delete` 操作を含むバッチを
拒否します。その他のインベントリの変更は確認なしで実行されます。
[安全性と破壊的な操作](https://docs.xbox.com/ja-jp/tools/xbox-cli/safety.md)を参照してください。

## インベントリ アイテム

| コマンド | PlayFab API パス | オプション |
| - | - | - |
| `playfab economy inventory list` | `/Inventory/GetInventoryItems` | 省略可能な `--entity-id`、`--entity-type`、`--collection-id`、`--limit`、`--continuation-token`、`--filter`。 |
| `playfab economy inventory add` | `/Inventory/AddInventoryItems` | 省略可能な `--entity-id`、`--entity-type`、`--collection-id`、`--idempotency-id`。アイテムは、`--item-id` と省略可能な `--stack-id`、または `--item` で指定する `InventoryItemReference` JSON オブジェクトで指定します。`--amount` は数量を設定します。 |

* `inventory list` は、`--limit` 個のアイテム (既定では 10 個) を 1 ページとして返します。次のページを取得するには、
  応答の継続トークンを `--continuation-token` で渡します。
* `--filter` は、アイテムのプロパティ `type`、`id`、`stackId` に対する OData フィルターです。
* `inventory add` は、変更後のインベントリではなく、`ETag`、`IdempotencyId`、および記録した `TransactionIds` を
  返します。結果を確認するには、`inventory list` を実行します。

## インベントリ コレクション

| コマンド | PlayFab API パス | オプション |
| - | - | - |
| `playfab economy inventory collection list` | `/Inventory/GetInventoryCollectionIds` | 省略可能な `--entity-id`、`--entity-type`、`--limit`、`--continuation-token`。 |

## インベントリ操作

| コマンド | PlayFab API パス | オプション |
| - | - | - |
| `playfab economy inventory operation execute` | `/Inventory/ExecuteInventoryOperations` | 省略可能な `--entity-id`、`--entity-type`、`--collection-id`、`--idempotency-id`。操作は JSON 配列として、`--operations` または `--operations-file` のいずれか 1 つで指定します。 |
| `playfab economy inventory operation status` | `/Inventory/GetInventoryOperationStatus` | `--operation-token` (必須)。アイテムを譲渡したエンティティの `--entity-id` と `--entity-type`。省略可能な `--collection-id`。 |

`operation execute` は、バッチを 1 つのトランザクションとして実行します。`inventory add` と同様に、バッチ全体の
`ETag`、`IdempotencyId`、`TransactionIds` を返します。実行された内容を確認するには、`inventory list` または
`inventory transaction list` を実行します。

`operation status` は、要求が返された時点で完了していなかったインベントリの転送を確認します。
`TransferInventoryItems` と `ExecuteTransferOperations` は、`OperationStatus` が `InProgress` の間、
`OperationToken` を返します。そのトークンと、転送の `GivingEntity` を `--entity-id` と `--entity-type` として渡します。
CLI にはこれらの転送 API 用のコマンドがないため、[`playfab api`](https://docs.xbox.com/ja-jp/tools/xbox-cli/commands/playfab/api) で呼び出します。トランザクション ID は
操作トークンではなく、PlayFab はトランザクション ID を `Bad OperationToken.` で拒否します。

## インベントリ トランザクション

| コマンド | PlayFab API パス | オプション |
| - | - | - |
| `playfab economy inventory transaction list` | `/Inventory/GetTransactionHistory` | 省略可能な `--entity-id`、`--entity-type`、`--collection-id`、`--limit`、`--continuation-token`、`--filter`、`--order-by`。 |

`--filter` では、`timestamp`、`transactionid`、`apiname`、`operationtype` を参照できます。
`--order-by` には `timestamp asc` または `timestamp desc` を指定できます。

## 表形式の出力

次のコマンドは `--output table` を受け付けます。`inventory add` と `operation execute` は受け付けません。
[テーブル出力](https://docs.xbox.com/ja-jp/tools/xbox-cli/commands.md#table-output)を参照してください。

| コマンド | 列 |
| - | - |
| `playfab economy inventory list` | `ID`、`TYPE`、`STACK`、`AMOUNT` |
| `playfab economy inventory collection list` | `COLLECTION ID` |
| `playfab economy inventory transaction list` | `TRANSACTION ID`、`TIMESTAMP`、`API`、`OPERATION` |
| `playfab economy inventory operation status` | `STATUS` |

表には継続トークンが表示されないため、最初のページ以降を表示するには JSON 出力を
使用します。

```bash theme={null}
xbox --playfab-title-id ABC123 playfab economy inventory list --entity-id TITLEPLAYER123 --entity-type title_player_account --output table
```

```text theme={null}
ID                                    TYPE      STACK    AMOUNT
------------------------------------  --------  -------  ------
11111111-2222-3333-4444-555555555555  currency  default  500
22222222-3333-4444-5555-666666666666  bundle    default  1
```

## 例

1 人のプレイヤーのインベントリ、コレクション、トランザクション履歴を読み取ります。

```bash theme={null}
xbox --playfab-title-id ABC123 playfab economy inventory list --entity-id TITLEPLAYER123 --entity-type title_player_account --limit 50 --data-only --output json-compact
xbox --playfab-title-id ABC123 playfab economy inventory collection list --entity-id TITLEPLAYER123 --entity-type title_player_account
xbox --playfab-title-id ABC123 playfab economy inventory transaction list --entity-id TITLEPLAYER123 --entity-type title_player_account --order-by "timestamp desc"
```

プレイヤーのインベントリにアイテムを 1 つ追加します。

```bash theme={null}
xbox --playfab-title-id ABC123 playfab economy inventory add --entity-id TITLEPLAYER123 --entity-type title_player_account --item-id 11111111-2222-3333-4444-555555555555 --amount 1 --idempotency-id 22222222-3333-4444-5555-666666666666
```

`ops.json` のインベントリ操作のバッチを実行します。

```bash theme={null}
xbox --playfab-title-id ABC123 playfab economy inventory operation execute --entity-id TITLEPLAYER123 --entity-type title_player_account --operations-file ops.json --idempotency-id 33333333-4444-5555-6666-777777777777
```

`ops.json` に `Delete` 操作が含まれている場合は、`--confirm` を追加します。

```bash theme={null}
xbox --playfab-title-id ABC123 playfab economy inventory operation execute --entity-id TITLEPLAYER123 --entity-type title_player_account --operations-file ops.json --confirm
```

`"OperationStatus": "InProgress"` を返した転送を、その応答の `OperationToken` と、アイテムを譲渡した
プレイヤーを使用して確認します。

```bash theme={null}
xbox --playfab-title-id ABC123 playfab economy inventory operation status --entity-id TITLEPLAYER123 --entity-type title_player_account --operation-token OPERATIONTOKEN123
```


## Related topics

- [ファンデーション モード](https://docs.xbox.com/ja-jp/services/playfab/get-started/foundation-benefits.md)
- [PlayFab エコノミーとは?](https://docs.xbox.com/ja-jp/services/playfab/economy-monetization/economy-what-is.md)
- [PlayFab の基礎](https://docs.xbox.com/ja-jp/services/playfab/get-started/index.md)
- [XBOX サービス タイトル向け PlayFab インテグレーション](https://docs.xbox.com/ja-jp/services/xbox-services/playfab-integration.md)
- [Windows & ROG XBOX Ally 概要](https://docs.xbox.com/ja-jp/paths/windows/overview.md)
