> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tinyfish.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Form Filling

> Automate form filling and submission

> [!NOTE]
>
> Form behind a login wall, like a job application? See [Fill Out and Submit a Form, Including a
> Job Application](https://docs.tinyfish.ai/tinyagent/how-to/fill-submit-form-with-vault.md) — same pattern, plus Vault
> credentials so the login password never ends up in the goal text.

## Basic Example

Fill and submit a contact form:

```python Python theme={null}
from tinyfish import TinyFish, EventType, RunStatus

client = TinyFish()

with client.agent.stream(
    url="https://example.com/contact",
    goal="""Fill in the contact form:
        - Name field: "John Doe"
        - Email field: "john@example.com"
        - Message field: "I am interested in your services."
        Then click the Submit button and extract the success message.
    """,
) as stream:
    for event in stream:
        if event.type == EventType.COMPLETE and event.status == RunStatus.COMPLETED:
            print("Result:", event.result_json)
```

```typescript TypeScript theme={null}
import { TinyFish, EventType, RunStatus } from "@tiny-fish/sdk";

async function main() {
  const client = new TinyFish();

  const stream = await client.agent.stream({
    url: "https://example.com/contact",
    goal: `Fill in the contact form:
      - Name field: "John Doe"
      - Email field: "john@example.com"
      - Message field: "I am interested in your services."
      Then click the Submit button and extract the success message.
    `,
  });

  for await (const event of stream) {
    if (event.type === EventType.COMPLETE && event.status === RunStatus.COMPLETED) {
      console.log("Result:", event.result);
    }
  }
}

main();
```

```bash cURL theme={null}
curl -N -X POST https://agent.tinyfish.ai/v1/automation/run-sse \
  -H "X-API-Key: $TINYFISH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/contact",
    "goal": "Fill in the contact form with name John Doe and email john@example.com, then click Submit"
  }'
```

```bash CLI theme={null}
tinyfish agent run "Fill in the contact form: Name: John Doe, Email: john@example.com, Message: I am interested in your services. Then click Submit and return the success message." \
  --url example.com/contact --pretty
```

**Output:**

```json theme={null}
{
  "success": true,
  "message": "Thank you for contacting us!"
}
```

## Multi-Step Form

Handle multi-step forms in a single goal:

```python Python theme={null}
from tinyfish import TinyFish

client = TinyFish()

with client.agent.stream(
    url="https://example.com/signup",
    goal="""Complete the multi-step signup form:

        Step 1 (Personal Info):
        - First name: "John"
        - Last name: "Doe"
        - Email: "john@example.com"
        - Click "Next"

        Step 2 (Address):
        - Street: "123 Main St"
        - City: "San Francisco"
        - State: "CA"
        - ZIP: "94102"
        - Click "Next"

        Step 3 (Preferences):
        - Select "Email notifications" checkbox
        - Click "Submit"

        Extract the confirmation number from the success page.
    """,
) as stream:
    for event in stream:
        print(event)
```

```typescript TypeScript theme={null}
import { TinyFish } from "@tiny-fish/sdk";

async function main() {
  const client = new TinyFish();

  const stream = await client.agent.stream({
    url: "https://example.com/signup",
    goal: `Complete the multi-step signup form:

      Step 1 (Personal Info):
      - First name: "John"
      - Last name: "Doe"
      - Email: "john@example.com"
      - Click "Next"

      Step 2 (Address):
      - Street: "123 Main St"
      - City: "San Francisco"
      - State: "CA"
      - ZIP: "94102"
      - Click "Next"

      Step 3 (Preferences):
      - Select "Email notifications" checkbox
      - Click "Submit"

      Extract the confirmation number from the success page.
    `,
  });

  for await (const event of stream) {
    console.log(event);
  }
}

main();
```

```bash cURL theme={null}
curl -N -X POST https://agent.tinyfish.ai/v1/automation/run-sse \
  -H "X-API-Key: $TINYFISH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/signup",
    "goal": "Complete the multi-step signup form: Step 1 - First name John, Last name Doe, Email john@example.com, click Next. Step 2 - Street 123 Main St, City San Francisco, State CA, ZIP 94102, click Next. Step 3 - Select Email notifications checkbox, click Submit. Extract the confirmation number."
  }'
```

## Tips

* Use stealth mode for login/signup forms
* Be explicit about field values in your goal
* Describe buttons by their text ("click 'Submit'")
* Handle multi-step forms in one goal

## Try It

**1. Save the code**

Save any example above as `form.ts`

**2. Set your API key**

`export TINYFISH_API_KEY="your_api_key" `

**3. Run it**

`npx tsx form.ts `

## Related

> [card] [Web Scraping](https://docs.tinyfish.ai/examples/scraping.md)
>
> Extract data from pages

> [card] [Run SSE API](https://docs.tinyfish.ai/api-reference)
>
> Complete API docs


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.