Home > Software engineering >  web API with R: VIES VAT validation
web API with R: VIES VAT validation

Time:11-28

I'd like to verify the customers' VAT information using R and the VIES website.

So far I've tried this method

library(curl)
library(xml2)
library(httr)
library(rvest)
url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=FR&iso=FR&vat=23489967794&name=&companyType=&street1=&postcode=&city=&requesterMs=FR&requesterIso=FR&requesterVat=23489967794&BtnSubmitVat=Verify';
test <- GET(url)
rawToChar(test$content)

Problem is, this gives me a content containing only weird output like :{\"servletContext\

Does anybody know how to perform this? they have a SOAP API available, but I haven't found out how to use it yet, the wsdl definition is here

CodePudding user response:

Not sure what response type you are after. Here is via html using headers specification:

library(rvest)
library(httr)

headers = c(
  "User-Agent" = "Safari/537.36",
  "Accept" = "text/html,application/xhtml xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
)

params = list(
  "ms" = "FR",
  "iso" = "FR",
  "vat" = "23489967794",
  "name" = "",
  "companyType" = "",
  "street1" = "",
  "postcode" = "",
  "city" = "",
  "requesterMs" = "FR",
  "requesterIso" = "FR",
  "requesterVat" = "23489967794",
  "BtnSubmitVat" = "Verify"
)

r <- httr::GET(url = "https://ec.europa.eu/taxation_customs/vies/viesquer.do", httr::add_headers(.headers=headers), query = params)
r |> content() |> html_element('.validStyle') |> html_text()
      
  • Related