Skip to content

Instantly share code, notes, and snippets.

@jeremywrowe
Last active December 20, 2015 15:19
Show Gist options
  • Save jeremywrowe/6153397 to your computer and use it in GitHub Desktop.
Save jeremywrowe/6153397 to your computer and use it in GitHub Desktop.
This is an example of querying the chargify api and retrieving the status code of the response
<?php
$api_key = "";
$subdomain = "";
$handle = curl_init('https://'.$subdomain.'.chargify.com/customers/100000.json');
curl_setopt($handle, CURLOPT_USERPWD, $api_key . ":x");
curl_setopt($handle, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
$info = curl_getinfo($handle);
echo 'Status Code: ' . $info['http_code'] . PHP_EOL; // was it 200 (successful)
echo 'Content-Type: ' . $info['content_type'] . PHP_EOL; // showing that json was indeed returned
echo 'Response: ' . $response . PHP_EOL;
curl_close($handle);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment