Back

[SOLVED] Problems with adding a new document in appwrite via function

  • 0
  • Self Hosted
  • Functions
  • Databases
  • Cloud
sidney
18 Jul, 2023, 14:50

Maybe i should not create an array EventData with all these elements because it is more complicated

TL;DR
The user was having problems with adding a new document in Appwrite via a function. The issue was that the `eventData` was missing from the payload. The user tried deleting `eventData` and only using `payload`, but it didn't solve the problem. Another user suggested removing `ID::unique()` from the payload, but it didn't work either. The user also checked for errors, but there were none. Finally, another user provided the correct payload format to try, which included the `eventData` attribute and removed the `ID::unique()` placeholder.
Binyamin
18 Jul, 2023, 14:50

This is not the problem That is just fine

Binyamin
18 Jul, 2023, 14:51

Did you try to send the data without eventId?

sidney
18 Jul, 2023, 14:52

yes it failed with no response showing

Binyamin
18 Jul, 2023, 14:54

Mmm We can try one more thing Can you share the payload data?

sidney
18 Jul, 2023, 14:56

async : true data : "{\n eventData: {\n eventId: ID::unique(),\n title: New Event,\n description: Event description,\n owner: 648051d777d7ac754e75,\n image: 64b4fec93805d8f21470,\n location: Event location,\n date: 18/07/2023 11:57:45.251,\n endDate: 19/07/2023 11:58:17.701,\n innocaps: [tag1, tag2, tag3]\n }\n

sidney
18 Jul, 2023, 14:56
Binyamin
18 Jul, 2023, 14:57

You send the ID::unique() it won't work with it Can you replace the whole string with this and try

TypeScript
{
  "eventData": {
    "eventId": "unique()",
    "title": "New Event",
    "description": "Event description",
    "owner": "648051d777d7ac754e75",
    "image": "64b4fec93805d8f21470",
    "location": "Event location",
    "date": "18/07/2023 11:57:45.251",
    "endDate": "19/07/2023 11:58:17.701",
    "innocaps": ["tag1", "tag2", "tag3"]
  }
}
sidney
18 Jul, 2023, 14:59

{"data":"{\n eventData: {\n eventId: unique(),\n title: New Event,\n description: Event description,\n owner: 648051d777d7ac754e75,\n image: 64b4fec93805d8f21470,\n location: Event location,\n date: 18/07/2023 11:57:45.251,\n endDate: 19/07/2023 11:58:17.701,\n innocaps: [tag1, tag2, tag3]\n }\n}","async":true}

sidney
18 Jul, 2023, 15:00
Binyamin
18 Jul, 2023, 15:00

Good And you got on this one?

sidney
18 Jul, 2023, 15:02

the execution with the payload that you sent was failed

Drake
19 Jul, 2023, 00:16

please share the error and updated code. Please also share the list of attributes for your events collection

sidney
19 Jul, 2023, 12:26

Response: {"success":false,"message":"Invalid payload. eventData is missing."} Logs: NULL

sidney
19 Jul, 2023, 12:28
Drake
19 Jul, 2023, 16:12

can you add var_dump($req['payload']) before the json_decode().

Do you see anything in the errors tab?

sidney
20 Jul, 2023, 10:47

Response: {"success":false,"message":"Invalid payload. eventData is missing."} Logs: string(360) "{ "eventData": { "eventId": ID::unique(), "title": "Sample Event", "description": "This is a sample event description.", "owner": "648051d777d7ac754e75", "image": "64b4fec93805d8f21470", "location": "Sample Location", "date": "20/07/2023 11:57:45.251", "endDate": "21/07/2023 11:57:45.251", "innocaps": ["innocap"] } } "

sidney
20 Jul, 2023, 10:47

No, there are no errors recorded

Drake
20 Jul, 2023, 17:08

You should not be putting ID::unique() in there. that was already mentioned to you

sidney
21 Jul, 2023, 07:47

No, this doesn't solve the problem for me

Drake
21 Jul, 2023, 15:57

what's the new output and code?

sidney
24 Jul, 2023, 10:09

Response: 'Invalid payload. eventData is missing. Logs: string(341) "{ "eventId": "ID::unique()", "title": "Sample Event", "description": "This is a sample event description.", "owner": "648051d777d7ac754e75", "image": "64b4fec93805d8f21470", "location": "Sample Location", "date": "24/07/2023 11:57:45.251", "endDate": "25/07/2023 11:57:45.251", "innocaps": ["innocap"] } "

Drake
24 Jul, 2023, 15:16

so that's your $req['payload']...do you see eventData in there?

harley_mlt
24 Jul, 2023, 16:53

I solved it by deleting eventData and only using payload. It works now

Drake
24 Jul, 2023, 16:56

[SOLVED] Problems with adding a new document in appwrite via function

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