« Merry Christmas | Home | Three days left for D… »

LogicalDOC Webservice

Some of our clients use the Loigcal DOC software, a document management system.

They do offer a webservice API for their system, so you can connect and query documents from FileMaker or Xojo solutions.

Today we wrote a FileMaker script to query a file given ID and login to the server:

# Parameters. Should come from Script parameters or configuration fields

Set Variable [ $username ; Value: "xxx" ] 

Set Variable [ $password ; Value: "yyy" ] 

Set Variable [ $documentID ; Value: "1234567" ] 

Set Variable [ $server ; Value: "test.ch" ] 

# Clear fields

Set Field [ CURL Test::debug ; "" ] 

Set Field [ CURL Test::metadata ; "" ] 

Set Field [ CURL Test::Result ; "" ] 

Set Field [ CURL Test::Text ; "" ] 

Set Field [ CURL Test::File ; "" ] 

# Start new session

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

# Set URL to load (HTTP, HTTPS, FTP, FTPS, SFTP, etc.)

Set Variable [ $r ; Value: MBS("CURL.SetOptionURL"; $curl; "https://" & $server & "/services/Auth") ] 

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

Set Variable [ $r ; Value: MBS("CURL.SetOptionHTTPHeader"; $curl; "Except:"; "SOAPAction: \"\"") ] 

Set Variable [ $r ; Value: MBS("CURL.SetOptionPostFields"; $curl; "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:auth=\"http://auth.webservice.logicaldoc.com/\">

   <soapenv:Header/>

   <soapenv:Body>

      <auth:login>

         <username>" & MBS( "Text.EncodeToXML"; $username ) & "</username>

         <password>" & MBS( "Text.EncodeToXML"; $password ) & "</password>

      </auth:login>

   </soapenv:Body>

</soapenv:Envelope>") ] 

# Run transfer

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

Set Field [ CURL Test::Result ; $result ] 

# Check result

Set Variable [ $text ; Value: MBS("CURL.GetResultAsText"; $curl; "UTF8") ] 

Set Field [ CURL Test::Text ; $text ] 

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

If [ $result = "OK" ] 

Set Variable [ $sessionID ; Value: MBS( "XML.GetPathValue"; $text; "Envelope.Body.loginResponse.return") ] 

If [ MBS("IsError") = 0 ] 

# Query file metadata

Set Variable [ $r ; Value: MBS("CURL.SetOptionURL"; $curl; "https://" & $server & "/services/Document") ] 

Set Variable [ $r ; Value: MBS("CURL.SetOptionHTTPHeader"; $curl; "Except:"; "SOAPAction: \"\"") ] 

Set Variable [ $r ; Value: MBS("CURL.SetOptionPostFields"; $curl; "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:doc=\"http://document.webservice.logicaldoc.com/\">

   <soapenv:Header/>

   <soapenv:Body>

      <doc:getDocument>

         <!--Optional:-->

         <sid>" & MBS( "Text.EncodeToXML"; $sessionID ) & "</sid>

         <docId>" & MBS( "Text.EncodeToXML"; $documentID ) & "</docId>

      </doc:getDocument>

   </soapenv:Body>

</soapenv:Envelope>") ] 

# Run transfer

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

Set Field [ CURL Test::Result ; $result ] 

If [ $result = "OK" ] 

# Check result

Set Variable [ $metadata ; Value: MBS("CURL.GetResultAsText"; $curl; "UTF8") ] 

Set Variable [ $filename ; Value: MBS( "XML.GetPathValue"; $metadata; "Envelope.Body.getDocumentResponse.document.fileName") ] 

Set Field [ CURL Test::metadata ; $metaData ] 

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

# Query file content

Set Variable [ $r ; Value: MBS("CURL.SetOptionURL"; $curl; "https://" & $server & "/services/Document") ] 

Set Variable [ $r ; Value: MBS("CURL.SetOptionHTTPHeader"; $curl; "Except:"; "SOAPAction: \"\"") ] 

Set Variable [ $r ; Value: MBS("CURL.SetOptionPostFields"; $curl; "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:doc=\"http://document.webservice.logicaldoc.com/\">

   <soapenv:Header/>

   <soapenv:Body>

      <doc:getContent>

         <!--Optional:-->

         <sid>" & MBS( "Text.EncodeToXML"; $sessionID ) & "</sid>

         <docId>" & MBS( "Text.EncodeToXML"; $documentID ) & "</docId>

      </doc:getContent>

   </soapenv:Body>

</soapenv:Envelope>") ] 

# Run transfer

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

Set Field [ CURL Test::Result ; $result ] 

If [ $result = "OK" ] 

# Check result

Set Variable [ $text ; Value: MBS("CURL.GetResultAsText"; $curl; "UTF8") ] 

Set Variable [ $content ; Value: MBS( "XML.GetPathValue"; $text; "Envelope.Body.getContentResponse.return") ] 

Set Field [ CURL Test::Text ; $content ] 

Set Variable [ $file ; Value: Base64Decode ( $content ; $fileName) ] 

Set Field [ CURL Test::File ; $file ] 

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

# Write to temp file

Set Variable [ $folder ; Value: MBS( "Folders.UserTemporary" ) ] 

Set Variable [ $path ; Value: MBS( "Path.AddPathComponent"; $folder; $fileName) ] 

Set Variable [ $r ; Value: MBS( "Container.WriteFile"; $File; $path ) ] 

If [ MBS("IsError") = 0 ] 

# Launch file

Set Variable [ $r ; Value: MBS( "Files.LaunchFile"; $path) ] 

End If

End If

End If

# Logout

Set Variable [ $r ; Value: MBS("CURL.SetOptionURL"; $curl; "https://" & $server & "/services/Auth") ] 

Set Variable [ $r ; Value: MBS("CURL.SetOptionHTTPHeader"; $curl; "Except:"; "SOAPAction: \"\"") ] 

Set Variable [ $r ; Value: MBS("CURL.SetOptionPostFields"; $curl; "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:auth=\"http://auth.webservice.logicaldoc.com/\">

   <soapenv:Header/>

   <soapenv:Body>

      <auth:logout>

         <sid>" & MBS( "Text.EncodeToXML"; $sessionID ) & "</sid>

      </auth:logout>

   </soapenv:Body>

</soapenv:Envelope>") ] 

# Run transfer

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

Set Field [ CURL Test::Result ; $result ] 

# Check result

Set Variable [ $text ; Value: MBS("CURL.GetResultAsText"; $curl; "UTF8") ] 

Set Field [ CURL Test::Text ; $text ] 

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

End If

End If

# Cleanup

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

As you see we first issue a login request, get the session ID, run a query to get metadata, than a query for the file content. Than we write file to disk and launch application. Finally we run the logout transfer.

If you have questions, please do not hesitate to contact us.

Claris FileMaker Plugin
27 12 17 - 12:54