Open alex-ge123 opened 3 days ago
To pass parameters to the headers and body in an APIRequest
component using the createDate
component, you need to ensure that the createDate
component outputs the data in the correct format expected by the APIRequest
component. Here’s how you can set it up:
Define Headers and Body in createDate
:
createDate
component outputs the headers and body as dictionaries.Configure the APIRequest
Component:
headers
and body
fields of the APIRequest
component to receive the data from the createDate
component.Here is an example of how you can set up the components:
createDate
Component# Example data creation in createDate component
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN"
}
body = {
"key1": "value1",
"key2": "value2"
}
APIRequest
Componentimport asyncio
from langflow.base.langflow.components.data.APIRequest import APIRequest
from langflow.schema import Record
# Create an instance of the APIRequest component
api_request_component = APIRequest()
# Define the headers and body using the output from createDate
headers = Record(data={
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN"
})
body = Record(data={
"key1": "value1",
"key2": "value2"
})
# Define other parameters
urls = ["https://testzxzq.rd.virsical.cn/vsk/smt-m"]
method = "POST"
timeout = 10
# Set the component's inputs
api_request_component.urls = urls
api_request_component.method = method
api_request_component.headers = headers
api_request_component.body = body
api_request_component.timeout = timeout
# Make the request
results = asyncio.run(api_request_component.build(method, urls, headers, body, timeout))
# Print the results
for result in results:
print(result.data)
createDate
component outputs the headers and body as dictionaries.APIRequest
component.Authorization
header is correctly set with a valid token.loguru
logger is used extensively within the APIRequest
component to log errors and important steps.By following these steps, you should be able to pass parameters to the headers and body in the APIRequest
component using the createDate
component effectively [1][2].
To continue talking to Dosu, mention @dosu.
Hello @alex-ge123,
Could you please review the status of this PR (https://github.com/langflow-ai/langflow/pull/2470) and confirm if the issue has been resolved on your end as well?
Thanks!
Describe the bug How to use createDate to pass parameters to header and body in apiRuquest![微信图片_20240701143954](https://github.com/langflow-ai/langflow/assets/71969995/0042dc31-86ce-43f7-ad1e-a8cfd63746f5)
Browser and Version
To Reproduce Steps to reproduce the behavior:
Screenshots
Additional context![微信图片_20240701143754](https://github.com/langflow-ai/langflow/assets/71969995/8e19be55-6cfd-485b-981f-4517877af729)