guys what causes this problem i wanna create document with a relation to another document.
- 0
- Databases
- Web
but it always give me internal error like this { name: "AppwriteException", code: 500, type: "general_unknown", response: { message: "Server Error", code: 500, type: "general_unknown", version: "0.11.35", }, }
Are you able to create a document using the appwrite console?
yeah i fixed that issue by adding the whole document of data for the relation, but it still bugs me can let me create this specific item cause i don't have premission to it even though i gave it all the pre mission.
this is my createDocument Action
const category = await categoriesRepository.getCategory(item.categoryId);
await Appwrite.databases.createDocument(
Environment.appwrite_database,
Environment.appwrite_collection_item,
ID.unique(),
{
userId: item.userId,
name: item.name,
price: item.price,
itemImage: item.image.url,
productionDate: item.productionDate,
expiredDate: item.expireDate,
quantity: item.quantity,
detail: item.detail,
category: category,
popular: 0,
deletedAt: null,
},
[
Permission.create(Role.any())
]
);
the error it logs right now {
name: "AppwriteException",
code: 400,
type: "general_argument_invalid",
response: {
message: "Invalid permissions
param: Permission create(any) is not allowed. Must be one of: read, update, delete, write.",
code: 400,
type: "general_argument_invalid",
version: "0.11.35",
},
}
const category = await categoriesRepository.getCategory(item.categoryId); await Appwrite.databases.createDocument( Environment.appwrite_database, Environment.appwrite_collection_item, ID.unique(), { userId: item.userId, name: item.name, price: item.price, itemImage: item.image.url, productionDate: item.productionDate, expiredDate: item.expireDate, quantity: item.quantity, detail: item.detail, category: category, popular: 0, deletedAt: null, }, [ Permission.read(Role.any()), Permission.write(Role.any()), Permission.delete(Role.any()), Permission.update(Role.any()), ] ); i changed it to this now the user is not authorized to do this action, AppwriteException: The current user is not authorized to perform the requested action.
@Rovar2000 see if the solution here can help you - https://discord.com/channels/564160730845151244/1176748823817752667
Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting
You can't put create permission on a document because the document would already be created
Don't include both write and delete and update because write is an alias for delete and update
Do you have any other relationships in this collection?
yes my items have a one to many relationship with category.
i excluded that but still the same problem persists, question is why when i create category nothing happens everything is okay but when i want to create item which has a relationship with category tells me my user is unauthorized to do the followinng action, AppwriteException: The current user is not authorized to perform the requested action. at Client.<anonymous> (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=949bebd3:850:17) at Generator.next (<anonymous>) at fulfilled (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=949bebd3:488:24)
What's your endpoint URL?
Does the related document have permissions set?
i gave it any in the console.
the default url
@Rovar2000 You're self hosting?
Or using the cloud solution?
i think the cloud one not self hosting, yeah i'm using the cloud console
but it's weird when i enable document security on the console of my collections it gives me 500 internal error from creating the document, and i gotta ask when creating an item with relation to another collection named category should i only send the id of the collection or the whole collection data? cause right now i'm sending the whole collection data.
You should be setting the ID, IIRC
Well i have solved it turned out i sent a wrong attribute parameter, popular must be popularity
Recommended threads
- Use different email hosts for different ...
Hello, I have 2 projects and i want to be able to set up email templates in the projects. Both projects will have different email host configurations. I see ...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...
- Edit ID of an existing collection
Hi there. Is it possible to edit an ID of an existing collection? Right now it looks impossible from AppWrite cloud at least.