Q:

Get user info from Knackhq.com API with PHP

I've built out a few PHP pages using Knackhq.com's API.  The documentation isn't very good on how to set up specific calls so I wanted to post this question to the community in hopes it will help myself and possibly others to accomplish this quickly.
I need to return a user's login status and information with a PHP post.  My code below doesn't return any objects, thanks for the help.
<?php

/* Query all of the records in an object using GET */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.knackhq.com/v1/applications/XXXXAPP-IDXXXX/session");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"email":"MY-EMAIL-HERE","password":"MY-PASSWORD-HERE"}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "X-Knack-Application-Id: " . $kn_appID, "X-Knack-REST-API-Key: " . $kn_APIKey)); 
$returnVal = json_decode(curl_exec($ch));

echo json_encode($returnVal);

// close our curl connection
curl_close($ch);

?>

A:

Thanks Muzza, I did work through the instructions you linked prior to posting the question... right part of their documentation but Knackhq doesn't quite work out the answer.  Also, nice catch on "GET" should be "POST", I changed it in my solution below.
To make this work you need to use "$_SESSION['VAR_NAME'] and attach the POST fields to form/login values.  After the user submits their email and password the PHP POST will verify they're a registered user and return the ID, Token, Email, Status, Full Name, etc.  Once returned you can link each of these to a "$_SESSION['VAR_NAME']" which will follow them throughout your site.  At any point you can include these sessions in API calls to your database to filter records connected to this specific user (each time the user visits the site they will need to login again to generate working sessions).
Here is my code:
<?php

session_start();

$accessuserArray = array(
'email' => $_POST['your_html_form_email_value'],
'password' => $_POST['your_html_form_password_value']
); 

$accessuserData = json_encode($accessuserArray);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.knackhq.com/v1/applications/XXXAPP-IDXXX/session");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $accessuserData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 
$returnVal = json_decode(curl_exec($ch));

$_SESSION["userId"] = $returnVal->session->user->id;
$_SESSION["userNameFirst"] = $returnVal->session->user->values->field_66->first;
$_SESSION["userNameLast"] = $returnVal->session->user->values->field_66->last;
$_SESSION["userEmail"] = $returnVal->session->user->values->field_67->email;

curl_close($ch);

?>

Hope this helps others!

