REST API works, but I cannot pass json parameter to it, getting "Unable to decode supplied JSON".

I am running CiviCRM 4.6.8 on Wordpress.

I have properly identified SITE KEY and API KEY, and I can run REST query with an empty json dictionary as parameter:


which gives me 25 contact records in a json data structure.

But when I try to add a json parameter (copied from API Explorer):

https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&api_key=secret1&key=secret2&json={%22sequential%22:1,%22email%22:%[email protected]%22}

..I get the following error:

{"is_error":1,"0":"error_message","1":"Unable to decode supplied JSON."}

What am I doing wrong?

  • Have you tried passing double-quotes directly (rather than the %22 encoding)?
    – DaveD
    Commented Sep 21, 2015 at 21:51
  • yes, with the same result
    – movonw
    Commented Sep 21, 2015 at 22:19
  • I never had any luck getting json parameters to work in GET requests. As Xavier said it works fine in POST, though. Commented Sep 22, 2015 at 10:32
  • I get the same issue with the json={"last_name":"somename"} way of phrasing the query. Now, I am, admittedly, brand new to Civi So all input is very welcome :) I will be creating services that query and hopefully update Civi records and the json= method looks like it would allow for a more flexible interface, in that I can easily construct a json query and insert it. It will be more fiddly to maintain separate arguments or even interfaces to represent the different queries I may want to call. SO, does the API call with json={some json query here}, not work at all? I took the examples from the Commented Nov 8, 2016 at 16:46
  • It doesn't work for me either... Commented Apr 6, 2017 at 1:01

3 Answers 3


I would recommend you to use post instead of get to communicate with the rest api, both because it would allow you to avoid having the keys "in clear" in the get url (and therefore written in the log an so on), but also because you don't have to deal with url encoding of the parameters.

btw, you don't have to put the param in the json most of the time, so you can directly call

https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&api_key=secret1&key=secret2&sequential=1&[email protected]&json=1

  • I tried to do a POST. When I sent the json parameter I had the same error as in the original question. When I sent parameters separately, I got a proper XML response. Because I wanted a JSON date returned, I have also added a json={} parameter which triggers returning data as JSON. Still, there seems to be a bug in CiviCRM regarding JSON parsing.
    – movonw
    Commented Sep 22, 2015 at 13:14
  • if you want json, put json=1
    – Xavier
    Commented Sep 22, 2015 at 13:34
  • you obviously don't have to url encode the json param, just "normal" json, should work fine. try decoding the json on the client, see if it works. The decoding message is fairly early in the code, it really just mean that, the formatting is wrong somewhere ;)
    – Xavier
    Commented Sep 22, 2015 at 13:37
  • Addition: If you want options, its for example "&options[limit]=100", and not what the api explorer says. Implicitly mentioned in docs.civicrm.org/dev/en/latest/api/interfaces Commented Jun 13, 2020 at 13:29

Strangely, le API explorer says to call the REST API with request attributes in the json parameter, like this:

https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&api_key=secret1&key=secret2&json={%22sequential%22:1,%22email%22:%[email protected]%22}

But, as explained in the documentation, the json parameters just defines if the result should be json or xml. it just takes values 0 or 1.

All parameters set in the json example have to be passed in the query string.

In your case, your syntax should be:

https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&api_key=secret1&key=secret2&sequential=1&[email protected]&json=1

which will return a json response


https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&api_key=secret1&key=secret2&sequential=1&[email protected]

for an XML response.

By the way, for security reasons, parameters should be passed in POST, especially api_key and key to prevent them for being store in logs.


I was encountering this error no matter what I did until I started dumping values near where this error is thrown.

I was able to resolve it by adding stripslashes() before json_decode().

I created this PR but I don't know if it is correct. That depends on what is adding the escaping to the string.

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.