
Hey, I just want to update the permission of a document in PHP for a user to for example read. How do I do that? I cant get it to work. My current solution is this: ```$databaseId = 'games'; $collectionId = 'pool'; $documentId = $_GET['document_id'] ?? null; $userId = $_GET['user_id'] ?? null;
$database = new Databases($client);
try {
// Retrieve the existing document
$document = $database->getDocument($databaseId, $collectionId, $documentId);
print_r($document);
$readPermissions = $document['$permissions']['read'] ?? [];
// Add the user to the read permissions if not already present
if (!in_array("user:$userId", $readPermissions)) {
$readPermissions[] = "user:$userId";
}
// Update the document with the new read permissions
$result = $database->updateDocument($databaseId, $collectionId, $documentId, $document, $readPermissions);
echo "Document updated successfully.";
} catch (Exception $e) {
echo "Error updating document: " . $e->getMessage();
}```

I get the error: Error updating document: Invalid permissions: Permission "user:X" is not allowed. Must be one of: read, update, delete, write.

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

ah sorry

I think you should add him to the ['read']
part of the array
if (!in_array("user:$userId", $readPermissions)) {
$readPermissions['read'][] = "user:$userId";
}

And create this part if it doesn't exist

Error updating document: Invalid permissions: Every permission must be of type string.

I also tried it with the [] gone but then the same error occurs as in the question.

You might want to take a look at what $document['$permissions']
is. Also, see: https://appwrite.io/docs/permissions

So I basically have to add use Appwrite\Models\Permission;
and then use Permission::delete(Permission::ROLE_USER, '5c1f88b42259e'),
?

Erre

Close

Whats missing?

Role::User('id')
And, btw, permissions is a list (rather than associative array)

ah okay


thanks that helped a lot! its working now.

[SOLVED] PHP Update Document Permission
Recommended threads
- 2 Columns still processing since yesterd...
Hey o/ Yesterday (around <t:1758045600:f>), I created a database and added several columns to it. After about 15 minutes, most of the "processing" tags disappe...
- 503 Timeout when Updating or Upserting D...
Hey I’m running into an issue when trying to update or upsert a row in Appwrite. The request hangs for a while and then throws this error: ``` AppwriteException...
- Row with the requested ID already exists...
I’m hitting a blocking issue creating rows in Appwrite (both from the console and my React Native app). After successfully inserting the first row, every subseq...
