54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
import fs from 'fs';
|
|
|
|
//プリザンター実行変数
|
|
const pleasanter = 'https://aaa.bbb.com/pleasanter';
|
|
const apiKey = '****';
|
|
const uploadSiteId = "999999";
|
|
|
|
function main() {
|
|
let importFile = "importData.csv";
|
|
importToPleasanter(importFile, "UTF-8", true, uploadSiteId, "Title");
|
|
|
|
}
|
|
|
|
function importToPleasanter(importFile, encoding, updatableImport, siteId, key) {
|
|
const url = pleasanter + '/api/items/' + siteId + '/import';
|
|
const csvData = fs.readFileSync(importFile, 'utf-8');
|
|
|
|
//送信データ
|
|
let formData = new FormData();
|
|
let json = {
|
|
"ApiVersion": 1.1,
|
|
"ApiKey": apiKey,
|
|
"Encoding": encoding,
|
|
"UpdatableImport": updatableImport,
|
|
"Key": key
|
|
};
|
|
|
|
formData.append('parameters', JSON.stringify(json));
|
|
formData.append('file', csvData);
|
|
|
|
fetch(url, {
|
|
"method": 'POST',
|
|
"body": formData
|
|
}).then((response) => {
|
|
if (!response.ok) {
|
|
throw new Error(`${response.status} ${response.statusText}`);
|
|
console.log(response);
|
|
}
|
|
// レスポンスが JSON 形式で返っていることを想定
|
|
return response.json();
|
|
}).then((data) => {
|
|
console.log('** fetch: then(data)');
|
|
console.log(data);
|
|
}).catch((reason) => {
|
|
// エラー処理
|
|
console.log('** fetch: catch');
|
|
console.log(reason);
|
|
});
|
|
|
|
}
|
|
|
|
//始動
|
|
main();
|