Skip to content

Create Department

Overview

You can create new records using the API.

Preparations

  • Please Create an API Key before performing API operations.
  • The user issuing the API key to execute this function must be granted tenant manager privileges.

Request

Send json data in the following request format:

Setting column Value
HTTP method POST
Content-Type application/json
Character code UTF-8
URL http://{server name}/api/depts/create (*1)
Body Refer to the json data below

(*1) Please edit the {server name} part to suit your environment as appropriate.
For Pleasanter.net, the format is as follows:
https://pleasanter.net/fs/api/depts/create

Request

JSON
{
    "ApiVersion": 1.1,
    "ApiKey": "017dRapJ3f5f1Dgsdj95...",
    "DeptCode": "[Department code of the department to register]",
    "DeptName": "[Name of the department to register",
    "Body": "[Description of the department to register]"
}

Response

The json data in the following format will be returned.

JSON
{
    "Id": 12345,
    "StatusCode": 200,
    "Message": "\"Department code of the department to register\" created."
}

Code Samples

Modify 【 ... 】 in the code as necessary.
1. Read a JSON file and create departments

A Python program reads the department information specified in a JSON file and creates the departments.

JSON(api_dept_create.json)
[
    { "DeptCode": "DEV001", "DeptName": "Development Department", "Body": "Development" },
    { "DeptCode": "DEV002", "DeptName": "Sales Department", "Body": "Sales" },
    { "DeptCode": "DEV003", "DeptName": "General Affairs Department", "Body": "General Affairs" }
]
Python(api_dept_create.py)
import json
import requests

# Specify the server name, API key, and JSON file path
BASE_URL = "【Server name】"
API_KEY = "【API key】"
JSON_PATH = "api_dept_create.json"
# Read the JSON file
with open(JSON_PATH, encoding="utf-8") as f:
    records = json.load(f)
# Register each record with the API
for r in records:
    payload = {
        "ApiVersion": 1.1,
        "ApiKey": API_KEY,
        "DeptCode": r["DeptCode"],
        "DeptName": r["DeptName"],
        "Body": r.get("Body", ""),
    }
    res = requests.post(
        f"{BASE_URL}/api/depts/create",
        json=payload,
        headers={"Content-Type": "application/json"},
    )
    print(r["DeptCode"], res.status_code, res.text)
Run
>python api_dept_create.py
Execution Result
DEV001 200 {"Id":31,"StatusCode":200,"Message":"\" Development Department \" has been created."}
DEV002 200 {"Id":32,"StatusCode":200,"Message":"\" Sales Department \" has been created."}
DEV003 200 {"Id":33,"StatusCode":200,"Message":"\" General Affairs Department \" has been created."}

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