« FileMaker Magazin 1/2… | Home | MBS FileMaker Plugin,… »

Swiss Post Webservice to verify addresses

The swiss post offers a web service to verify addresses via SOAP. You can use this webservice with our plugin and the CURL functions. As you see we make a post here with xml data based on a template. We replace the placeholders with values from fields. We need to use Text.EncodeToXML function to make sure the special characters are inserted. When we got result, we pick the results from the xml with a quick query. We simply look for the first nodes matching local name (without namespaces). Maybe this also helps if you want to use a similar webservice:

Set Variable [$curl; Value:MBS("CURL.New")]

Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; "https://webservices.post.ch/IN_ADRCHECKERxV4xEXTERNE/V4-01-00")]

Set Variable [$xml; Value:Test::XML Template]

Set Variable [$xml; Value:Substitute($xml; "$$CallUser$$"; MBS("Text.EncodeToXML"; Test::Username))]

Set Variable [$xml; Value:Substitute($xml; "$$Name$$"; MBS("Text.EncodeToXML";Test::Last Name))]

Set Variable [$xml; Value:Substitute($xml; "$$FirstName$$"; MBS("Text.EncodeToXML";Test::First Name))]

Set Variable [$xml; Value:Substitute($xml; "$$Street$$"; MBS("Text.EncodeToXML"; Test::Street))]

Set Variable [$xml; Value:Substitute($xml; "$$Town$$"; MBS("Text.EncodeToXML"; Test::Town))]

Set Variable [$xml; Value:Substitute($xml; "$$Zip$$"; MBS("Text.EncodeToXML"; Test::Zip))]

Set Variable [$r; Value:MBS("CURL.SetOptionPostFields"; $curl; $xml)]

Set Variable [$r; Value:MBS("CURL.SetOptionUserName"; $curl; Test::Username)]

Set Variable [$r; Value:MBS("CURL.SetOptionPassword"; $curl; Test::Passwort)]

Set Variable [$r; Value:MBS("CURL.SetOptionHTTPHeader"; $curl; "SOAPAction: \"http://post.ch/AdressCheckerExtern/V4-01-00\""; "Expect:"; "Content-Type: text/xml; charset=\"utf-8\"")]

Set Field [Test::Result; MBS("CURL.Perform"; $curl)]

Set Field [Test::Text; MBS("CURL.GetResultAsText"; $curl; "UTF8")]

Set Field [Test::Debug; MBS("CURL.GetDebugAsText"; $curl)]

Set Field [Test::OutputStreetFormatted; MBS( "XML.Query"; Test::Text; "//*[local-name()='StreetFormatted']/text()"; ""; 2 )]

Set Field [Test::OutputTown; MBS( "XML.Query"; Test::Text; "//*[local-name()='Town27']/text()"; ""; 2 )]

Set Field [Test::OutputZip; MBS( "XML.Query"; Test::Text; "//*[local-name()='Zip']/text()"; ""; 2 )]

Set Variable [$result; Value:MBS("CURL.Cleanup"; $curl)]

The example will be included in next prerelease.

Claris FileMaker Plugin
02 03 16 - 18:16