Start a new topic

How to access Kinvey by PHP server?

Hello

I have seen a  this 3 year old post and are now in the same situation: https://support.kinvey.com/support/discussions/topics/5000048858


As soon as the user accepts some data I would like to send/store these data to Kinvey backend. The send will happen by my server (not from the users browser):

1. The User wants to publish data (confirm button) client-side

2. My server reacts on that confirmation and sends the data to Kinvey backend by PHP into a collection


So I'm pretty new to all of these. Concerning the 3 years old post: Is that still uptodate (using curl operations) or do you have any newer sample or link of such a communication from PHP (my server) to Kinvey backend? 


Regards


In between and with the link I have posted in my first message I was able to create a sample accessing Kinvey backend by PHP from my server. It's rather a handshake example just to check if it works. I post it here for others. The solution is to use the REST API and within PHP the key is using 'curl':

<?php

// This sample expects you to have already a user created in your Kinvey app pannel (IDENTITY > Users)
// It will not login or something, just checking the connection to your app is working
$username = "created_username";
$password = "created_password";

$curl = curl_init();

// Build connection and header data (get the App Key from the app pannel clicking on the '..." next to the app name
curl_setopt ($curl, CURLOPT_URL, "https://baas.kinvey.com/appdata/Your_App_Key");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Basic ".base64_encode($username . ":" . $password)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

// Access Kinvey backend
$result = curl_exec ($curl);
curl_close ($curl);
print $result;

?>

Hello Tayger,


We're happy that you found the solution and thank you for posting your solution back to this post.


Regards,


Billy Gee

You're welcome. I had a hard time to proceed with curl in PHP and to register/login user. In between I made it, was not that difficult. It's just a bit tough to learn/use Kinvey and curl at the same time. I will post all these working samples later on for anyone else being in the same situation.   


There was one thing I couldn't make clear: version setting. I'm using it that way in the header: 


curl_setopt ($ch, CURLOPT_URL, "https://baas.kinvey.com/appdata/kid_SJnaQfYjG");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Basic ".base64_encode($username . ":" . $password), "X-Kinvey-API-Version: 2"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

The returned data is telling me this:

Array

(

    [version] => 3.9.61

    [kinvey] => hello myapp

    [appName] => myapp

    [environmentName] => Development

)


I would have expected to get returned something like " [version] => 2.x" as a confirmation of the version I have set.


Furthermore to set the version (1, 2, or 3) in the Kinvey console will still return "[version] => 3.9.61". Will the returned version always show the latest version number while internally the set version is used or did I just something wrong?


Regards

Login or Signup to post a comment