How to validate a VAT number in Ruby
Let’s look at how to quickly set up automatic validation of value added tax (VAT) identification numbers using Ruby. First we need to add our API client to Ruby’s Gemfile using the following snippet of code.
gem 'cloudmersive-validate-api-client', '~> 1.3.2'
All that’s left after that is to call the function vat_vat_lookup:
# load the gem
require 'cloudmersive-validate-api-client'
# setup authorization
CloudmersiveValidateApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
endapi_instance = CloudmersiveValidateApiClient::VatApi.newinput = CloudmersiveValidateApiClient::VatLookupRequest.new # VatLookupRequest | Input VAT codebegin
#Lookup a VAT code
result = api_instance.vat_vat_lookup(input)
p result
rescue CloudmersiveValidateApiClient::ApiError => e
puts "Exception when calling VatApi->vat_vat_lookup: #{e}"
end
Our API will then provide you with all the relevant data from the VAT number in question. This includes whether the code itself is actually valid, the business name, address, and country code.
