-
|
Hi, I am trying to send message via API with
but I am getting this error in HTTP response: and in container logs: Other calls like GET /api/v1/nodes work. Any clue? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Root CauseThe CSRF protection middleware was being applied to all Bearer token authentication is inherently protected against CSRF attacks because:
FixPR #1191 updates the CSRF middleware to skip protection when a Bearer token is present in the Authorization header. Once merged, your curl command will work: curl -H "Authorization: Bearer mm_v1_39..." \
-X POST http://host/api/v1/messages \
-H "Content-Type: application/json" \
-d '{"text": "Private message via API", "toNodeId": "!ffffffff"}'The fix will be in the next release. Thanks for reporting this! |
Beta Was this translation helpful? Give feedback.
-
|
Hello,
getting this error in HTTP response
|
Beta Was this translation helpful? Give feedback.
-
|
@TheHobBytes The issue is with your JSON syntax - it is missing the opening brace Your command: -d "\"channel\": 0, \"text\": \"API Test\", \"wantResponse\": false}"Should be: -d "{\"channel\": 0, \"text\": \"API Test\"}"The server was returning a generic 500 error because the JSON parsing error was not being handled properly. PR #1280 fixes this to return a helpful 400 error message instead. In the meantime, try this corrected command: curl -sS -H "Authorization: Bearer mm_v1_..." \
-H "Content-Type: application/json" \
-X POST http://host/api/v1/messages \
-d "{\"channel\": 0, \"text\": \"API Test\"}"Note: |
Beta Was this translation helpful? Give feedback.
Root Cause
The CSRF protection middleware was being applied to all
/apiroutes, including the v1 API which uses Bearer token authentication. CSRF protection is designed for browser-based session authentication (cookies), not for API token authentication.Bearer token authentication is inherently protected against CSRF attacks because:
Fix
PR #1191 updates the CSRF middleware to skip protection when a Bearer token is present in the Authorization header.
Once merged, your curl command will work:
curl -H "Authorization:…