Ok - it's my first time diving into REST API - First of all trying to get it to return me just the data for one specific contact. It works great in the browser but on the command line no matter what I try I keep getting the data for the first 25 contact_ids in the civicrm_contact table; it's simply ignoring my very specific attempts to just give me contact_id: 358383;

I've tried [and they all return data for the first 25 contact_ids in either json or xml - that all works fine]:

CiviCRM 4.6 LTS - and Drupal 7.x

curl -i -H "Content-Type: application/json" -X POST -d '{"contact_id":"358383"}' "https://example.org/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&api_key=XXX&key=XXX"

curl -i -H "Content-Type: application/json" -X POST "https://example.org/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&api_key=XXX&key=XXX&json={"contact_id":"358383"}"


curl -i -H "Content-Type: application/json" -X POST "https://example.org/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&api_key=XXX&key=XXX&json={contact_id:358383}"

If anyone has any examples/suggestions that would be great! I'm curl-ing on MacOSX - from what I've been reading "/%22' syntax could be important.

  • 1
    Really worth looking into what the encoding means, and how it's interacting with both your commandline environment and the webserver. I'd aim to reduce extra "noise" if you can ({contact_id:1} works as well as {"contact_id":"1"}), and to understand what encoding you require (putting a " inside the quotes at the beginning and end of the URL will cut the rest of your URL off, which I suspect why you found encoding " to %22 helped, but maybe wrapping the URL in a pair of ' would have been simpler?). Commented Nov 13, 2016 at 1:52

2 Answers 2


I just created a working example for curl and tested it on linux. Do also URL encode the curly braces. I used the this website to do that. So {"contact_id":"358383"} becomes %7B%22contact_id%22%3A%22358383%22%7D .

I used curl with different parameters. My example is

curl -X POST "http://localhost/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&api_key=XXX&key=XXX&json=%7B%22sequential%22%3A%221%22%2C%22id%22%3A%222%22%7D"

Update: I see I am a bit misleaded by the example generated by the api explorer. JSON for parameters is not mandatory. It is possible to use the following format.

 curl -X POST "http://localhost/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&api_key=XXX&key=XXX&json=1&contact_id=2"

See REST API without JSON just key=value .


Try adding: option.limit=0 to you request?



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.