Douglas Pinto
Posts: 0
Joined: Sun May 04, 2014 5:33 pm

php curl json serialization error

Hi guys,

I'm figthing this for 2 days already...

  • curl IS working properly;

  • YES I've retrieved all the data of this collection successfully, but...

    The issue is very simple:

    If I take the "where=" out, it creates a new record and if I use it it returns bad serialization error.

    I saw here that appery.io had a problem with this and it was partially solved by creating an array and then json_enconding it.

    OK, but how do I make it WITH this "where=" clause?

    The code is this: very simple:

    $message = "where={'pgId':'535b0c50e4b03823058510bd'}";

    $ch = curl_init("https://api.appery.io/rest/1/db/colle...");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS,$message);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Appery-Database-Id: xxxxxxxxxxxxxxxxxxxxxxxxxx','Content-type: application/json', 'Content-Length: '.strlen($message)));
    $result = curl_exec($ch);

    print_r(json_decode($result,true));

    Thanks a lot!

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

php curl json serialization error

Hello Douglas,

Please look at this link: http://docs.appery.io/documentation/b...
Parameter "where" should be urlencoded.

Douglas Pinto
Posts: 0
Joined: Sun May 04, 2014 5:33 pm

php curl json serialization error

Hi Levgen, thanks for your prompt answer.

Unfortunatelly, I'm stiil getting the same and only result...

I did this test, so you could see the results:
===================================
where={"pgId":"535b0c50e4b03823058510bd"} ;

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

php curl json serialization error

Hello again,

Did you use this function urlencode: http://www.php.net/manual/en/function... ?

Douglas Pinto
Posts: 0
Joined: Sun May 04, 2014 5:33 pm

php curl json serialization error

Hi , sorry for taking so long to answer. Too much work.

This is the code I am using and I am already using URLENCODE

Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

php curl json serialization error

Hello Douglas,

Try to compare two request.

  1. First one make in appery. Create one page application. And make request to your database from application (not from page "test" of your service). Look at requests parameter of this request
  2. To intercept request from php to appery.io (for example using wireshark)
  3. Compare these two requests.
Douglas Pinto
Posts: 0
Joined: Sun May 04, 2014 5:33 pm

php curl json serialization error

Hi Evgene, took me sometime to join everything but here it is:
As you will see now I can get all the list but the "where" clause is ignored.
Please note the red warning (I really do not have a clue about what is it)
Image

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

php curl json serialization error

Hi Douglas,

This is a client side error, it could happen depending on what you display on page.
Could you please expand the error and show the full console so we can see where and why it happened (it's cut on the screenshot).

Douglas Pinto
Posts: 0
Joined: Sun May 04, 2014 5:33 pm

php curl json serialization error

Hi Katya, sorry for that. Here is the PHP code:
$ch = curl_init("https://api.appery.io/rest/1/db/colle...=");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"GET");
curl_setopt($ch, CURLOPT_POSTFIELDS,urlencode("{'_id':'535b0cefe4b03823058510cd'}"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Appery-Database-Id: ','Content-type: application/json'));
$result = curl_exec($ch);

The error screen comes and fade so it took me a little while to get a screen copy of it.
Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

php curl json serialization error

Hello Dougls,

This code wokrs fine for me:

code$ch = curl_init();
$qry_str = urlencode('{"_id": "5368b612e4b07b9b72c61edc"}');
curl_setopt($ch, CURLOPT_URL, 'https://api.appery.io/rest/1/db/collections/todo?where='.$qry_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Appery-Database-Id: 530cxxxxxxxxxxxxxx21dd4','Content-type: application/json'));
$result = curl_exec($ch);
echo $result; /code
Here are the screenshots: http://www.screencast.com/t/IyKCuA75vl

Return to “Issues”