Appwrite Function Not Receiving HTTP Request Body (req.payload, req.body, and req.bodyRaw all empty) on Cloud (nyc region)
- Dominant language
- TypeScript
- Stars
- 57.4k
- Forks
- 5.7k
- Avg merge
- 16h 27m
- Merged PRs (30d)
- 291
Description
### 👟 Reproduction steps
Description:
I am unable to get my Appwrite Function (Node.js 18, deployed in the nyc region) to receive the HTTP request body when triggered via the REST API. The function always receives req.payload, req.body, and req.bodyRaw as undefined or empty, even though the request is sent with the correct Content-Type and a nonzero content-length.
Function Code:
```
module.exports = async ({ req, res, log, error }) => {
// Debug: log the full req object and possible body locations
try {
log('req.payload:', req.payload);
log('req.body:', req.body);
log('req.bodyRaw:', req.bodyRaw);
log('Full req:', JSON.stringify(req));
} catch (e) {
log('Error logging req object:', e);
}
// Parse payload from Appwrite REST/SDK or local
let raw = req.payload;
if (!raw && req.bodyRaw) {
raw = req.bodyRaw;
}
if (!raw && req.body) {
if (typeof req.body === 'string') {
raw = req.body;
} else if (req.body.data) {
raw = req.body.data;
}
}
log('Raw payload value:', raw);
if (!raw) {
error('Missing payload! req.payload:', req.payload, 'req.body:', req.body, 'req.bodyRaw:', req.bodyRaw);
throw new Error('Missing payload');
}
const payload = JSON.parse(typeof raw === 'string' ? raw : JSON.stringify(raw));
log('Payload parsed:', payload);
return res.json({ payload, body: req.body, bodyRaw: req.bodyRaw }, 200);
};
```
How I’m Triggering the Function:
Using both frontend code (fetch and axios) and direct curl requests.
Example curl command:
```
curl -X POST 'https://nyc.cloud.appwrite.io/v1/functions/68c358e4001be6aa5c0c/executions' \
-H 'Content-Type: application/json' \
-H 'X-Appwrite-Project: 68bfaa37002cf15d8be9' \
-d '{"test":"hello"}'
```
Observed Appwrite Function Execution Logs:
```
--- Incoming request to storeUser.js ---
Request method: POST
Request payload: undefined
Request body:
Request bodyRaw:
Error logging req object: SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at get bodyJson [as bodyJson] (/usr/local/server/src/server.js:125:21)
at JSON.stringify ()
at module.exports (/usr/local/server/src/function/storeUser.js:9:27)
at execute (/usr/local/server/src/server.js:222:22)
at action (/usr/local/server/src/server.js:237:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /usr/local/server/src/server.js:26:5
Raw payload value: undefined
--------
Missing payload! req.payload: undefined req.body: req.bodyRaw:
Internal error: Error: Missing payload
at module.exports (/usr/local/server/src/function/storeUser.js:51:13)
at execute (/usr/local/server/src/server.js:222:22)
at action (/usr/local/server/src/server.js:237:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /usr/local/server/src/server.js:26:5
```
### 👍 Expected behavior
What I Expect:
The function should receive the request body as [req.payload](vscode-file://vscode-app/c:/Users/ponna/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html), [req.body](vscode-file://vscode-app/c:/Users/ponna/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html), or [req.bodyRaw](vscode-file://vscode-app/c:/Users/ponna/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html), but all are empty.
What I’ve Tried:
Sending the body as a raw JSON string with correct headers.
Using both [axios](vscode-file://vscode-app/c:/Users/ponna/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html) and [fetch](vscode-file://vscode-app/c:/Users/ponna/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html) in the frontend.
Testing with direct curl requests.
Logging all possible request properties.
Function runtime is Node.js 18, and all environment variables are set.
Verified that content-length and content-type are correct.
No proxy or firewall is interfering.
Impact:
This blocks all HTTP-based function use cases that require a request body, including user authentication and database writes.
Environment:
Appwrite Cloud (nyc region)
Node.js 18 function runtime
Function ID: 68c358e4001be6aa5c0c
Project ID: 68bfaa37002cf15d8be9
Please advise if this is a known issue, or if there is a workaround.
### 👎 Actual Behavior
Impact:
This blocks all HTTP-based function use cases that require a request body, including user authentication and database writes.
Environment:
Appwrite Cloud (nyc region)
Node.js 18 function runtime
Function ID: 68c358e4001be6aa5c0c
Project ID: 68bfaa37002cf15d8be9
### 🎲 Appwrite version
Appwrite Cloud
### 💻 Operating system
Linux
### 🧱 Your Environment
Environment:
Appwrite Cloud (nyc region)
Node.js 18 function runtime
Function ID: 68c358e4001be6aa5c0c
Project ID: 68bfaa37002cf15d8be9
### 👀 Have you spent some time to check if this issue has been raised before?
- [x] I checked and didn't find similar issue
### 🏢 Have you read the Code of Conduct?
- [x] I have read the [Code of Conduct](https://github.com/appwrite/.github/blob/main/CODE_OF_CONDUCT.md)
Contributor guide
Assessment
This issue has not been assessed yet.