Webhook to SQL gives a workflow its own web address. Each time your website or another system sends a request to it, the workflow saves what was sent as a row in a Microsoft SQL table. This article shows how to install it and fill in each step.

Who can do this

Workspace Admins and Editors. Templates are on every plan. Microsoft SQL ◇ is on paid plans: on Free you can set the template up and test it, and publishing asks for a paid plan. See Premium connections on the Free plan.

Before you start

  • A Microsoft SQL connection, to a server on the public internet, with a SQL Server user and password. See Connect a Microsoft SQL database.
  • A table to save into. The template's query writes to a table named enquiries with the columns name, email, message and received_at. Make that table, or change the query to suit your own table.
  • The system that will send the requests, such as your website's form, able to call a web address with JSON fields named name, email and message. Your own names work too, if you change the parameters to match.

Steps

Install it

  1. On Workflows, select the arrow beside + New workflow, then From a template.
  2. In Search templates, type SQL.
  3. On Webhook to SQL, select Use this template.
  4. In Install into, choose the workspace or project, then select Install as a draft.
  5. The toast says Installed as a draft, for example Webhook to SQL is in Consulace. Connect Microsoft SQL, then publish. If the workspace has one Microsoft SQL connection, the template has chosen it and the toast doesn't name it. Select Open it. The workflow opens in the designer with two steps.

You can also start it on a new, empty workflow, under Start from a template. See Starting a workflow from a template.

Fill in the steps

  1. Select When the address is called (Webhook).
    • Method starts on POST. Choose the one your system sends.
    • Respond starts on Immediately with 200, so the caller doesn't wait for the row to be saved. Leave it unless your system needs to wait.
  2. Select Save it to the table (Microsoft SQL · Query).
    • Choose the Connection.
    • Query is already an insert into enquiries: insert into enquiries (name, email, message, received_at) values (@name, @email, @message, sysutcdatetime()). Change the table and column names to your own if they differ.
    • Under Parameters, @name, @email and @message are already {{ trigger.body.name }}, {{ trigger.body.email }} and {{ trigger.body.message }}, the fields of the request's JSON body. Change name, email and message after body. to the names your system sends. Add a parameter for each other @name you add to the query.
  3. Select the trigger again, copy the Test URL with Copy, then select Listen for a test event.
  4. Within two minutes, send a request to the Test URL from your system, or from a tool such as curl or Postman. A test run starts with what was sent, and really saves the row. See Send a test event to a webhook.
  5. Check the row in your table, then publish the workflow and switch it on.
  6. Copy the Production URL with Copy, and give it to your system in place of the Test URL.

What happens next

  • Each request to the Production URL starts one run and saves one row. Each run counts in the month's allowance.
  • The address stays the same across publishes, so your system is set up once.
  • The caller gets 200 and the run's id as soon as the run is queued.

Good to know

  • Keep the Production URL secret. Anyone who has it can start the workflow, so keep it where your system keeps its secrets.
  • Values always go in Parameters, never in the query. {{ }} isn't allowed inside the query, which keeps what's sent from changing the SQL.
  • A field the request didn't send saves as empty. Give the column a default in SQL Server, or make the system always send it.
  • received_at is set by SQL Server with sysutcdatetime(), in UTC.

If something goes wrong

What you see Why What to do
Steps marked Needs setup The connection isn't chosen yet Choose it. See Fix steps marked Needs setup.
SQL Server refused: … The table or a column doesn't exist, or the user may not insert into it Read the reason. Make the table, correct the names in Query, or give the user the right to insert.
Put values from earlier steps in Parameters — @name in the query — never in the query itself. The query has {{ }} in it Move each value into Parameters.
The caller gets 404 — Nobody is listening on this test address. Press “Listen for a test event” in the designer, then send it again. You weren't listening, or the two minutes ran out Select Listen for a test event, then send again.
Publishing says "“Save it to the table” needs a paid plan. Change the plan, or remove it and publish the rest." Microsoft SQL is a premium connection and the company is on Free Change to a paid plan once they're open.