Page 1 of 2

php curl json serialization error

Posted: Sun May 04, 2014 5:33 pm
by Douglas Pinto

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!


php curl json serialization error

Posted: Mon May 05, 2014 9:46 am
by Evgene Karachevtsev

Hello Douglas,

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


php curl json serialization error

Posted: Mon May 05, 2014 11:35 am
by Douglas Pinto

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


php curl json serialization error

Posted: Mon May 05, 2014 12:10 pm
by Evgene Karachevtsev

Hello again,

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


php curl json serialization error

Posted: Tue May 06, 2014 3:00 am
by Douglas Pinto

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


php curl json serialization error

Posted: Tue May 06, 2014 11:51 am
by Evgene Karachevtsev

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.

php curl json serialization error

Posted: Wed May 07, 2014 7:16 pm
by Douglas Pinto

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


php curl json serialization error

Posted: Wed May 07, 2014 9:44 pm
by Kateryna Grynko

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).


php curl json serialization error

Posted: Wed May 07, 2014 11:05 pm
by Douglas Pinto

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


php curl json serialization error

Posted: Thu May 08, 2014 11:03 am
by Evgene Karachevtsev

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