Skip to content

Web Forms - Custom

The ThinkAutomation Web API can accept HTTP POST requests from your own web forms. Simply set the form action to the public API URL. For example:

<html>
  <body>
   <form action="https://api.thinkautomation.com/addmessage?taid=5f7b421a6e1f408c38488397179ab14c6e1f405c7cbf955cd9%2fwxO9qltjQwt0pU7d4GRErBl5njQP%2f" method="post">
     <label for="fname">First name:</label>
     <input type="text" id="fname" name="fname"><br><br>
     <label for="lname">Last name:</label>
     <input type="text" id="lname" name="lname"><br><br>
     <input type="submit" value="Submit">
   </form>
  </body>
</html>

You can add a &redirect={URL} parameter to the API URL query string if you want the server to respond with a 303 Redirect once the message has been accepted.

When the form is posted to ThinkAutomation a new message will be sent to your Automation in Json format. For example:

{
    "fname": "Alice",
    "lname": "Bamber"
}

The RemoteHost, User-Agent & Origin headers will also be added to the ThinkAutomation message headers. The RemoteHost can be accessed using the built-in variable %Msg_FromIp%. You can access these values in your Automation using the Set Variable action with the Extract Header Value operation.

You can then use Extract Field actions to extract the data from the message and perform any other Automation actions. If your ThinkAutomation Server is not active when a web form is submitted it will be queued by the ThinkAutomation API for up to 48 hours.

Returning Automation Results

By default API POST requests will respond with a 202 Accepted status as soon as the message has been queued (unless a &redirect parameter is specified). You can optionally wait for the Automation results by adding &wait=true or &results=true query string parameter to the URL.

If &wait=true is used the API will return the results of the Automation in the MessageResultDetail object of the Json response along with a 200 OK status. The response will include the Automation return value.

If the &results=true parameter is used then only the Automation Return Value content (or an error message) will be returned along with a 200 OK status. Depending on the content of the Automation Return value, the result will be served as plain text (text/plain), HTML (text/html) or Json (application/json). If the Return Value contains Markdown text it will be converted to HTML first. If the Return Value is already HTML it will be returned as HTML. If the Return Value is Json it will be returned as Json.

If your Automation is long running, or you want to provide a static link to the Automation results that a user can access later, you can use the %Msg_ResultsUrl% variable. Your Automation could include this variable in an outgoing email. A user can click the link to view the Automation results at a later date. The %Msg_ResultsUrl% URL is unique for each processed message and contains a secure hash. The link will work for as long as the Message is stored in the Message Store.

For additional security, ensure the Allowed Origins entry on the Message Source API properties contains the URL for the site containing the forms you will be posting to ThinkAutomation. This will ensure that form posts will only be accepted from your own website.