ClimberCloud: Upload Web Invoice File

ClimberCloud: Upload Web Invoice File

Uploads a ClimberCloud Web Invoice file to a specified content ID in ClimberCloud.
* ClimberCloud® is a registered trademark of NTT DATA Business Brains Corporation.

Auto Step icon
Configs for this Auto Step
conf_TenantId
C1: Tenant ID *#{EL}
conf_ApiKey
C2: API Key *#{EL}
conf_PdfFile
C3: Invoice PDF file to be uploaded (fixed to one file) *
conf_ListIndexNames
C4: Column names (separated by semicolons) to be added to the search attribute *#{EL}
conf_ListIndexData
C5: Data to be added to search attributes (separated by semicolons) *#{EL}
conf_CustomerId
C6: Business partner ID to whom invoices should be sent *#{EL}
conf_Subject
C7: Subject of invoice *#{EL}
conf_isAutoRelease
C8: Do you want to automatically publish invoices?
conf_ContentsId
C9: Content ID of the upload destination *#{EL}
conf_log
X: Data Items to be stored in communication log (update)
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 = "";


//File Base64 conversion
//Maximum file size is 10 MB
const files = engine.findDataByNumber( dataId_pdfFile );
let base64Text = "";
if (( !files ) || ( files.length != 1 )) {
  throw `PDF File Num invalid.`;
}
const file = files.get(0);//1 file fixed
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 generation
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 call
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 call result confirmation
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 This is freely-modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installation of add-on automated processes is only available in the Professional edition)

Notes

  • ClimberCloud is a service provided by NTT Data Business Brains, Inc. and is JIIMA certified (the service is compliant with the Electric Ledger Law and Invoice System).
  • For information on how to obtain an API key for ClimberCloud, please refer to the ClimberCloud service (Support > Terms of Use/Specifications > WEBAPI Specifications). For ClimberCloud trial, please apply from the ClimberCloud site.
  • Upload only one PDF file and one index file each. PDF files should be no larger than 10MB (subject to size limitations on the ClimberCloud side).
  • Similar to [ClimberCloud: Upload File] this add-on is a process for web billing.

Capture

See Also

%d bloggers like this: