[SOLVED] Log: "Missing required user data" after executing a PHP function
- 0
- Resolved
- 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
- Android SDK: Kotlin null Value Not Updat...
Hi team, I think you should check the Android SDK implementation once, as it seems to have an issue handling Kotlin **null** values. For example: When I send:...
- Can't connect GitHub — 500 error at the ...
Appwrite Cloud, Pro plan, SFO region. All my Git connections vanished today — Sites and all 15 Functions now show no repository connected. When I try to add a ...
- GB Hours IS NOT resetting
Hi, I was checking my usage and noticed that all of my usage quotas were reset on August 20, 2026, when my billing cycle renewed. Everything else appears to ha...