VAT ID Check using XML-RPC

I need to check the VAT Id of a client. This is possible using XML-RPC. Example of such a call (the query keys have to be exactly as in the example):

As text:
https://evatr.bff-online.de/evatrRPC?UstId_1=DE812673471&UstId_2=IE9672540N&Firmenname=&Ort=&PLZ=&Strasse=

If the client VAT Id is found, the ErrorCode 200 for success is returned (result in Postman):

image

However, WeWeb returns each character in the response as a separate string and the Result key has no effect:

The characters correspond exactly to the Postman response:

image

Here’s the data source definition (bypass CORS is required; otherwise error):

How can I return the ErrorCode only (which I will evaluate then)?

I just tried with the Rest API plugin, seems to give the correct result.
Hadd to use CORS proxy, probably because it should be requested from backend??


image

Hi Thomas,

Thank you very much for this fast and helpful reply!
I didn’t try using the call in a workflow but just had a look at the result in the collection definition. I will continue working on this tomorrow, but I’m sure you found the solution. Thank you again!
Best regards,
Bert

Hi Thomas,

In the beginning, the workflow didn’t work as intended. But I eventually found the 2 issues:

  1. The RPC only works using GET, not POST.
  2. The response seemed to be contained in a data string like this:
    " UstId_1 ErrorCode 215 UstId_2 Druck nein Erg_PLZ Ort Datum 08.08.2024 PLZ Erg_Ort Uhrzeit 11:48:39 Erg_Name Gueltig_ab Gueltig_bis Strasse Firmenname Erg_Str "

I first tried extracting the ErrorCode using a JS string function but this never worked (result always null).
Actually, the result string is an XML structure like the one from above:
image

I then asked Gemini once again and it suggested a specific XML script:

function extractErrorCode(xmlString) {
// Create a DOMParser instance
const parser = new DOMParser();

// Parse the XML string into a DOM document
const xmlDoc = parser.parseFromString(xmlString, “text/xml”);

// Get all elements
const params = xmlDoc.getElementsByTagName(“param”);

// Iterate over params to find the one with key “ErrorCode”
for (let i = 0; i < params.length; i++) {
const keyElement = params[i].getElementsByTagName(“string”)[0];
if (keyElement.textContent === “ErrorCode”) {
const valueElement = params[i].getElementsByTagName(“string”)[1];
return valueElement.textContent;
}
}

return null; // Handle case where ErrorCode not found
}

const xmlString = context.workflow[‘3bdd1ccc-f5c6-457a-8ac7-872566f61929’].result?.[‘data’]/* your XML string here */;
const errorCode = extractErrorCode(xmlString);
// console.log(errorCode); // Output: 200 >> valid
return(errorCode);

This works perfectly! I now added a workflow True/False split using the returned ErrorCode: 200 = valid (true), other codes: error message

Great that you found a solution!

You can also make a formula to extract your XML into a proper json object, so you keep your workflows clean.

Create new formula, with one variable (xml). You can call it extract_vatid_xml() or what you want.
Use this code:

const xmlString = xml;

function extractKeyValuePairs(xmlString) {
  const parser = new DOMParser();
  const xmlDoc = parser.parseFromString(xmlString, "text/xml");
  const params = xmlDoc.getElementsByTagName("param");
  const result = {};

  for (let param of params) {
    const values = param.getElementsByTagName("string");
    if (values.length >= 2) {
      const key = values[0].textContent;
      const value = values[1].textContent;
      result[key] = value;
    }
  }

  return result;
}

return extractKeyValuePairs(xmlString);

Now you have a clean object to work with

Hi Thomas,
This alternative worked fine. Thank you!
Step by step, I’m approaching my goal.

1 Like