POST Call Example in PHP

Call example »POST« in PHP

$identifier = '9b03c8cdf967d24a';
$private_key = '0a68ff8b77272baf5a04f3b656f27fb5250438bc21d7707515a1b506a3a8491b';
 
// GET params
$action = 'updateSurvey';       // Function to execute
$survey_id = '7050';        // ID of survey
$params = '';        // other parameters needed for function execution
 
// POST data
$post_data = array(
 "title" => "New survey title"
);
 
// Prepare data for hashing
$request_method = 'POST';
$request = 'https://www.1ka.si/api/'.$action.'/survey/'.$survey_id.$params;
$raw_post_data = http_build_query($post_data);
 
$data = $request_method . $request . $raw_post_data;
 
// Calculate hash (token)
$token = hash_hmac('sha256', $data, $private_key);
 
// Prepare call – we add parameters 'identifier' and 'token'
$ch = curl_init($request.'&identifier='.$identifier.'&token='.$token);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data)); // JSON string za POST
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_method);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
// Execute call
$result = curl_exec($ch);

<< Back to Examples

1KA is free to use for basic users