Created
June 5, 2014 20:25
-
-
Save rondorkerin/34842b40c8c7abfe8ba7 to your computer and use it in GitHub Desktop.
An Example PHP Request With SharpSpring APIv1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$method = '<API method name>'; | |
$params = array('id' => <'the id of the object you want to retrieve'>); | |
$limit = <'query limit'>; | |
$offset = <'query id offset'>; | |
$requestID = <'an id for your request'>; | |
$accountID = '<your account ID>'; | |
$secretKey = '<your secret key>'; | |
$data = array( | |
'method' => $method, | |
'params' => $params, | |
'id' => $requestID, | |
); | |
$queryString = http_build_query(array('accountID' => $accountID, 'secretKey' => $secretKey)); | |
$url = "http://api.sharpspring.com/pubapi/v1/?$queryString"; | |
$data = json_encode($data); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($data) | |
)); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
echo $result; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment