Developer Function: API: Table Operation: Import Record
Overview¶
Import records into the specified table using the API.
Preparation¶
Please Create an API Key before performing API operations.
Request¶
Send CSV data and JSON parameters using the request format below.
| Setting column | Value |
|---|---|
| HTTP Method | POST |
| Content-Type | multipart/form-data |
| Character Code | UTF-8 |
| URL | http://{server name}/api/items/{site ID}/import (*1) |
| Body | Refer to "Column to Specify for Body" below |
(*1) Please edit the {server name} and {site ID} parts suit your environment as appropriate.
For pleasanter.net, the format is as follows:
https://pleasanter.net/fs/api/items/{site ID}/import
Column to Specify for Body¶
| Column name | Value |
|---|---|
| parameters | Specify the contents of the "API Parameters" below as a JSON format string |
| file | Binary data of the CSV file to be registered |
API Parameters¶
| Column name | e.g. | Notes |
|---|---|---|
| ApiVersion | 1.1 | API version |
| ApiKey | 3da0fa3a7R61faf821... | Acquired API key |
| Encoding | Shift-JIS | Encoding of CSV file. Specify "UTF-8" or "Shift-JIS" |
| UpdatableImport | true | Specify true if you want to "update records with matching keys" |
| Key | IssueId | Key column when UpdatableImport is set to true. If the key column is ClassA, set it to "ClassA" |
Execution Example¶
If the response is a 403 error after executing the following sample, even though the API key belongs to a valid user and has write permission to the target site, please refer to the following FAQ.
FAQ: 403 Error Occurs When Importing Records via API Using PowerShell
PowerShell (version 6.0 or later) Sample¶
PowerShell¶
$uri = 'http://servername/api/items/1234/import'
$filePath = "./sample.csv"
$form = @{
parameters = ConvertTo-Json @{
ApiVersion = 1.1;
ApiKey = "4d84b4773a58bbc3c4...";
Encoding = "UTF-8";
UpdatableImport = $true;
Key = "IssueId";
};
file = Get-Item -Path $filePath;
}
Invoke-WebRequest -Uri $uri -Method Post -Form $form
Python Sample¶
Python¶
import requests
import json
url = "https://servername/api/items/1234/import"
filePath = "./sample.csv"
data = {
"parameters": json.dumps({
"ApiVersion" : 1.1,
"ApiKey" : "4d84b4773a58bbc3c4...",
"Encoding" : "UTF-8",
"UpdatableImport" : True,
"Key" : "IssueId"
})
}
files = {
"file":("sample.csv", open(filePath,"rb"), "text/csv")
}
response = requests.post(url, data, files=files)
print(response.content.decode())
Response¶
The json data in the following format will be returned.
JSON¶
{
"Id":1234,
"StatusCode":200,
"LimitPerDate":1000,
"LimitRemaining":998,
"Message": "Table Name: 50 added, 12 updated."
}
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