[SOLVED] Log: "Missing required user data" after executing a PHP function
- 0
- Android
- Accounts
- Cloud
- Users
- Functions
Maybe there is a problem with the payload that I send. This is an example: {
"name":"myname", "email":"myname@gmail.com", "password":"appassword123"
}
It seems like no user id is being sent?
Try this one
use Appwrite\ID;
...
$users->create(ID::unique(), $email,null, $password, $name);
I tried it, also I sent the userid in the payload and yet it shows the same response.
And you get the same error?
Yes
Can you share your code at this point?
Yes
What is the exact error?
In Appwrite there are no errors
Only the response
Good, and what exactly is this one?
Missing required user data: name, email, password
Okay, then the error is from here
if (empty($name) || empty($email) || empty($password)) {
return $res->send('Missing required user data: name, email, password', 400);
}
Meaning you'll need to parse the data in a different way.
Yes
Try this
try {
$userData = \json_decode($req['payload'], true);
} catch(\Exception $err) {
$res->json([
'success' => false,
'message' => 'Payload is invalid.',
]);
return;
}
Now you're $userData should have the parsed JSON.
Should I replace this with your code: try { $user = $users->create(ID::unique(), $email, null, $password, $name); $userId = $user['$id'] ?? ''; // Retrieve the generated user ID } catch (AppwriteException $error) { echo $error->getMessage(); return; }
This part you can leave the same
Here's the complete example
<?php
use Appwrite\Client;
use Appwrite\Services\Users;
use Appwrite\Services\Functions;
use Appwrite\ID;
require_once 'vendor/autoload.php';
return function ($req, $res) {
$client = new Client();
$users = new Users($client);
if (
!$req['variables']['APPWRITE_FUNCTION_ENDPOINT']
|| !$req['variables']['APPWRITE_FUNCTION_API_KEY']
|| !$req['variables']['APPWRITE_FUNCTION_PROJECT_ID']
) {
return $res->send('Environment variables are not set. Function cannot use Appwrite SDK.', 500);
}
$client
->setEndpoint($req['variables']['APPWRITE_FUNCTION_ENDPOINT'])
->setProject($req['variables']['APPWRITE_FUNCTION_PROJECT_ID'])
->setKey($req['variables']['APPWRITE_FUNCTION_API_KEY'])
->setSelfSigned(true);
// Debug code: Log the received payload
error_log('Received payload:');
error_log(print_r($req, true));
// Correctly access the user data from the payload
try {
$userData = \json_decode($req['payload'], true);
} catch(\Exception $err) {
$res->json([
'success' => false,
'message' => 'Payload is invalid.',
]);
return;
}
// Retrieve the user data fields from the payload
$userId = $userData['userid'] ?? '';
$name = $userData['name'] ?? '';
$email = $userData['email'] ?? '';
$password = $userData['password'] ?? '';
// Check for missing user data fields
if (empty($name) || empty($email) || empty($password)) {
return $res->send('Missing required user data: name, email, password', 400);
}
try {
$user = $users->create(ID::unique(), $email, null, $password, $name);
$userId = $user['$id'] ?? ''; // Retrieve the generated user ID
} catch (AppwriteException $error) {
echo $error->getMessage();
return;
}
$user = [
'userid' => ID::unique(),
'name' => $name,
'email' => $email,
'password' => $password
];
return $res->json(['user' => $user]);
};
Ok, thanks
It's solved now. Thanks
<a:agooglethumbsup:635256484682530825>
[SOLVED] Log: "Missing required user data" after executing a PHP function
Recommended threads
- cant resume project
Invalid console fingerprint event i try man time
- TablesDB can't be used in Appwrite Funct...
I have written a function (DART) and it won't deploy. Here is what I get : 2026-03-14T17:09:41.459693680Z Compiling ... 2026-03-14T17:09:42.915619217Z ../build...
- general_route_not_found - Auth Guide
If you’ve just added a subdomain to your project, verified your DNS records, and confirmed your SSL certificate is working, but you're still hitting a `general_...