This article describes how to create a SAFR Actions script that performs an HTTP POST to a web service.   This article assumes you have read How to trigger a script with SAFR actions.  If you are familiar with SAFR Actions, you can likely follow information in this page alone.


For more information about SAFR Actions, please refer to SAFR Actions Overview in our documentation portal.


How it works

This solution uses curl to make an HTTP POST request, passing information from a recognition event to the external web service.  The parameters that are passed can easily be customized to fit different needs.  This way, you can change the columns that are written simply by editing the SAFR Actions configuration file.  More details on this below.


By default the script writes to the publicly avalable service http://ptsv2.com.


Instructions


Setting up the HTTP POST SAFR Actions script involves 2 parts

  1. Configure SAFR Actions
  2. Verify script


For more advanced requirements, the HTTP POST can be made from a script that is executed by SAFR Actions.  This would allow you to perform more advanced actions such as first retrieving the event image or implementing conditional logic based on information passed with the event. 


For this article, we use curl to make the HTTP POST request which comes installed by default on both Windows and Linux.


Install the script

Add the attached script (write_log.py) to the SAFR Actions Scripts directory in following locations:

  • Mac: /Library/RealNetworks/SAFR/ares/scripts
  • Linux: /opt/RealNetworks/SAFR/ares/scripts
  • Windows: C:\ProgramData\RealNetworks\SAFR\ares\scripts


SAFR Actions configuration

Open SAFR Actions application and edit as follows:

Replace above with your username and password.  Set Environment to "SAFR Custom..." if you are using SAFR On-Premises Server.  


The HTTP Service shown above is a public web service that is meant for testing purpose only.  It is quite useful because you can use it to see what information was posted.  This is a good tool to use in troubleshooting the process before you implement the same against your own web services.  To learn more go to http://ptsv2.com and create a test site.  You will need username, password and test site ID for use below.


Edit the actions item 1 line to fit your need.  Here are the contents of the line show in the image above:

curl -u USER:PWD -X POST -F 'name=#N' -F "external_id=#E" -F "site=#I" -F "source=#S" -F "age=#A" -F "gender=#G" http://ptsv2.com/t/YOUR_PTSV2_ID/post


Where:

  • -u USER:PWD should be replaced with the PTSV2 test site
  • YOUR_PTSV2_ID is the ID you created
  • The tokens (#N, etc) are replaced by SAFR Actions.  The definitions of the tokens are found in Action and Reply Message Escape Sequences.   For convenience, you can use the attached helper tool (SAFRActionsTokens.xlsx) to generate the command string.  Hopefully the spreadsheet is self-explanatory.


As an alternative, you can edit the attached "SAFRActions.config" file and paste in the contents of the attached.  The SAFR Actions config file (SAFRActions.config) is located in following: 

  • Mac: /Library/RealNetworks/SAFR/ares/
  • Linux: /opt/RealNetworks/SAFR/ares/
  • Windows: C:\ProgramData\RealNetworks\SAFR\ares\

After editing the file, start SAFR Actions to reload the file.


Testing the script


Please refer to How to trigger a script with SAFR actions for details on testing the action.  Use the PTSV2 site to check that results are posted.