Closed Banbury closed 1 week ago
I found a similar closed issue that might be relevant to your problem: Custom tool with API Key. The suggested solution was to change the endpoint to use HTTP instead of HTTPS due to a self-signed certificate issue.
For your specific issue with the Bearer Token returning a 400 Bad Request in Dify version 0.7.2, while the same token works with curl, it could be due to the specific structure and requirements of the API request as defined by Dify.
Here are the key points to check:
Headers:
Content-Type
should be application/json
.Authorization
should be in the format Bearer {api_key}
.Request Body:
point
and params
.Here is an example of how the request should be structured:
{
"point": "app.external_data_tool.query",
"params": {
"app_id": "61248ab4-1125-45be-ae32-0ce91334d021",
"tool_variable": "weather_retrieve",
"inputs": {
"location": "London"
},
"query": "How's the weather today?"
}
}
Ensure that your custom tool sends the request in this format and includes the correct headers. This should resolve the 400 Bad Request error [1][2].
To continue talking to Dosu, mention @dosu.
After restarting the HA server the error went away. Go figure.
Self Checks
Dify version
0.7.2
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
I have attached the OpenAPI spec for Home Assistant. But unless you have an installation of HA, it won't help much. ha.json I have successfully used other unprotected APIs on the same network.
✔️ Expected Behavior
I would expect the test to succeed. I have tried the endpoint with curl and the same token on the same machine and it works.
❌ Actual Behavior
I get the message
Request failed with status code 400 and 400: Bad Request
. The log file contains the line2024-09-02 10:33:25 api-1 | 2024-09-02 08:33:25,743.743 INFO [Dummy-2] [_client.py:1026] - HTTP Request: GET http://192.168.1.115:8123/api/ "HTTP/1.1 400 Bad Request"
I have tried to increase the log level, but your code doesn't seem to contain any Debug level log messages. I can only assume, that the HTTP request is malformed on your side.