Wenn Sie keinen benutzerdefinierten Client erstellen können oder möchten (z. B. für PHP), weil Sie Low-Code-Plattformen wie Node Red verwenden, können Sie mit den folgenden node.js-/npm-Paketen in Ihrer package.json-Datei bereits viel erreichen.
{
"dependencies": {
"axios": "^1.7.9",
"file-saver": "^2.0.5",
"string-to-file-stream": "^2.0.0"
}
}
Nach einem „npm install“ und dem Erhalt eines Zugriffstokens für client_credentials, wie unter
axios.post('https://gw.usegroup.de:9443/oauth2/token',
null,
{
params: {'grant_type':'client_credentials'},
auth: {
username: '<client id/>',
password: '<client secret/>'
}
}
).then(function (response) {
// handle success
const msg={};
msg.payload =response.data.access_token;
console.log("done", msg.payload);
})
.catch(function (error) {
// handle error
console.warn(error);
})
.finally(function () {
// always executed
console.log("finished");
});
Eine einfache Anfrage funktioniert dann wie folgt, nachdem Sie das erhaltene access_token unten eingefügt haben:
const axios = require('axios');
axios.get('https://gw.usegroup.de:8243/mustang/1.5.1/mustang/ping',
{
headers: {
'accept': '*/*',
'Authorization': 'Bearer <access_token/>'
}
}
).then(function (response) {
// handle success
console.log("done: ",response.data);
})
.catch(function (error) {
// handle error
console.warn(error);
})
.finally(function () {
// always executed
console.log("finished");
});
Eine komplexere Operation mit einer Dateianforderung und einer Dateiantwort könnte wie folgt funktionieren:
const stringToFileStream = require('string-to-file-stream');
const axios = require('axios');
const bufStr='<rsm:CrossIndustryInvoice...';// rest of XML goes in here!
const stream=stringToFileStream(bufStr);
const FormData = require('form-data');
const fsPromises = require('fs').promises;
const form = new FormData();
form.append("file", stream);
axios.post('https://gw.usegroup.de:8243/mustang/1.5.1/mustang/xmltopdf',
form,
{
responseType: 'arraybuffer',
headers: {
'accept': '*/*',
'Content-Type': 'multipart/form-data',
'Authorization': 'Bearer <access_token/>'
}
}
).then(function (response) {
// handle success
fsPromises.writeFile('response.pdf', response.data, { encoding: 'binary' });
console.log("done");
})
.catch(function (error) {
// handle error
console.warn(error);
})
.finally(function () {
// always executed
console.log("finished");
});
Node Red
Dies ist ein Node Red flow, der ein Verzeichnis (/tmp/incoming) überwacht, neu abgelegte UBL-Dateien in CII konvertiert, zusätzlich in PDF konvertiert und den CII-Inhalt hinzufügt, um aus einer XRechnung eine Factur-X-Datei zu erstellen:

Die benutzerdefinierte Funktion UBL2CII hat die Einstellung

und wird definiert als
axios.post('https://gw.usegroup.de:8243/eigor/v1.6.0/eeisi/eigor?sourceFormat=ubl&destFormat=cii',
msg.payload,
{
"responseType": 'arraybuffer',
headers: {
'Content-Type': 'text/plain',
'accept': '*/*',
'apikey': 'eyJ4N...=='
}
}
).then(function (response) {
msg.payload=response.data;
node.send(msg);
})
XML2PDF ist definiert als
flow.set("read",msg.payload);
const form=new FormData();
form.append("file", stringToFileStream(msg.payload))
axios.post('https://gw.usegroup.de:8243/mustang/1.6.1/mustang/xmltopdf?returnJSON=false',
form,
{
"responseType": 'arraybuffer',
headers: {
'Content-Type': 'multipart/form-data',
'accept': '*/*',
'apikey': 'eyJ4N...=='
}
}
).then(function (response) {
msg.payload=response.data;
flow.set("pdf",response.data);
node.send(msg);
})
und PDF2FX ist definiert als
const form=new FormData();
form.append("file", stringToFileStream(flow.get('pdf')))
form.append("XML", flow.get('read'))
axios.post('https://gw.usegroup.de:8243/mustang/1.6.1/mustang/combineXML?format=fx&version=2&profile=EN16931',
form,
{
"responseType": 'arraybuffer',
headers: {
'Content-Type': 'multipart/form-data',
'accept': '*/*',
'apikey': 'eyJ4N...=='
}
}
).then(function (response) {
msg.payload=response.data;
node.send(msg);
})
Viel Spaß!
