Fill in missing dataAll pages

Ask a person to fill in missing data

A script is missing values it cannot guess. It asks a person to fill them in, and reads the values back from the decision.

What you build#

A script that books supplier invoices finds one without the supplier's VAT number and payment terms. Instead of stopping, it creates a task. A person opens the invoice, fills in the two values and approves. The script gets the values back in the decision and books the invoice.

You use a task type with editable fields: the human may change those fields, and only those, before approving. The result is decision.action: "edited" with the completed values in decision.payload.

Before you start#

  • A TaskToHuman account and a workspace where you can create task types.
  • Editable fields need the page.edit feature. If your plan doesn't include it, the Editable switch is locked and names the plan that has it. See pricing.
  • Python 3.10 or newer with pip install tasktohuman, or curl. The SDKs page shows the same calls in TypeScript.

1. Create the task type#

In the app, open Task types, choose New task type and start from Blank.

  • Basics: name it "Supplier details", key supplier_details. Under What should the human do? choose Approval: editable fields are for approvals only.
  • What they see: under Instructions for the human, say what to do, for example: "Open the invoice. Fill in the supplier's VAT number and payment terms, then choose Approve with changes. Reject if the invoice is not ours."
  • Who is asked: add yourself as the first step.

Then add these Fields, in this order:

KeyLabelTypeSwitches
invoice_numberInvoiceTextRequired
supplier_nameSupplierTextRequired
invoice_urlInvoice documentLinkClickable (on by default)
vat_numberVAT numberTextEditable
payment_terms_daysPayment terms (days)NumberEditable

Leave the two editable fields not required: the script sends the task without them, and a missing required field refuses the task (field_required). The person can still fill in an editable field that arrived empty. Fields without Editable stay read-only on the task page.

Choose New task type to create it. Every field type and switch is described under Fields.

2. Create a test API key#

Open API & webhooks, then API keys, choose New API key, pick Test and choose Create key. The key starts with tth_test_ and is shown once. Keep it in an environment variable:

Shell
export TTH_API_KEY="tth_test_…"

A test task notifies only you, whoever the chain names. See Test mode.

3. Create the task from your script#

Send the values you have and leave out the ones you are missing. An unknown key or a wrong type is refused; an absent optional field is fine.

import os

from tasktohuman import TaskToHuman

tth = TaskToHuman(os.environ["TTH_API_KEY"])

task = tth.create_task(
    "supplier_details",
    title="Supplier details for invoice INV-2041",
    payload={
        "invoice_number": "INV-2041",
        "supplier_name": "Northwind Supplies",
        "invoice_url": "https://erp.example.com/invoices/2041",
    },
    idempotency_key="INV-2041",
)

The answer is 201 Created with the task, now notified. The idempotency key names this invoice, so a retry never asks twice (Idempotency). The title is not encrypted and appears in emails: keep it to an invoice number.

4. Fill in the values#

Open the email and its link. Choose Edit & approve: the VAT number and the payment terms become inputs, the other fields stay as they are. Fill them in and choose Approve with changes.

At least one field must change. A person who approves without changes gives approved, and a person who can't help can Reject, with a comment.

5. Read the values back#

For an edited decision, decision.payload holds the task's fields with the person's changes, so every value comes from one place:

Part of the finished task
"decision": {
  "action": "edited",
  "by": { "id": "01a1dcba-b57a-7aa2-b6b1-05d81545c2ba", "name": "Ana" },
  "automatic": false,
  "comment": null,
  "payload": {
    "invoice_number": "INV-2041",
    "supplier_name": "Northwind Supplies",
    "invoice_url": "https://erp.example.com/invoices/2041",
    "vat_number": "XX123456789",
    "payment_terms_days": 30
  }
}

A script can wait for it. In production, give the task type a Callback URL (under After the answer) and receive the same finished task as a signed POST: see Callbacks and signatures.

Python
task = tth.wait_for_decision(task["id"], timeout=3600)
decision = task["decision"]

if decision and not decision["automatic"] and decision["action"] == "edited":
    values = decision["payload"]
    vat, terms = values.get("vat_number"), values.get("payment_terms_days")
    if vat and terms is not None:
        ...  # book the invoice with these values
else:
    ...  # rejected, approved unchanged, expired or cancelled: leave it for a person
  • Check the values before you use them. They are checked against the field types, but the person may have left one empty.
  • Act only when decision.automatic is false. A task nobody answered ends expired, and a task type's default action could even end it approved by nobody. See When nobody answers.
  • Without callbacks or the SDK, GET /v1/tasks/{id} returns the same decision (Get a task).

Check it works#

  • Create a second task for another invoice, with its own idempotency key (the same key returns the first task), and Reject it with a comment: decision.action is rejected, decision.payload is null and decision.comment holds the comment.
  • Send vat_number as a number, with a new idempotency key (a used key with another body is 409 idempotency_conflict): the answer is 400 validation_failed, with payload.vat_number and the code field_invalid.

Going live#

  • Create a live key (tth_live_…). Tasks then go to the humans of the chain instead of you.
  • Put the people who know your suppliers in the chain, with a backup step. See Escalation chains.
  • Mark a field Sensitive when it holds bank details or personal data: it then stays on the task page, out of emails, previews and logs. It still comes back to your code in decision.payload of an edited decision.

Where next#