Skip to content

Table Operation: Delete Record

Overview

You can delete records using the API.

Preparations

Please Create an API Key before performing API operations.

Request

Please send json data in the following format.

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

(*1) Please edit the {server name} and {record ID} parts suit your environment as appropriate.
For Pleasanter.net, the format is as follows:
https://pleasanter.net/fs/api/items/{record ID}/delete

JSON
{
     "ApiVersion": 1.1,
     "ApiKey": "Asfas63dsf1A0faA567A..."
}

Response

The json data in the following format is returned:

JSON
{
    "Id": 12345,
    "StatusCode": 200,
    "LimitPerDate": 10000,
    "LimitRemaining": 9995,
    "Message": "\" {record title name} \" deleted."
}

Code Samples

Modify 【 ... 】 in the code as necessary.
1. Delete records by specifying the record ID

Gets the records whose status is '910' and deletes them using the retrieved IDs.

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

# Library for JSON operations
import json

# Server name and API key
BASE_URL = "【Server name】"  # e.g., http://server
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 = "【Site name】"
TARGET_STATUS = '["910"]'

# 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 (multiple records)
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) Delete the retrieved records one by one
for row in rows:
    record_id = row.get("ResultId") or row.get("Id")
    if not record_id:
        continue

    delete_url = f"{BASE_URL}/api/items/{record_id}/delete"
    delete_payload = {
        "ApiVersion": 1.1,
        "ApiKey": API_KEY,
    }

    try:
        post_json(delete_url, delete_payload)
        print(f"Deleted: Id={record_id}")
    except Exception as e:
        print(f"Failed to delete: Id={record_id}")
        print(e)
Run
>python api_record_delete_p1.py
Execution Result
Deleted: Id=9001
Deleted: Id=9002
Deleted: Id=9003
Deleted: Id=9004
・・・・

Confirmation Items 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

Specification Changes

*API specifications have been partially changed since October 2019.**
- Classification, Numerical Value, Date, Description, and Check Items have been changed from being directly entered in the JSON to being entered within "~Hash".

*API specifications have been partially changed since November 2018.**
- The URL format has been changed from '/pleasanter/api_items/xxxx' to '/pleasanter/api/items/xxxx'.
- The Content-Type specification has been changed from 'application/x-www-form-urlencoded' to 'application/json'.