0

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

gaut
  • 5,771
  • 1
  • 14
  • 45

1 Answers1

1

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()
      
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • please consider checking this new, related question: https://stackoverflow.com/questions/73528499/form-submission-via-httr-vies-vat-validation – gaut Aug 29 '22 at 12:02