Home > Uncategorized > Checking a Spanish #VAT number using the #VIES webservice in C#

Checking a Spanish #VAT number using the #VIES webservice in C#

Checking EU VAT numbers using the VIES webservice has some quirks, for example, in Germany, only the validity of the number can be verified, and in Spain, although the company name and address are not exposed, the API can be used to verify them against provided details, for this, a different service method needs to be used for Spain, than for other countries;

TL; DR; here is the Github Repo showing the code in c# https://github.com/infiniteloopltd/CheckVatNumberSpain

Checking a VAT number in Spain can be done by using the European Union’s VAT Information Exchange System (VIES). VIES is a web-based system that allows businesses and tax authorities in the EU to verify the validity of VAT numbers assigned to companies in other EU member states.

To check a VAT number in Spain using VIES, you would need to make a SOAP web service request to the VIES web service endpoint, passing in the VAT number you wish to validate as a parameter. The request would be sent to the VIES service over HTTPS, ensuring the data transmitted is secure.

The VIES service would then respond with a validation result indicating whether the VAT number is valid or not. If the VAT number is valid, the response would also include the country code of the member state that issued the VAT number. The VIES service does not expose the name or address of the company.

Added in the code is a inspector that prints to the console the XML being sent and received, for use in Postman, or another client that needed to POST the XML via HTTP rather than SOAP; which would be;

Sample Request

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <checkVatApprox xmlns="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
      <countryCode>ES</countryCode>
      <vatNumber>B83891812</vatNumber>
      <traderName>Rodrisa Automoviles</traderName>
      <traderCompanyType />
      <traderStreet>Avda. Reina Victoria</traderStreet>
      <traderPostcode>28430</traderPostcode>
      <traderCity>Madrid</traderCity>
      <requesterCountryCode />
      <requesterVatNumber />
    </checkVatApprox>
  </s:Body>
</s:Envelope>

Sample Response

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header/>
    <env:Body>
        <ns2:checkVatApproxResponse xmlns:ns2="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
            <ns2:countryCode>ES</ns2:countryCode>
            <ns2:vatNumber>B83891812</ns2:vatNumber>
            <ns2:requestDate>2023-01-12+01:00</ns2:requestDate>
            <ns2:valid>true</ns2:valid>
            <ns2:traderName>Rodrisa Automoviles</ns2:traderName>
            <ns2:traderCompanyType></ns2:traderCompanyType>
            <ns2:traderStreet>Avda. Reina Victoria</ns2:traderStreet>
            <ns2:traderPostcode>28430</ns2:traderPostcode>
            <ns2:traderCity>Madrid</ns2:traderCity>
            <ns2:traderNameMatch>1</ns2:traderNameMatch>
            <ns2:traderCompanyTypeMatch>3</ns2:traderCompanyTypeMatch>
            <ns2:traderStreetMatch>1</ns2:traderStreetMatch>
            <ns2:traderPostcodeMatch>1</ns2:traderPostcodeMatch>
            <ns2:traderCityMatch>2</ns2:traderCityMatch>
            <ns2:requestIdentifier></ns2:requestIdentifier>
        </ns2:checkVatApproxResponse>
    </env:Body>
</env:Envelope>
Advertisement
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: