Chapter 28

Widgets, webhooks and HTTP calls

Put a form that starts an automation on a web page. Let another service start runs with a webhook call, and let a script call another company's API without holding its key. You will also know the security limits of each one.

28.1Embed an automation on a web page

A widget is a small page with a Run button, and optionally a form, that you place on another website with an <iframe>. Use it to let people start an automation from an internal portal or dashboard without signing in to Autoworklet.

Before you start, know four things:

  • The automation's creator, admins and managers can create, edit and delete widgets.
  • Any member of the organization can open View details on an existing widget and create an embed token. The code they get still runs as the person who created the widget.
  • Getting the embed code needs the Pro plan or above.
  • Every widget run uses the published version, runs as the person who created the widget, and uses your organization's minutes. In the Runs tab, these runs carry a Widget label.

Create a widget

You create a widget in the Create new widget dialog on the automation's Triggers tab.

The Create new widget dialog with a name, a description and an allowed origin typed in
Figure 28.1The Create new widget dialog with a name, a description and an allowed origin typed in
  1. Open the automation.
  2. Click the Triggers tab.
  3. Scroll to Widget triggers. It says "Embed this worklet on websites or internal dashboards." With no widgets yet, it reads "No widgets yet. Create one to expose this automation elsewhere."
  4. Click Add widget trigger. The Create new widget dialog opens.
  5. In Widget name 1, type a name, for example "Price check widget".
  6. Optional: in Description, say what the widget does.
  7. Optional: in Allowed origins 2, list the sites you plan to put the widget on, separated by commas, for example portal.example.com. Only those sites, and Autoworklet itself, can then show the widget. A browser refuses to show it on any other page. Leave the box empty to let every site show it. How to write a site:
    • A bare name such as portal.example.com means that site over https://.
    • Add the scheme and port for anything else, for example http://intranet.example:8080.
    • *.example.com covers every subdomain of example.com, but not example.com itself.
    • An entry with a path, such as portal.example.com/help, names no site and is ignored.
  8. Default parameters 3 starts with the automation's default inputs, as JSON. Change the values the widget should send. The box must hold one JSON object, or be empty.
  9. Read the Security notice 4: widget runs execute under your account and use your organization's run allowance. It advises you to restrict the allowed origins, which is step 7.
  10. Click Create widget 5. The button stays grayed out until you type a name.

"Widget created successfully!" appears, and the widget is listed as a card. The card reads Inactive until you create its embed token. Its icons are View details, Edit widget and Delete widget.

Warning

Give the embed code only to the people who manage the page. Delete the widget when you stop using it. Allowed origins limits which websites can show the widget, not who can use its embed code. With the box empty, anyone who has the embed code can show the widget on any page. They can also start runs that use your minutes. With sites listed, a program that runs outside a web browser and has the embed code can still start runs.

A visitor can also change any input before they click Run:

  • In the JSON box.
  • Under Advanced JSON on a widget with a form.
  • In the widget's address.

Get the embed code

  1. On the widget's card, click View details (the eye icon). The dialog shows "No Embed Token" and "Create an embed token to get the widget code and start using it on external sites."
  2. Click Create Token. The button reads Creating..., then "Token created" appears.
  3. Under Embed Code, click Show Code.
  4. Click Copy. "Embed code copied!" appears.
  5. Paste the code into the HTML of your web page where the widget should appear.

The code is one <iframe> element. It looks like this, with your Autoworklet address, the widget's id and its token filled in:

Embed code
<iframe src="https://YOUR_AUTOWORKLET_ADDRESS/embed/WIDGET_ID?token=TOKEN" width="100%" height="500" style="border:0"></iframe>

Change height if your form needs more room. To fill in inputs for one page, add &params= and URL-encoded JSON to the end of the src address, for example &params=%7B%22customer_id%22%3A%22123%22%7D. Those values replace the widget's default values for the same inputs on that page, and visitors can still change them.

To try the widget first, click Show Preview to see it in a frame, or Open Widget to open it in a new tab. A run you start from either one is a real run: it performs the automation's actions and uses your minutes.

Important

The token is not saved anywhere you can open it again. Copy the embed code as soon as it appears. It stays in the dialog until you leave the automation's page or reload it. After that, View details shows "No Embed Token" and Create Token again, though the card still reads Active.

Creating another token gives a new embed code, and the earlier codes keep working. Tokens do not expire. The only way to stop every copy of the code is to delete the widget.

The Total Runs, Last Run and Success Rate tiles at the top of the dialog do not count runs yet. They always read 0, "Never" and 0%. To see widget runs, open the automation's Runs tab and look for the Widget label (Run history).

Add a form for visitors

Without a form, visitors see a Parameters (JSON) box. A form is easier for most people.

  1. On the widget's card, click Edit widget (the pencil icon). The Edit widget dialog opens.
  2. Under Embedded form, click a field type under Add field:
    • Short text
    • Long text
    • Number
    • Toggle
    • Date
    • Date & time
    • Select
  3. Fill in the new field:
    • Field label: what the visitor sees, for example "Customer ID".
    • Key: the name of the automation's input this field fills, for example customer_id. Every field needs one: a field without a Key is dropped when you save. As you type, spaces become _ and other symbols are removed.
    • Required: if the visitor must fill the field in, select this checkbox.
    • Optional: Description (shown beneath the label), Placeholder and Default value.
    • For Select, add each choice under Options with Add option, giving each a Label and a Value.
  4. Custom parameters holds the JSON inputs the widget starts from, the same as Default parameters when you created it.
  5. Click Save changes. "Widget updated" appears.

The form editor keeps one field. After a field has a Key, a new field you add under Add field disappears immediately. To replace the field, click Remove field (the trash icon) and add another. Put the other inputs the widget sends in Custom parameters.

You can also change the name, the description and Allowed origins in this dialog.

What visitors see

The widget page has a Run Parameters card with the form, or the Parameters (JSON) box when there is no form.

  1. Optional: to have AI fill in the fields, the visitor clicks Ask AI. In "Ask AI for parameters", they type what they need under "Describe what you need". They click Ask AI again. They check the suggested values and click Use suggestion.
  2. The visitor fills in or checks the fields.
  3. The visitor clicks Run. "Starting widget run..." and then "Widget run started successfully!" appear.
  4. The Automation Run panel shows:
    • The status (Running, then Completed, Stopped or Error).
    • The times.
    • A live view of the screen.
    • Live Updates from the run.
  5. The round history button in the bottom-right corner opens Recent Runs. It lists the runs started from this browser only, up to 10 at a time. Visitors never see each other's runs.

After the first run, the form is replaced by a Run button at the top of the page. To start another run, the visitor clicks Run, which opens the form in a dialog.

Delete a widget

  • The trash icon on the widget's card deletes it immediately, without asking.
  • Delete Widget in the View details dialog asks "Are you sure you want to delete this widget?" first.

After you delete a widget, every copy of its embed code stops working.

If something goes wrong

Message Where What to do
"Failed to create widget" Create dialog Check that Default parameters is one JSON object, such as {"key": "value"}. Only the automation's creator, admins and managers can create widgets.
"Embed widgets need the Pro plan or above." Create Token Upgrade to Pro or above (Change your plan).
"Failed to create token" Create Token Try again.
"Add a token query param to the iframe URL: ?token=..." The widget on your page The ?token= part of the address is missing. Paste the whole embed code.
"Initialization failed" The widget on your page The widget was deleted, or the token in the code is wrong or cut short. Copy the code again from View details, or create a new token.
"Please fix the highlighted fields before running." The widget on your page The visitor left a required field empty or typed an invalid value.
"Fix parameter JSON before running." The widget on your page The JSON box does not hold valid JSON.

Note

In a HIPAA organization, do not put health information in a widget's inputs or results. Widgets there do not show the run report, the live screen or images from the run (HIPAA organizations).

28.2Start runs from other services

A webhook lets another service start a run with one HTTP request. Set it up on the automation's Triggers tab: add a Webhook under External connections, then click Generate secret (Webhooks). You get two things to give the other service: the trigger's Endpoint URL and its secret. This section is the request that service must send.

The request

Send a POST to the Endpoint URL with:

  • The header x-aw-trigger-secret set to the secret.
  • The header content-type: application/json.
  • A JSON body with the run's inputs under params.
  • Optional: the header x-aw-delivery-id set to a unique id for this event.

In this example, replace:

  • The address with your trigger's Endpoint URL.
  • awt_... with the secret.
  • my-event-123 with your own event id.
  • The params with the automation's inputs.
Shell
curl -X POST https://api.autoworklet.com/v1/triggers/WORKLET_ID/TRIGGER_ID \
  -H "x-aw-trigger-secret: awt_..." \
  -H "x-aw-delivery-id: my-event-123" \
  -H "content-type: application/json" \
  -d '{"params":{"hello":"world"}}'

Autoworklet reads the body as JSON when it is sent as application/json or application/cloudevents+json. How the body becomes the run's inputs:

  • {"params": {...}} sets the inputs to what is inside params.
  • Any other JSON object becomes the inputs as it is. This lets a service that cannot shape its body, such as a form tool, still start a run.
  • A form sent as application/x-www-form-urlencoded, the way an HTML form sends it, turns each field into an input of the same name.
  • Any other body starts the run without inputs from the request. Examples are plain text, and JSON sent as text/plain or another type such as application/vnd.custom+json.
  • If you leave the content-type header out of the example above, curl -d sends the body as a form, not as JSON. The JSON text then becomes an input name instead of the inputs, so keep the header.
  • The input names are the automation's input keys (Inputs, outputs and default values).

A webhook run uses the published version, runs as the person who created the trigger, and uses your organization's minutes. In the Runs tab, it carries a Webhook label.

The same event twice

Services often send an event again when they do not get an answer in time. To stop that from starting a second run:

  • Send x-aw-delivery-id. A request with an id Autoworklet has seen returns the same runId and starts nothing new.
  • Without it, a request counts as the same event when it has the same body and goes to the same trigger. It must also arrive within 10 minutes of the request that started the run. A copy that arrives later starts a second run. Send x-aw-delivery-id whenever a second run would matter.

Responses

Status Body Meaning
200 { "runId": "...", "status": "queued", "deduped": false } The run was queued.
200 { "runId": "...", "status": "queued", "deduped": true, "runStatus": ... } A repeat of an event this trigger already took. It returns the same runId and starts nothing new. status always says queued. runStatus says where that run is now, such as running or finished.
200 { "ignored": true, "reason": ... } GitHub only: the event, repository or branch is not one the trigger watches. This answer also comes when a GitHub delivery sent as application/x-www-form-urlencoded has a payload field that is not valid JSON.
400 A web page that says "Bad Request", not JSON The body was sent as application/json or application/cloudevents+json but is not a JSON object or list (malformed JSON, or a bare string, number, true, false or null). This answer comes before the secret is checked, and it does not count toward the 60 a minute or the day's 500.
400 { "error": "invalid_params" } The run's inputs cannot be saved. The cause is a list directly inside a list, a blank name, or a name that starts and ends with __. Another cause is more than 20 levels of nesting. It does not count toward the day's 500.
401 { "error": "unauthorized" } The secret is missing or wrong, no secret was generated yet, or the address is wrong. All of these give the same answer on purpose.
403 { "error": "trigger_disabled" } The secret is right, but the trigger is turned off.
413 A web page that says "Request Entity Too Large", not JSON The body is over 32 MiB, or it is a form (application/x-www-form-urlencoded) with more than 1,000 fields. For the form, that page says "Payload Too Large" instead. This answer comes before the secret is checked, and it does not count toward the 60 a minute or the day's 500.
413 { "error": "payload_too_large" } The run's inputs are too big for one run: more than 900 KB, or more than 30,000 entries. Entries are counted like this: 2 for the inputs, 2 for each name inside them, and 1 for each item in a list. It does not count toward the day's 500.
429 { "error": "rate_limited", "retryAfter": ... } More than 60 requests in a minute to this trigger. Wait retryAfter seconds.
429 { "error": "daily_budget_exhausted", "retryAfter": ... } This trigger took 500 new requests today. A repeat of an event it already took does not count, and still returns its runId. The day ends at midnight UTC. Wait retryAfter seconds.

Note

In a HIPAA organization, do not put health information in a webhook request (HIPAA organizations).

GitHub

A GitHub trigger is set up in the repository's webhook settings (Webhooks). GitHub does not send the secret itself. It signs each request with the secret. Autoworklet checks the signature and uses GitHub's own delivery id to skip repeats, so x-aw-delivery-id is not needed.

Warning

Keep the secret in the other service's secret settings, never in a web page or a shared document. To replace a secret that might have leaked, see Webhooks.

28.3Call other APIs from a script

A script often needs to call another company's API, such as a payment, shipping or CRM service. Do not put that API's key in the script or in the run's inputs. Store it as an HTTP connection, and let the script call the connection by name. Autoworklet adds the key to the request, and the script never sees it.

An admin or manager adds the connection under Menu, Organization, Integrations, HTTP connections (HTTP connections). The connection's Name is what the script uses, for example stripe. It cannot be changed later.

Use a connection in a script

get_connection returns the connection's base address and its type of authentication, never the key. Pass the same name as connection= to the request, and Autoworklet adds the key:

main.pyPython
conn = get_connection("stripe")   # {"connection", "base_url", "auth"} - never the secret
resp = integration_get(url=conn["base_url"] + "/v1/charges", connection="stripe")

Change stripe to your connection's name, and /v1/charges to the path you need.

The call returns a dictionary:

Key What it holds
success True when the API answered with a 2xx status.
status_code The HTTP status, or None if the request did not get through.
data The reply, when the API answered with a JSON object.
text The reply as text, when it was not a JSON object.
error Why the request did not get through, when status_code is None.

The same connection= argument works with these calls:

  • integration_post
  • integration_put
  • integration_patch
  • integration_delete

Send a JSON body with json_data=.

To read the run's inputs and record results from the reply, see Read inputs and publish outputs.

Good practice

  • Build every address from base_url. Autoworklet adds the key to whatever address the call names. Starting from conn["base_url"] keeps the key going only to the API it belongs to.
  • Record only the fields you need. Some APIs send the key back in their reply. A script that saves the whole reply as an output would store the key where others can read it.
  • Check success before you use data. A failed call returns success as False and does not stop the script by itself.
  • Use the exact name. get_connection stops the run with "Unknown connection" and the name when no connection matches. A call that passes a wrong name only in connection= does not stop the run. It returns success as False, and error holds the same message. Check the spelling on the HTTP connections card.

An AI agent connected over MCP sees the organization's connections in get_worklet, with their names and types of authentication but never their keys. This lets it write scripts that use them (Connect an AI agent (MCP)).

Important

In a HIPAA organization, do not send health information to another API through an HTTP connection (HIPAA organizations).