Skip to content

Table Operation: Bulk Delete Record

Overview

You can delete records using the API.

Preparations

Please Create an API Key before performing API operations.

Cautions

This function deletes records and information.
Please pay close attention to the records to be deleted and the deletion conditions.
We recommend that you follow the steps below to delete records.

(1) Retrieve Records Scheduled for Deletion

(2) Transcribe delete records and delete column from retrieved records and create a bulk delete API request.
(Check here if you want to use view column)

(3) Check the PhysicalDelete option (if set to true, the deletion records will be deleted from the _deleted and _history tables for time-limited tables, and they will no longer be able to be restored)

Request

Please send json data in the following format.

Setting column Value
HTTP Method POST
Content-Type application/json
Character Code UTF-8
URL http://{server name}/pleasanter/api/items/{site ID}/bulkdelete (*1)

(*1) Edit the "http://{server name}/pleasanter" part to suit your environment as appropriate, and replace "{site ID}" with the ID of the site where the record you want to delete is registered.
(For Pleasanter.net, https://pleasanter.net/fs/api/items/{site ID}/bulkdelete)

Settings

These settings can also be specified for Developer's Guide: Script: $p.apiBulkDelete and Developer's Guide: Server Script: items.BulkDelete.

Parameter Type Required Description
ApiVersion decimal API version.
ApiKey string *1 API key created in advance.
View object Specify when setting conditions for the records to bulk delete. See below for details.
Selected object Specify the IDs of the records to delete in array format.
All bool Set to true to bulk delete all records in the table.
PhysicalDelete bool Set to true to also delete the records from the change history and the recycle bin at the same time as deleting them.

*1: The API key is required for the API. It is optional for scripts and server scripts. If specified, the process is executed with the permissions of the user of the API key.

View

Parameter Type Required Description
ColumnFilterHash object Conditions for the records to bulk delete. For details, see Developer's Guide: JSON Data Layout: View.

Usage Examples

1. When physically deleting records narrowed down by column conditions

Set View: {description of ColumnFilterHash}.
Set PhysicalDelete: true.

JSON

{
    "ApiVersion": 1.1,
    "ApiKey": "XXXXX...",
    "view": {
        "ColumnFilterHash": {
            "Status": "[100,910]"
        }
    },
    "PhysicalDelete": true
}

2. When selecting and deleting multiple records (delete the records with record IDs 135,376)

Set Selected: [target IDs].

JSON

{
    "ApiVersion": 1.1,
    "ApiKey": "XXXXX...",
    "Selected": [
        135,
        376
    ]
}

3. When deleting all records in the target table

Set All: true.

JSON

{
    "ApiVersion": 1.1,
    "ApiKey": "XXXXX...",
    "All": true
}

Response

The following json data will be returned.

Return Value

Parameter Type Required Description
Id long Yes ID of the record table or time-limited table targeted for bulk deletion.
StatusCode int Yes Status code of the execution result.
Message string Yes Message of the execution result.

Execution Result Example

1. When bulk deleting (moving to the recycle bin) records registered in the table with site ID 46010

JSON

{
    "Id": 46010,
    "StatusCode": 200,
    "Message": "3 column deleted."
}

2. When physically deleting records registered in the table with site ID 46010

JSON

{
    "Id": 46010,
    "StatusCode": 200,
    "Message": "2 column physically deleted."
}

Code Samples

Modify 【 ... 】 in the code as necessary.
1. Get the records to delete, and then bulk delete them by specifying their IDs.

Gets the records to delete (Status=910 in this sample), sets their IDs in the bulkdelete request, and deletes them.

Python(api_record_bulkdelete_p1.py)
# Library for communicating with websites and APIs
import requests

# Library for JSON operations
import json

# Server name and API key
BASE_URL = (
    "【URL】"
)
API_KEY = "【API key】"

# Site ID to start the search from
START_SITE_ID = 【Site ID】

# Target site name and status to delete
TARGET_SITE_NAME = "Project Management"
TARGET_STATUS = '["910"]'  # On hold (910)

# Set to True to delete physically (including history and the recycle bin)
PHYSICAL_DELETE = False

# Share the session
session = requests.Session()
session.headers.update({"Content-Type": "application/json"})

# Common function for JSON POST requests
def post_json(url: str, payload: dict) -> dict:
    r = session.post(url, data=json.dumps(payload))
    if not r.ok:
        raise RuntimeError(f"HTTP {r.status_code} {url}\n{r.text}")
    return r.json()

# 1) Get the SiteId from the site name
getclosest_url = f"{BASE_URL}/api/items/{START_SITE_ID}/getclosestsiteid"
closest_payload = {
    "ApiVersion": 1.1,
    "ApiKey": API_KEY,
    "FindSiteNames": [TARGET_SITE_NAME],
}

closest_res = post_json(getclosest_url, closest_payload)
data_list = closest_res.get("Data", [])
if not data_list:
    print(f"{TARGET_SITE_NAME} Failed to get the site information")
    raise SystemExit()

site_id = data_list[0].get("SiteId")
if not isinstance(site_id, int) or site_id <= 0:
    print(f"{TARGET_SITE_NAME} Invalid site ID: {site_id}")
    raise SystemExit()

print(f"Got the target site ID: {site_id}")

# 2) Get the records with Status=910 (to check the records to delete)
get_url = f"{BASE_URL}/api/items/{site_id}/get"
get_payload = {
    "ApiVersion": 1.1,
    "ApiKey": API_KEY,
    "View": {
        "ColumnFilterHash": {
            "Status": TARGET_STATUS,
        }
    },
}

get_res = post_json(get_url, get_payload)

rows = []
if isinstance(get_res, dict):
    rows = (get_res.get("Response", {}) or {}).get("Data", []) or []
elif isinstance(get_res, list):
    rows = get_res

if not rows:
    print("No data to delete")
    raise SystemExit()

# 3) Bulk delete the retrieved record IDs together (with Selected)
record_ids = []
for row in rows:
    rid = row.get("ResultId") or row.get("Id")
    if isinstance(rid, int) and rid > 0:
        record_ids.append(rid)

# Remove duplicates just in case
record_ids = sorted(set(record_ids))

if not record_ids:
    print("Could not get the IDs to delete")
    raise SystemExit()

bulkdelete_url = f"{BASE_URL}/api/items/{site_id}/bulkdelete"
bulkdelete_payload = {
    "ApiVersion": 1.1,
    "ApiKey": API_KEY,
    "Selected": record_ids,  # <- Specify an array of IDs to bulk delete
    "PhysicalDelete": PHYSICAL_DELETE,
}

try:
    bulk_res = post_json(bulkdelete_url, bulkdelete_payload)
    # Example of the bulkdelete response: { Id: <siteId>, StatusCode: 200, Message: "..." }
    print("bulkdelete result:", bulk_res)
except Exception as e:
    print("bulkdelete failed")
    print(e)
Run
>python api_record_bulkdelete_p1.py
Execution Result
Got the target site ID: 9999
bulkdelete result: {'Id': 9999, 'StatusCode': 200, 'Message': 'Project Management: 5 items have been deleted at once.'}
2. Filter the records to delete and bulk delete them.

Filters the records to delete (Status=910 in this sample) and runs bulkdelete.

Python(api_record_bulkdelete_p2.py)
# Library for communicating with websites and APIs
import requests

# Library for JSON operations
import json

# Server name and API key
BASE_URL = "【URL】"
API_KEY = "【API key】"

# Site ID to start the search from
START_SITE_ID = 6429

# Target site name and status to delete
TARGET_SITE_NAME = "Project Management"
TARGET_STATUS = '["910"]'  # On hold (910)

# Set to True to delete physically (cannot be restored)
PHYSICAL_DELETE = False

# Share the session
session = requests.Session()
session.headers.update({"Content-Type": "application/json"})

def post_json(url: str, payload: dict) -> dict:
    r = session.post(url, data=json.dumps(payload))
    if not r.ok:
        raise RuntimeError(f"HTTP {r.status_code} {url}\n{r.text}")
    return r.json()

# 1) Get the SiteId from the site name
getclosest_url = f"{BASE_URL}/api/items/{START_SITE_ID}/getclosestsiteid"
closest_payload = {
    "ApiVersion": 1.1,
    "ApiKey": API_KEY,
    "FindSiteNames": [TARGET_SITE_NAME],
}

closest_res = post_json(getclosest_url, closest_payload)
data_list = closest_res.get("Data", [])
if not data_list:
    print(f"{TARGET_SITE_NAME} Failed to get the site information")
    raise SystemExit()

site_id = data_list[0].get("SiteId")
if not isinstance(site_id, int) or site_id <= 0:
    print(f"{TARGET_SITE_NAME} Invalid site ID: {site_id}")
    raise SystemExit()

print(f"Got the target site ID: {site_id}")

# 2) Specify View conditions and run bulkdelete
bulkdelete_url = f"{BASE_URL}/api/items/{site_id}/bulkdelete"
bulkdelete_payload = {
    "ApiVersion": 1.1,
    "ApiKey": API_KEY,
    "View": {"ColumnFilterHash": {"Status": TARGET_STATUS}},
    "PhysicalDelete": PHYSICAL_DELETE,
}

try:
    res = post_json(bulkdelete_url, bulkdelete_payload)
    print("bulkdelete result:", res)
except Exception as e:
    print("bulkdelete failed")
    print(e)
Run
>python api_record_bulkdelete_p2.py
Execution Result
Got the target site ID: 9999
bulkdelete result: {'Id': 9999, 'StatusCode': 200, 'Message': 'Project Management: 5 items have been deleted at once.'}

Confirmation Column in Case of Error

・Precautions when using the API and things to check if an error occurs
・FAQ: What to check if modified configuration files or API requests (JSON format) are not recognized correctly