Customs Process Compliance AB - TWSExchange Validator


TWSExchange - XSD

Link to TWSExchange XSD document

SOAP - WSDL

SOAP - Example via Python / SUDS (SOAP Client)

WSDL: http://twsexchangevalidator.customsprocess.se/services/ws/twsService?wsdl
import threading
from os import listdir
from os.path import isfile, join
from suds.client import Client
from suds.cache import NoCache
import datetime

wsdl_url = 'http://twsexchangevalidator.customsprocess.se/services/ws/twsService?wsdl'
client = Client(url=wsdl_url, cache=NoCache())
print client

filePath = 'twsexchangevalidate/testfiles/'
filesToSendNames = [f for f in listdir(filePath) if isfile(join(filePath, f))]
print filesToSendNames

fileList = list()

for fileToSendName in filesToSendNames:
    fileToSend = open(join(filePath, fileToSendName), 'rb')
    fileToSendData = fileToSend.read().encode('base64')
    fileToSend.close()
    fileList.append(fileToSendData)

# Function for sending single file
startTime = datetime.datetime.now()

for count in range(0, len(fileList)):
    result = client.service.validateTWSExchangeXML(fileList[count])
    print "TWSExchangeValidation result for file \"{}\"".format(filesToSendNames[count])
    print result

HTTP - REST

Example via cURL

    curl -X "POST" "http://twsexchangevalidator.customsprocess.se/rest/validateTWSExchangeXML/" -H "Content-Type: application/xml" -d @test.xml

Answer - File correct

	{
	    "businessValid": true,
	    "hasNoticesWarnings": false,
	    "technicalValid": true,
	    "twsExchangeBusinessValidationErrors": null,
	    "twsExchangeBusinessValidationNoticeWarnings": null,
	    "twsExchangeMessageType": "SE_INSH",
	    "valid": true,
	    "xsltValidationResult": null
	}


Flags:
	Valid - Both TechnicalValid and BusinessValid - OK
	TechnicalValid - Technical OK
    BusinessValid - Business OK

Answer - File invalid (Technical error)

curl -X "POST" "http://twsexchangevalidator.customsprocess.se/rest/validateTWSExchangeXML/" -H "Content-Type: application/xml" -d @testError.xml | python -m json.tool
{
    "businessValid": null,
    "hasNoticesWarnings": null,
    "technicalValid": false,
    "twsExchangeBusinessValidationErrors": null,
    "twsExchangeBusinessValidationNoticeWarnings": null,
    "twsExchangeMessageType": null,
    "valid": false,
    "xsltValidationResult": [
        {
            "columnNumber": 637,
            "errorMessage": "cvc-datatype-valid.1.2.1: '2017-03-31' is not a valid value for 'dateTime'.",
            "errorType": "ERROR",
            "lineNumber": 1
        },
        {
            "columnNumber": 637,
            "errorMessage": "cvc-type.3.1.3: The value '2017-03-31' of element 'invoice_date' is not valid.",
            "errorType": "ERROR",
            "lineNumber": 1
        }
    ]
}

The described error: "invoice_date" is not valid