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

# Bulk delete devices with the Public API

> Search for devices with the Public API to collect their IDs, and then delete multiple devices at once.

> [!NOTE]
>
> A Device management plan is required to use the device management feature. If you have 50 or fewer IDs, the Device management plan is also free. To request a trial or free use, contact us via **Ask a support representative directly** in the chat.

## Overview

Bulk delete on the Devices screen deletes up to 50 devices at a time. Use the [Public API](https://support.i.moneyforward.com/en/it-management/faq/cw1ivgng0g-admina-api.md) to delete more devices at once. You can also find devices by a condition, such as the user's email address, and delete them.

You use the following two APIs.

| Purpose | API |
| - | - |
| Search for devices and collect the IDs of the devices to delete | [Search devices for an organization](https://support.i.moneyforward.com/api-reference/it-management/devices/search-devices-for-an-organization.md) |
| Delete the devices with the collected IDs at once | [Delete multiple devices of an organization](https://support.i.moneyforward.com/api-reference/it-management/devices/delete-multiple-devices-of-an-organization.md) |

> [!NOTE]
>
> Deleting an MDM integration workspace does not delete the devices imported from that workspace. They remain in the device list.

## Before you begin

1. Create an API key in **Settings** > **API Keys**. For the steps, see [Generating an API Key](https://support.i.moneyforward.com/en/it-management/faq/cw1ivgng0g-admina-api.md#generate-api-key).
2. Check the **Organization ID** in **Settings** > **API Keys**. For the steps, see [Finding your Organization ID](https://support.i.moneyforward.com/en/it-management/faq/cw1ivgng0g-admina-api.md#organization-id).
3. Before you delete devices, export the device list as a CSV file and keep it as a backup. For the steps, see [Device Export](https://support.i.moneyforward.com/en/it-management/device/erfxlknd5e-1-devices.md#device-export).

For how to authenticate API requests, see [Authentication](https://support.i.moneyforward.com/en/api-reference/it-management/authentication.md).

## Step 1. Collect the IDs of the devices to delete

Use [Search devices for an organization](https://support.i.moneyforward.com/api-reference/it-management/devices/search-devices-for-an-organization.md) to search for the devices to delete. The following example searches for devices whose user's email address (`people.primaryEmail`) contains "@example.com".

```bash theme={null}
curl -X POST "https://api.itmc.i.moneyforward.com/api/v1/organizations/<ORGANIZATION_ID>/devices/search?limit=50" \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"searchTerm": "@example.com", "searchFields": ["people.primaryEmail"]}'
```

* `items[].id` in the response is the device ID.
* If `meta.nextCursor` in the response has a value, more results remain. Add `&cursor=<value of nextCursor>` to the URL and send the same request again. Replace `+` with `%2B`, `/` with `%2F`, and `=` with `%3D` in the value. Repeat until `meta.nextCursor` is `null`.
* Compare the collected IDs with the exported CSV file. Make sure that no device that must be kept is included.

## Step 2. Delete the devices at once

Use [Delete multiple devices of an organization](https://support.i.moneyforward.com/api-reference/it-management/devices/delete-multiple-devices-of-an-organization.md) to delete the devices with the collected IDs. Specify the IDs of the devices to delete in `deviceIds`.

> [!WARNING]
>
> Deleting a device also deletes its usage history, and you cannot undo it.

```bash theme={null}
curl -X DELETE "https://api.itmc.i.moneyforward.com/api/v1/organizations/<ORGANIZATION_ID>/devices" \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"deviceIds": [101, 102, 103]}'
```

You can specify up to 100 IDs in one request. If you have more than 100 IDs, split them into groups of 100 and send a request for each group. For the limits on API calls, see [IT Management API rate limits](https://support.i.moneyforward.com/en/api-reference/it-management/rate-limits.md).

> [!NOTE]
>
> * If even one ID does not exist, no device is deleted and the request returns an error. IDs of devices that are already deleted and duplicate IDs are treated the same way.

## Step 3. Check the result

On the Devices screen, make sure that the deleted devices no longer appear in the list. Deletions made with the API are recorded in the [audit log](https://support.i.moneyforward.com/en/it-management/faq/3kr059fq2z-auditlog.md).

## Related pages

* [Device management overview](https://support.i.moneyforward.com/en/it-management/device/tmkn2wxi35-manage-device.md)
* [Use the Public API](https://support.i.moneyforward.com/en/it-management/faq/cw1ivgng0g-admina-api.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.