It turns out a lot more work, but after a day of searching the Internet and trying, I got it to work with UrlFetchApp
function UrlFetchAppDetermineCountryFromIP_(ipAddress) { var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +"<SOAP-ENV:Body>" +"<GetGeoIP xmlns=\"http://www.webservicex.net/\">" +"<IPAddress>"+ ipAddress +"</IPAddress>" +"</GetGeoIP>" +"</SOAP-ENV:Body>" +"</SOAP-ENV:Envelope>" var options = { "method" : "post", "contentType" : "text/xml", "payload" : xml }; var result = UrlFetchApp.fetch("http://www.webservicex.net/geoipservice.asmx?wsdl", options); var xmlResult = XmlService.parse(result).getRootElement(); var soapNamespace = xmlResult.getNamespace("soap"); var getGeoIPResponse = xmlResult.getChild("Body", soapNamespace).getChildren()[0]; var getGeoIPResponseNamespace = getGeoIPResponse.getNamespace(); return getGeoIPResponse .getChild("GetGeoIPResult", getGeoIPResponseNamespace) .getChild("CountryCode", getGeoIPResponseNamespace) .getText(); }
It would be nice to build the xml payload using XmlService , however I tried this for several hours and could not put 4 xmlns attributes on the Evnelope Element, which causes the web service request to fail
Jarno source share