Answers.Body: <p>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.</p>
  
  <p>btw, you don't have to put the param in the json most of the time, so you can directly call</p>
  
  <p><a href="https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=secret1&amp;key=secret2&amp;sequential=1&amp;email=marcin@akcja.pl&amp;json=1">https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=secret1&amp;key=secret2&amp;sequential=1&amp;email=marcin@akcja.pl&amp;json=1</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-13T13:29:47.693Z
Answers.Text: Addition: If you want options, its for example "&options[limit]=100", and not what the api explorer says. Implicitly mentioned in https://docs.civicrm.org/dev/en/latest/api/interfaces/
Answers.UserDisplayName: Weidenrinde
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T13:14:24.173Z
Answers.Text: 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.
Answers.UserDisplayName: movonw
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T13:34:12.927Z
Answers.Text: if you want json, put json=1
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T13:37:23.830Z
Answers.Text: 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 ;)
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T04:10:49.593Z
Answers.LastActivityDate: 2015-09-22T13:34:36.860Z
Answers.LastEditDate: 2015-09-22T13:34:36.860Z
Answers.UserDisplayName: Xavier
Answers.Body: <p>Strangely, le API explorer says to call the REST API with request attributes in the <strong>json</strong> parameter, like this:</p>
  
  <p><code>https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=secret1&amp;key=secret2&amp;json={%22sequential%22:1,%22email%22:%22marcin@akcjademokracja.pl%22}</code></p>
  
  <p>But, as explained in <a href="https://docs.civicrm.org/dev/en/latest/api/usage/#rest" rel="nofollow noreferrer">the documentation</a>, the <code>json</code> parameters just defines if the result should be json or xml. it just takes values <strong>0</strong> or <strong>1</strong>.</p>
  
  <p>All parameters set in the json example have to be passed in the query string.</p>
  
  <p>In your case, your syntax should be:</p>
  
  <p><code>https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=secret1&amp;key=secret2&amp;sequential=1&amp;email=marcin@akcjademokracja.pl&amp;json=1</code> </p>
  
  <p>which will return a json response</p>
  
  <p>or:</p>
  
  <p><code>https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=secret1&amp;key=secret2&amp;sequential=1&amp;email=marcin@akcjademokracja.pl
  </code> </p>
  
  <p>for an XML response.</p>
  
  <p>By the way, for security reasons, parameters should be passed in POST, especially <code>api_key</code> and <code>key</code> to prevent them for being store in logs.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-29T08:40:23.790Z
Answers.LastActivityDate: 2018-08-29T08:40:23.790Z
Answers.UserDisplayName: Bastien Ho
Answers.Body: <p>I was encountering this error no matter what I did until I started dumping values near where this error is thrown.</p>
  <p>I was able to resolve it by adding <code>stripslashes()</code> before <code>json_decode()</code>.</p>
  <p>I created this <a href="https://github.com/civicrm/civicrm-core/pull/23089" rel="nofollow noreferrer">PR</a> but I don't know if it is correct. That depends on what is adding the escaping to the string.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-02T00:47:20.907Z
Answers.LastActivityDate: 2022-04-02T00:47:20.907Z
Answers.UserDisplayName: ginkgoMZD
Body: <p>REST API works, but I cannot pass <em>json</em> parameter to it, getting "Unable to decode supplied JSON".</p>
  
  <p>I am running CiviCRM 4.6.8 on Wordpress.</p>
  
  <p>I have properly identified SITE KEY and API KEY, and I can run REST query with an empty json dictionary as parameter:</p>
  
  <p><code>https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=secret1&amp;key=secret2&amp;json={}</code></p>
  
  <p>which gives me 25 contact records in a json data structure.</p>
  
  <p>But when I try to add a json parameter (copied from API Explorer):</p>
  
  <p><code>https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=secret1&amp;key=secret2&amp;json={%22sequential%22:1,%22email%22:%22marcin@akcjademokracja.pl%22}</code></p>
  
  <p>..I get the following error:</p>
  
  <p><code>{"is_error":1,"0":"error_message","1":"Unable to decode supplied JSON."}</code></p>
  
  <p>What am I doing wrong?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-21T21:51:02.700Z
Comments.Text: Have you tried passing double-quotes directly (rather than the %22 encoding)?
Comments.UserDisplayName: DaveD
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-21T22:19:40.267Z
Comments.Text: yes, with the same result
Comments.UserDisplayName: movonw
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-22T10:32:51.593Z
Comments.Text: I never had any luck getting json parameters to work in GET requests. As Xavier said it works fine in POST, though.
Comments.UserDisplayName: Andrew West
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-08T16:46:10.267Z
Comments.Text: 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
Comments.UserDisplayName: CiviStackStu
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-06T01:01:06.343Z
Comments.Text: It doesn't work for me either...
Comments.UserDisplayName: Francis Poisson
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-31T02:14:16.800Z
Comments.Text: json does not work for me either...
Comments.UserDisplayName: Serge
Tags: <api><rest>
Title: REST API: Unable to decode supplied JSON
ThreadText: # REST API: Unable to decode supplied JSON
  
  (Asked by: username_0 on 2015-09-21)
  
  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:
  
  `https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&api_key=secret1&key=secret2&json={}`
  
  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:%22marcin@akcjademokracja.pl%22}`
  
  ..I get the following error:
  
  `{"is_error":1,"0":"error_message","1":"Unable to decode supplied JSON."}`
  
  What am I doing wrong?
  
  **Tags:** api, rest
  
  > **Comments:**
  > **username_1**: Have you tried passing double-quotes directly (rather than the %22 encoding)?  
  > **username_0**: yes, with the same result  
  > **username_2**: I never had any luck getting json parameters to work in GET requests. As username_6 said it works fine in POST, though.  
  > **username_3**: 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  
  > **username_4**: It doesn't work for me either...  
  > **username_5**: json does not work for me either...  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_6 on 2015-09-22. Score: 8
  
  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=marcin@akcja.pl&json=1>
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_6**: if you want json, put json=1  
  > **username_6**: 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 ;)  
  > **username_7**: Addition: If you want options, its for example "&options[limit]=100", and not what the api explorer says. Implicitly mentioned in https://docs.civicrm.org/dev/en/latest/api/interfaces/  
  
  ---
  
  ### Answer by username_8 on 2018-08-29. Score: 0
  
  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:%22marcin@akcjademokracja.pl%22}`
  
  But, as explained in [the documentation](https://docs.civicrm.org/dev/en/latest/api/usage/#rest), 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=marcin@akcjademokracja.pl&json=1`
  
  which will return a json response
  
  or:
  
  `https://foo.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&api_key=secret1&key=secret2&sequential=1&email=marcin@akcjademokracja.pl`
  
  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.
  
  
  ---
  
  ### Answer by username_9 on 2022-04-02. Score: 0
  
  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](https://github.com/civicrm/civicrm-core/pull/23089) but I don't know if it is correct. That depends on what is adding the escaping to the string.
  
  
  ---
  
  