Back

guys what causes this problem i wanna create document with a relation to another document.

  • 0
  • Databases
  • Web
Rovar2000
23 Nov, 2023, 12:19

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", }, }

TL;DR
User is trying to create a document with a relation to another document. They are getting a 500 internal server error. They are unsure if they should send only the ID or the whole collection data when creating an item with a relation. They are also getting an "unauthorized user" error when creating an item. The user has tried various solutions but none have fixed the issue. The user also received a 400 error with the message "Invalid `permissions` param: Permission `create("any")` is not allowed" when trying to add permissions to the document creation. Possible solution: Check if the related document has permissions set. Use
Ernest
23 Nov, 2023, 13:40

Are you able to create a document using the appwrite console?

Rovar2000
23 Nov, 2023, 13:51

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", }, }

Rovar2000
23 Nov, 2023, 14:03

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.

Haimantika
23 Nov, 2023, 14:34

@Rovar2000 see if the solution here can help you - https://discord.com/channels/564160730845151244/1176748823817752667

Drake
23 Nov, 2023, 14:45

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

Drake
23 Nov, 2023, 14:47

You can't put create permission on a document because the document would already be created

Drake
23 Nov, 2023, 14:48

Don't include both write and delete and update because write is an alias for delete and update

Drake
23 Nov, 2023, 14:49

Do you have any other relationships in this collection?

Rovar2000
23 Nov, 2023, 19:25

yes my items have a one to many relationship with category.

Rovar2000
23 Nov, 2023, 19:48

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)

D5
23 Nov, 2023, 20:10

What's your endpoint URL?

D5
23 Nov, 2023, 20:11

Does the related document have permissions set?

Rovar2000
24 Nov, 2023, 15:26

i gave it any in the console.

Rovar2000
24 Nov, 2023, 15:39
Rovar2000
24 Nov, 2023, 15:39

the default url

D5
24 Nov, 2023, 15:39

@Rovar2000 You're self hosting?

D5
24 Nov, 2023, 15:39

Or using the cloud solution?

Rovar2000
24 Nov, 2023, 15:44

i think the cloud one not self hosting, yeah i'm using the cloud console

Rovar2000
24 Nov, 2023, 19:47

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.

ideclon
26 Nov, 2023, 16:18

You should be setting the ID, IIRC

Rovar2000
26 Nov, 2023, 16:20

Well i have solved it turned out i sent a wrong attribute parameter, popular must be popularity

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more