Back

[SOLVED] Troubleshooting Appwrite PHP Function: Document Deletion Issue

  • 0
  • Databases
  • Functions
  • Self Hosted
  • Cloud
Binyamin
10 Jul, 2023, 13:34

But, when it fails, what error do you see?

TL;DR
Title: [SOLVED] Troubleshooting Appwrite PHP Function: Document Deletion Issue - Issue: Invalid payload. eventData is missing. - Solution: Adjust the code to include payload and ensure the collectionId and documentId are not empty. Change the line from `$database->deleteDocument($collectionId, [$documentId]);` to `$response = $database->deleteDocument($databaseId, $collectionId, $documentId);`. Parse the payload using `json_decode($req['payload'], true)` instead of `data`. Make sure to send the collectionId in the JSON payload. Verify the payload and response in
sidney
10 Jul, 2023, 13:46

it says no errors recorded

Binyamin
10 Jul, 2023, 14:09

And no response?

sidney
10 Jul, 2023, 14:12

Yes there is no response if i send the payload with the correct request.

Binyamin
10 Jul, 2023, 14:18

It means it crashes before Can you share the payload and the response in the network tab? Like so:

sidney
10 Jul, 2023, 14:27

the payload: {

"documentId": "64abc0eee265357c5f51" }

Binyamin
10 Jul, 2023, 14:28

Can you share screenshot like this

sidney
10 Jul, 2023, 14:28

ok

sidney
10 Jul, 2023, 14:32
Binyamin
10 Jul, 2023, 14:37

Why is your data includes the text the payload:

Binyamin
10 Jul, 2023, 14:37

Can you share this screen giht before you're clicking the Execute now button

sidney
10 Jul, 2023, 14:44
sidney
10 Jul, 2023, 14:45

I updated the code and after i send the payload the response is: {"success":false,"message":"Missing required data: collectionId or documentId"}

Binyamin
10 Jul, 2023, 15:00

Try to put all the custome data in one line, like such:

Binyamin
10 Jul, 2023, 15:00
TypeScript
{"documentId":"64abc0eee265357c5f51"}
Binyamin
10 Jul, 2023, 15:08

Ohh And also you haven't send the collectionId in the JSON

sidney
11 Jul, 2023, 07:47

I also sent the collection id but i get the same error

Binyamin
11 Jul, 2023, 13:33

In this if add the payload and share it, so we can spot the issue

TypeScript
    if (empty($collectionId) || empty($documentId)) {
            return $res->json([
                'success' => false,
                'message' => 'Missing required data: collectionId or documentId',
                'payload' => $req['payload']
            ], 400);
        }

Also, in this line you'll need to parse the payload not data

TypeScript
 $requestData = json_decode($req['payload'], true);
sidney
11 Jul, 2023, 13:38

Yes, I have realised the problem. The problem was this line: $database->deleteDocument($collectionId, [$documentId]); The document Id was an array instead of string. So I changed this line into this: $response = $database->deleteDocument($databaseId, $collectionId, $documentId);. Now it works

Binyamin
11 Jul, 2023, 13:39

Great !

Drake
12 Jul, 2023, 02:06

[SOLVED] Troubleshooting Appwrite PHP Function: Document Deletion Issue

sidney
18 Jul, 2023, 12:56

The logs: Warning: Trying to access array offset on value of type null in /usr/code-start/src/index.php on line 39

sidney
18 Jul, 2023, 12:57

response: title is required

sidney
18 Jul, 2023, 13:34

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

Drake
19 Jul, 2023, 00:15

I think you ahve the wrong thread

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