Start a new topic

php CRUD operations

How or where i can to find documentations and examples for to do CRUD operations from php?


I have for example one collection called ToDos. I need to create one record in this collection. Where i can to find one example for to do this? 


I im reading this http://devcenter.kinvey.com/rest/guides/datastore but really i don't know how apply this to php.


I have this example but i don't know how for example add create option of my ToDos Collection:


<?php

//tip: user a user account you created in kenvey admin panel.

//will make things easy when displaying the files later.

    $username = "kid_xxxx";

 $password = "c8xxxxx";

//set the endpoint in curl_init after https://baas.kinvey.com/

        $ch = curl_init("https://baas.kinvey.com/appdata/kid_xxxx");

 

//You need to send the appropriate header and use base64_encode function to scrable username and password

        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Basic ".base64_encode($username . ":" . $password),"X-Kinvey-API-Version: 3"));

//cURL after we send something give us a reply.

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//curl_exec opens the curl connection, grabs the info and saves it in $result2 variable

        $result2 = curl_exec($ch);

//Kinvey sends back JSON and it needs to be decoded using json_decode function in php..more fun functions listed on http://php.net

        $result2 = json_decode($result2, true);

//it's a good practice to close what you open.

        curl_close($ch);

//let's dump what we got back from Kinvey on to page

        var_dump($result2);

        //echo $result2;

?>





Regards,



Edgar mejia

1 Comment

Hello Edgar:


You can find a listing of our CRUD style-operations in our rest API guide


http://devcenter.kinvey.com/rest/guides/datastore


As an example, here's how a call to postman looks to add a collection for instance:


POST: https://baas.kinvey.com/appdata/<YourKinveyID>/<CollectionName>

Headers:

X-Kinvey-API-Version: 3

Content-Type: application/json

Authorization : Authorization code (appkey and mastersecret)


Post Body: {}



This same call is changed to include an id (/collectionName/id(unique) ) 

And then instead of {} you would pass in a valid json document.


Does that help?


Thanks,

Login or Signup to post a comment