Sample PHP Code

This page shows you how to use PHP to query the Arctic Spas API.

Standard CURL Request Function

<?php

function do_api_call($postfields) {

	$api_end_point_url = "https://api.arcticspascore.com/live/";
	$api_key = "contact hello@jucra.com for api key format";
	
	###########
	//urlify the data for the POST query
	###########
	$fields_string = http_build_query($postfields);
 
 	###########
 	//prepare curl request
	###########
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $api_end_point_url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [$api_key]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
	curl_setopt($ch, CURLOPT_POST, count($postfields));
	curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	
	###########
	//make the request to remote api
	###########
    $result = curl_exec($ch);

	###########
	//return json result
	###########
	return $result;

}

?>

Standard Query

<?php

#########
//connect to Arctic API and get closest dealer
//see: https://api.arcticspascore.com/docs/get_closest_dealer/
#########
	
#########
//get form values
#########
$ip = $_SERVER['REMOTE_ADDR'];
		
#########
//prepare the fields for transit
#########
$postfields = array(
     'action' => "get_closest_dealer",
     'search_type' => "ip",
     'ip' => $ip,
);
	
#########
//query the arctic api and get the json response
#########
$result = do_api_call($postfields);
		
#########
//convert json to php array so we can parse
#########
$result_array = json_decode($result,TRUE);
		
#########
//get the response code returned by Arctic api
#########
$response_code = $result_array["MainResponse"]["ResponseCode"];

?>