# Smart Fill PDF Form API by any data types (Mapping and Dynamic)

In this tutorial, we’ll guide you through how to fill a PDF form using both **Mapping Data** and **Dynamic Data** together.

This method is the most flexible and works well in real-world scenarios—especially when your data comes from multiple sources such as: Intake forms, Passport or ID images, Financial documents, Your internal database, etc.

Let’s walk through how to combine these inputs and generate a fully filled form with TakeForm.

## Step 1: Get an API Key  [API Key](/docs/api-developer/api-key.md)

Before using any of the steps below, make sure to:

1. **Register a new account** on the [TakeForm platform](https://platform.takeform.app).&#x20;
2. **Receive $5 in free credits** instantly—enough to start testing right away.
3. **Generate your API key** to begin integrating with our API.

Once you have your API key, you're ready to move on to the next section.

## Step 2: Upload the form&#x20;

Now, you need a form to work with. You have two options:

* **Choose an existing form** from your [Form Library](https://platform.takeform.app/)
* **Upload your own form** by following the instructions in the section below\
  \&#xNAN;*(Video guide included)*

{% embed url="<https://www.youtube.com/watch?v=zvpLTG3uSSM>" %}
Upload new form
{% endembed %}

## Step 3: Use Form Filling API to fill form in step 2

Full Code example: <https://github.com/cptrodgers/takeform-examples/blob/master/fill-form-example/smart-filling-method.py>

TakeForm enables you to fill a form using both **`Mapping Data`** and **`Dynamic Data`**. First, it fills the known fields using structured **`Mapping Data`** (via a schema), then it uses **`Dynamic Data`** (such as text, images, or documents) to fill the remaining fields. You can send both types of data in a single request, and TakeForm will handle the process seamlessly.

Read more about TakeForm Filling Method here [TakeForm Community](/docs/about-takeform/takeform-community.md)

<pre class="language-python"><code class="lang-python"># JSON Input Sample form W-9 Form Above.
mapping_data = {
	"address_line_1": "123 Main St",
<strong>	"business_name_disregarded_entity_name": "Acme Corp",
</strong>	"foreign_partners_owners_beneficiaries_indicator": False,
	"name_of_entity_individual": "John Doe",
	"requester_name_address": "Jane Smith\n456 Elm St\nAnytown, CA 91234"
}

# Dynamic Data, Free Text
dynamic_text_data = """
City, State, ZIP: Anytown, CA, 91234

Federal Tax Classification:
C Corporation: true

Exemptions:
Exempt Payee Code: 4
Exemption from FATCA Reporting Code: A

List of Account Numbers:
12345, 67890

Taxpayer Identification Number (EIN):
12-3456789
"""

def fill_form():
    url = f"https://api.takeform.app/developer/v1/forms/{FORM_ID}/fill"
    headers = {
        'X-API-Key': TAKE_FORM_API_KEY,
        'Content-Type': 'application/json; charset=utf-8',
    }

    response = requests.post(
        url,
        headers=headers,
        json={
            "mapping": mapping_data,
            "dynamic": {
                "sources": [
                    {
                        "type": "Text",
                        "text": dynamic_text_data
                    },
                ]
            }
        },
    )
    print("Fill succesfully: Filled Form Object", response.json())
    # Expected Output: Fill succesfully: Filled Form Object {'created_at': 1744736364, 'file_id': '4a1609c5-7113-4f11-b22d-af70d40f9bed', 'filled_via': 'Api', 'form_id': '854d35dc-c401-4079-aadc-63c309a052e8', 'id': 'e31c24cc-6883-4e52-ab9b-474601d89543', 'name': 'w-9.pdf', 'status': 'Filling', 'updated_at': 1744736363, 'user_id': 'df0bebb1-c460-4263-a654-6d9f5dda7428'}

    return response.json()["id"]


</code></pre>

## Step 4: Retrieve the filled form.

```python

def download_form(filled_form_id: str):
    url = f"https://api.takeform.app/developer/v1/filled-forms/{filled_form_id}/download-url"
    headers = {
        'X-API-Key': TAKE_FORM_API_KEY,
        'Content-Type': 'application/json; charset=utf-8',
    }

    response = requests.get(
        url,
        headers=headers,
    )
    print("Filled Form", response.json())
    # Output: Filled Form https://storage.googleapis.com/takeform/8da53c8c-5334-4ebb-8074-a1c6cd79d1ca?...

```

That's all, now you can download the filled pdf.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://takeform.gitbook.io/docs/api-developer/smart-fill-pdf-form-api-by-any-data-types-mapping-and-dynamic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
