PHP cURL

Access Our Data in PHP with cURL:

// API URL
$url = 'https://api.dataendpoints.com/chosen/endpoint/';

// Create a new cURL resource
$ch = curl_init($url);

// Setup request to send json via POST
$data = array(
   'api_key'   => 'your_api_key',
   'username'  => 'your_username',
   'output'    => 'xml', 
   'delimiter' => '', 

   //API
   'version'    => '1.0',
   'amount'     => '325000',
   'rate'       => '3.25',
   'years'      => '30',
   'start_date' => '2020-05-01'
);

$request = json_encode(array("data" => $data));

// Attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

// Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
   'Content-Type: application/json',
   'Content-Length: ' . strlen($payload))
);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);

// Return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute the POST request
$result = curl_exec($ch);

print $result;

// Close cURL resource
curl_close($ch);