How to pass values to body variable of TableInput type in APIRequestComponent when using the RUN API? (Python example needed)
When using the RUN API to invoke a flow in LangFlow, I need to pass values to the body variable of TableInput type in the APIRequestComponent. The documentation mentions that TableInput is typically used for structured data (e.g., JSON arrays or nested objects), but lacks concrete code examples. Questions How can I properly construct the body variable in Python to meet the format requirements of TableInput? Do I need to manually serialize the data (e.g., convert Python dictionaries to JSON strings), or is this handled automatically by LangFlow? Could you provide a complete Python example (e.g., using the requests library or LangFlow SDK) demonstrating how to pass such data?
To pass values to the body variable of TableInput type in the APIRequestComponent when using the RUN API, you should structure your data as a dictionary in Python, where each entry represents a key-value pair as expected by the TableInput schema. The APIRequestComponent is designed to accept the body as a dictionary or Data object, and serialization to JSON is handled automatically when making the request—manual serialization is not required on your part [source].
Here’s a complete Python example using the requests library:
import requests
# Replace with your actual LangFlow RUN API endpoint and flow_id
url = "http://<your-langflow-host>/api/v1/flows/<flow_id>/run"
# Example TableInput data as a dictionary
body_data = {
"body": [
{"key": "username", "value": "alice"},
{"key": "email", "value": "[email protected]"}
]
}
# Other required inputs for your flow
payload = {
# ... other flow inputs ...
**body_data
}
headers = {
"Content-Type": "application/json",
# Add authentication headers if needed
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
In this example, the body variable is a list of dictionaries, each with a "key" and "value", matching the TableInput schema [source]. You do not need to manually convert the dictionary to a JSON string; passing it as the json argument to requests.post is sufficient.
If you use the LangFlow SDK, the approach is similar: provide the body as a Python dictionary or list of key-value dictionaries, and the SDK will handle serialization.
If you need to pass more complex nested objects, structure them as nested dictionaries or lists as appropriate for your TableInput schema.
To reply, just mention my name @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
Thank you for the provided example, but after testing, I found that the body parameter should be placed under the tweaks field (not as a top-level field in the request payload). However, even after modifying it this way, the API still returns an error.
@lahok You can pass parameters via tweaks (input schema), as shown in the example.
https://docs.langflow.org/concepts-publish#input-schema
import requests
import os
import uuid
url = "https://aws-us-east-2.langflow.datastax.com/lf/9e993a65-5dc8-4f60-9bf0-d4261a6c8dcc/api/v1/run/2b439b24-edf1-412e-8d48-d912e686149b"
# O URL completo do endpoint da API para este flow
# Configuração do payload da requisição
payload = {
"output_type": "text",
"input_type": "text",
"input_value": "hello world!",
"tweaks": {
"APIRequest-JEgfA": {
"body": [
{
"key": "User-Agent",
"value": "langflow"
}
],
"headers": [
{
"key": "User-Agent",
"value": "langflow"
}
]
}
}
}
Another alternative is to use the Create Data component to create the JSON that will be inserted into the Body or Header of the API Request component.