ClimberCloud: Web請求ファイルアップロード

ClimberCloud: Upload Web Invoice File

ClimberCloud の指定コンテンツ ID に「Web請求」文書ファイルとしてアップロードします。
※ClimberCloud®は株式会社NTTデータビジネスブレインズの登録商標です。

Auto Step icon
Configs for this Auto Step
conf_TenantId
C1: テナント ID *#{EL}
conf_ApiKey
C2: API キー *#{EL}
conf_PdfFile
C3: アップロードする請求書 PDF ファイル(1ファイル固定) *
conf_ListIndexNames
C4: 検索属性に追加したいカラム名(セミコロン区切り) *#{EL}
conf_ListIndexData
C5: 検索属性に追加したいデータ(セミコロン区切り) *#{EL}
conf_CustomerId
C6: 請求書送付先の取引先ID *#{EL}
conf_Subject
C7: 請求書の件名 *#{EL}
conf_isAutoRelease
C8: 請求書を自動公開するか
conf_ContentsId
C9: アップロード先のコンテンツID *#{EL}
conf_log
X: 通信ログを保存するデータ項目 (更新)
Script (click to open)


main();
function main(){
//// == Config Retrieving / 工程コンフィグの参照 ==
const tenantId         = configs.get( "conf_TenantId" ) + "";
const apiKey           = configs.get( "conf_ApiKey" ) + "";
const contentsId       = configs.get( "conf_ContentsId" ) + "";

const listIndexNames   = configs.get( "conf_ListIndexNames" ) + "";
const listIndexData    = configs.get( "conf_ListIndexData" ) + "";
const customerId       = configs.get( "conf_CustomerId" ) + "";
const subject          = configs.get( "conf_Subject" ) + "";

const isAutoRelease = configs.getObject( "conf_isAutoRelease" );

const dataId_pdfFile   = configs.get( "conf_PdfFile" );
const dataId_log       = configs.get( "conf_log" );


//// == 演算 / Calculating ==
if ( tenantId == "" ) {
  throw `Tenant ID none.`;
}
if ( apiKey == "" ) {
  throw `API key none.`;
}
if ( contentsId == "" ) {
  throw `Contents ID none.`;
}
if ( customerId == "" ) {
  throw `Customer ID none.`;
}
if ( subject == "" ) {
  throw `Subject none.`;
}

let arrayListIndexNames = listIndexNames.split(";");
let arrayListIndexData = listIndexData.split(";");
if (arrayListIndexNames.length != arrayListIndexData.length) {
  throw `List Index length not equal.`;
}

let accessLog = "";


//ファイルBase64変換
//ファイルの上限サイズは10MB
const files = engine.findDataByNumber( dataId_pdfFile );
let base64Text = "";
if (( !files ) || ( files.length != 1 )) {
  throw `PDF File Num invalid.`;
}
const file = files.get(0);//1ファイル固定
if ( file.getLength() > 10485760 ) {
  throw `PDF File size over.`;
}
fileRepository.readFile(file, 10485760, function(bytes) {
  base64Text += base64.encodeToString(bytes);
});
//engine.log("base64Text:" + base64Text);

let isAutoReleaseValue = 0;
if (isAutoRelease) {
  isAutoReleaseValue = 1;
}


//JSON生成
let indexObjects = [];
for ( let i = 0; i < arrayListIndexNames.length; i++) {
  let indexName = arrayListIndexNames[i];
  let indexData = arrayListIndexData[i];
  let indexObject = {};
  indexObject.KeyName = indexName;
  indexObject.KeyData = indexData;
  indexObjects.push( indexObject );
}

let fileObjects = [];
let fileObject = {};
fileObject.file_data = base64Text;
fileObject.file_name = file.getName();
fileObjects.push( fileObject );

let requestObj = {};
  requestObj.contents_id = contentsId;
  requestObj.customer_id = customerId;
  requestObj.subject = subject;
  requestObj.is_auto_release = isAutoReleaseValue;
  requestObj.listIndex = indexObjects;
  requestObj.listFile = fileObjects;
//engine.log("json:" + JSON.stringify(requestObj));


//APIコール
const uri = "https://api.climber-cloud.jp/api/ContractPdf";
let response = httpClient.begin()
  .header( "X-Tenant", tenantId )
  .header( "X-ApiKey", apiKey )
  .body( JSON.stringify(requestObj), "application/json" )
  .post( uri );
accessLog += "---POST request--- " + response.getStatusCode() + "\n";
accessLog += response.getResponseAsString() + "\n";
engine.log("res:" + response.getResponseAsString());

const status = response.getStatusCode();
if( status >= 300 ){
  engine.log(accessLog);
  throw `Failed in POST request. status: ${status}`;
}


//APIコール結果確認
const jsonObj = JSON.parse( response.getResponseAsString() );
const isSuccess = jsonObj.isSuccess + "";
engine.log("isSuccess:" + isSuccess);
if ( isSuccess !== "0") {
  const message = jsonObj.message + "";
  engine.log("message:" + message);
  throw `Failed in request. isSuccess: ${isSuccess} message: ${message}`;
}


//// == ワークフローデータへの代入 / Data Updating ==
if ( dataId_log !== "" ) {
  engine.setDataByNumber( dataId_log, accessLog );
}

}

Download

warning 自由改変可能な JavaScript (ECMAScript) コードです。いかなる保証もありません。
(アドオン自動工程のインストールは Professional editionでのみ可能です)

Notes

  • ClimberCloud は NTTデータビジネスブレインズ社のサービスで、JIIMA認証を取得しています(電帳法・インボイス制度対応サービスです)。
  • ClimberCloud の APIキー 取得方法については、ClimberCloud サービス内(サポート>利用規約/仕様書>WEBAPI仕様書)から確認できます。ClimberCloud トライアルについては、ClimberCloud サイトからお申込ください。
  • アップロードする PDF ファイル・インデックスファイルはそれぞれ1ファイルのみで固定です。PDF ファイルは 10MB 以下にしてください(ClimberCloud 側のサイズ制限があります)。
  • 「ClimberCloud: ファイルアップロード」と似ていますが、本アドオンは「Web請求」向けの処理となります。

Capture

See Also

%d人のブロガーが「いいね」をつけました。