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'
api_instance = CloudmersiveValidateApiClient::VatApi.newinput = # 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}"

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.

Image for post

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store