Soap Request in R

SOAP request in R

This solves the problem:


headerFields =
c(Accept = "text/xml",
Accept = "multipart/*",
'Content-Type' = "text/xml; charset=utf-8",
SOAPAction = "")

body = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
<clientLogin xmlns="">

curlPerform(url = "",
httpheader = headerFields,
postfields = body

How to do a SOAP request for EUR-Lex API with R?

The answers you linked to have pretty good examples to work off of. Adding in the various URLs from the WSDL and information from the manual, you end up with the code below.

Unfortunately due to the EUR-Lex security restrictions I couldn't test this (you need a username and password from them, which I assume you have), but it should at the very least get you on the right track.


headerFields =
c(Accept = "text/xml",
Accept = "multipart/*",
'Content-Type' = "text/xml; charset=utf-8",
SOAPAction = "")

body = '<soap:Envelope xmlns:soap="" xmlns:sear="">
<wsse:Security soap:mustUnderstand="true" xmlns:wsse="">
<wsse:UsernameToken wsu:Id="UsernameToken-3" xmlns:wsu="">
<wsse:Username>${EUR-Lex username}</wsse:Username>
<wsse:Password Type="
wss-username-token-profile-1.0#PasswordText">${WS password}</wsse:Password>
<sear:expertQuery>${expert query}</sear:expertQuery>
<sear:searchLanguage>${search language}</sear:searchLanguage>

reader = basicTextGatherer()

curlPerform(url = "",
httpheader = headerFields,
postfields = body,
writefunction = reader$update

xml <- reader$value()

Soap request in R: POST not supported

The WSDL give the definition of the SOAP endpoint. That's not where you should be posting your request. In the content of the WSDL there is a <wsdlsoap:address location=""> attribute which appears to give the correct URL where you should send your post request. This version of the request seems towk work

xml.request = r'[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="" >
<urn:checkVat xmlns:urn="">

'Content-Type' = "text/xml",
Accept = "text/xml")
getURL(url = "",
# [1] "<env:Envelope xmlns:env=\"\">
# <env:Header/><env:Body><ns2:checkVatResponse
# xmlns:ns2=\"\">
# <ns2:countryCode>NL</ns2:countryCode>
# <ns2:vatNumber>800938495B01</ns2:vatNumber><ns2:requestDate>2022-08-
# 29+02:00</ns2:requestDate><ns2:valid>false</ns2:valid><ns2:name></ns2:name>
# <ns2:address></ns2:address></ns2:checkVatResponse></env:Body></env:Envelope>"

How to convert SOAP request curl to RCurl

Here's how with httr:

r <- POST("", body = upload_file("request.xml"))

Related Topics

Leave a reply