2

Been trying to get this to work for hours. Help would be greatly appreciated. userkey and sitekey are replaced with actual keys.

I'm trying to run in a php file:

$result = curl -X POST "https://www.mysite.org/sites/all/modules/civicrm/extern/rest.php?entity=Membership&action=get&api_key=userkey&key=sitekey&json={"sequential":1,"return":"membership_type_id,id,end_date","contact_id":2,"active_only":1,"options":{"limit":1,"sort":"join_date DESC"}}";

I get the error:

PHP Parse error:  syntax error, unexpected 'POST' (T_STRING) in /home/spulver/civicrmapi.php on line 3

Any ideas how to fix?

2 Answers 2

4

I use CURL to call rest api. Here is the snippet you can ignore/remove many lines that sets curl variable.

$url = 'http://domain.org/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=getsingle&api_key=HR76BS710C&key=8c1cf9913fd674e08c8f27804334eb5a&json={"id":1}';

$ch = curl_init();
//http://php.net/manual/en/function.curl-setopt.php
//$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_TIMEOUT, 5);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, "");

//for debugging?
curl_setopt($ch, CURLOPT_VERBOSE, true);

$data = curl_exec($ch);
curl_close($ch);
$obj = json_decode($data);

HTH

Pradeep

0
0

you need to replace the url parameters api_key and key with the relevant keys. More information can be found in the developer documents.

2
  • in addition to @pradeep-nayak answer Jul 1, 2018 at 21:15
  • Yes I have replaced the keys in my actual code. Not posting them here. THanks Jul 2, 2018 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.