Skip to content
Back

Trying using documents finding via curl in PHP

  • 0
  • Databases
  • Web
danielatik
13 Apr, 2025, 23:53

I cannot use the SDK and I'm trying to call via PHP to get the value of the paramaters of a document but I don't find the right documentation for this and an error appears:

This is my code:

<?php header('Content-Type: application/json'); ini_set('display_errors', 1); // Configuración de Appwrite extraída de config.js $DATABASE_ID = 'xxx'; $COLLECTION_ID = 'xxx'; $PROJECT_ID = 'xxx'; $ENDPOINT = 'https://cloud.appwrite.io/v1'; $API_KEY = 'xxx'; $userId = 'xxx'; $endpoint = "https://cloud.appwrite.io/v1/databases/$DATABASE_ID/collections/$COLLECTION_ID/documents"; $query = 'equal("userId","' . $userId . '")'; // IMPORTANTE: agregar queries[] como múltiples parámetros si hace falta más de uno $url = $endpoint . '?queries[]=' . urlencode($query); $headers = [ "Content-Type: application/json", "X-Appwrite-Project: $PROJECT_ID", "X-Appwrite-Key: $API_KEY" ]; $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $headers, CURLOPT_CUSTOMREQUEST => "GET", ]); $response = curl_exec($curl); if (curl_errno($curl)) { echo 'Error de cURL: ' . curl_error($curl); } else { $data = json_decode($response, true); echo json_encode($data, JSON_PRETTY_PRINT); } curl_close($curl); And this is the response I receive: { "message": "Invalid query: Syntax error", "code": 400, "type": "general_query_invalid", "version": "1.6.2" } Could you help me to find the right way to ask to documents?
TL;DR
Developers are attempting to retrieve document parameters through curl in PHP but encounter a syntax error. The issue lies in the query formatting. The correct way to structure the query is by encoding it and adding it as a multiple parameter. This solution should resolve the error and allow successful retrieval of the document parameters.
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