// validation_rest_min.js
// A minimal JavaScript program to test the FirmaSAT Validation REST API
// 1. Define some XML content as a string
// As a test, send some well-formed XML that is not a valid SAT CFDi document
// This should return a status "partialsuccess" with an xml-error
// "XML file is not a supported document."
const xmlContent = `<?xml version="1.0"?><data><item>value</item></data>`;
// 2. Create the payload: an object where the XML is a string value
const payload = {
"api-token": "YOUR_API_TOKEN_HERE", // Replace with your own api-token
"xmldata": xmlContent,
};
// 3. Define the target URL and headers
const url = "https://di-mgt.com.au/cryptosys/api/fsa_validation";
const headers = {
"Content-Type": "application/json"
};
// 4. Send the POST request using fetch
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload)
})
.then(response => {
// 5. Check the response
console.log(`Status Code: ${response.status}`);
return response.text();
})
.then(responseBody => {
console.log(`Response Body: ${responseBody}`);
})
.catch(error => {
console.error(`Error: ${error.message}`);
});