Answers.Body: <p>The last one look OK to me, the JSON parameter AFAIK is there just so I get the results in JSON format rather than XML format. </p>
  
  <p>But are you doing your api call with the REST, in Javascript or in PHP? And did you check the API chapter in the Developer Guide? It can be found here: <a href="https://docs.civicrm.org/dev/en/latest/api/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/api/</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-26T08:15:17.180Z
Answers.Text: The API explorer does not use `json: 1` but an object as shown in my first and second snippet. The documentation and the API explorer and the resources on the internet are not distinct regarding this. I am using the REST API and tbh I think all implementations are using the same interface.
Answers.UserDisplayName: Daniel W.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-26T08:18:55.273Z
Answers.Text: OK, in that case I would not expect the activity.id but just id? See the example from @Aidan?
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-26T08:21:03.507Z
Answers.Text: Thanks for your feedback. Question is not the name of the field, but where to place it and how many variants are legit. Please compare the documentation and the examples in the API browser. They are different.
Answers.UserDisplayName: Daniel W.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-26T08:31:00.897Z
Answers.Text: I immediately believe you :-) And I assume you are volunteering for the next CiviSprint to update the documentation :-)
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-26T08:35:44.597Z
Answers.Text: I know for good, documentation is hard work, don't get me wrong :)
Answers.UserDisplayName: Daniel W.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-26T09:12:06.157Z
Answers.Text: I appreciate that :-) But I sincerely would like to update the Developer Guide documentation at the next CiviSprint with as many people as possible so I am recruiting :-)
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-26T07:54:28.987Z
Answers.LastActivityDate: 2019-06-26T07:54:28.987Z
Answers.UserDisplayName: ErikH - CiviCooP
Answers.Body: <p>It looks like you're doing this via REST. The API explorer gives this:</p>
  
  <p><code>https://dmaster.demo.civicrm.org/sites/all/modules/civicrm/extern/rest.php?entity=Activity&amp;action=get&amp;api_key=userkey&amp;key=sitekey&amp;json={"sequential":1,"id":123,"options":{"limit":1}}</code></p>
  
  <p>If you explain more about what you are trying to do you may get better answers.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-26T08:18:31.070Z
Answers.Text: The structure of this request is different [in the docs](https://docs.civicrm.org/dev/en/latest/api/usage/#rest) vs in the API browser, look at the `json` parameter.
Answers.UserDisplayName: Daniel W.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-26T08:35:57.143Z
Answers.Text: REST API call can be specified in various ways - either with key=value pairs or a json object.  See https://civicrm.stackexchange.com/a/4977/225  If you think the documentation is bad, please help improve it: https://docs.civicrm.org/dev/en/latest/documentation/#contributing
Answers.UserDisplayName: Aidan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-26T08:06:47.560Z
Answers.LastActivityDate: 2019-06-26T08:06:47.560Z
Answers.UserDisplayName: Aidan
Body: <p>The parameters in the API are confusing, especially the depth + the <code>json</code> paramter.</p>
  
  <p>I have seen these three combinations and my question is, which variant is wrong and which is not.</p>
  
  <p>I can't figure out from the results what exactly is going on as most of my queries don't yet return what I'm expecting, so I want to get this clear first. I think Civi has some kind of fallback magic as in some requests I get <code>undefined_fields</code> but it returns correct results.</p>
  
  <hr>
  
  <p>Entity related stuff goes into the root level, as seen in different (inofficial) files:</p>
  
  <pre><code>{
    'api_key': '...',
    'activity.id': 123,
    'json': {
      'options': {
        'limit': 1
      }
    }
  }
  </code></pre>
  
  <hr>
  
  <p>The API Explorer suggest entity/attribute related stuff goes inside the <code>json</code> parameter:</p>
  
  <pre><code>{
    'api_key': '...',
    'json': {
      'activity.id': 123,
      'options': {
        'limit': 1
      }
    }
  }
  </code></pre>
  
  <hr>
  
  <p>Variant without nesting and <code>json</code> beeing integer as seen on <a href="https://docs.civicrm.org/dev/en/latest/api/usage/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/api/usage/</a> :</p>
  
  <pre><code>{
    'api_key': '...',
    'activity.id': 123,
    'limit': 1
    'json': 1
  }
  </code></pre>
  
  <p>P.S I'm accessing the REST API via HTTP calls to <code>/sites/all/modules/civicrm/extern/rest.php</code>.</p>
  
Tags: <api>
Title: `json` parameter in the request API
ThreadText: # `json` parameter in the request API
  
  (Asked by: username_0 on 2019-06-26)
  
  The parameters in the API are confusing, especially the depth + the `json` paramter.
  
  I have seen these three combinations and my question is, which variant is wrong and which is not.
  
  I can't figure out from the results what exactly is going on as most of my queries don't yet return what I'm expecting, so I want to get this clear first. I think Civi has some kind of fallback magic as in some requests I get `undefined_fields` but it returns correct results.
  
  ---
  
  Entity related stuff goes into the root level, as seen in different (inofficial) files:
  
  ```
  {
    'api_key': '...',
    'activity.id': 123,
    'json': {
      'options': {
        'limit': 1
      }
    }
  }
  
  ```
  
  ---
  
  The API Explorer suggest entity/attribute related stuff goes inside the `json` parameter:
  
  ```
  {
    'api_key': '...',
    'json': {
      'activity.id': 123,
      'options': {
        'limit': 1
      }
    }
  }
  
  ```
  
  ---
  
  Variant without nesting and `json` beeing integer as seen on <https://docs.civicrm.org/dev/en/latest/api/usage/> :
  
  ```
  {
    'api_key': '...',
    'activity.id': 123,
    'limit': 1
    'json': 1
  }
  
  ```
  
  P.S I'm accessing the REST API via HTTP calls to `/sites/all/modules/civicrm/extern/rest.php`.
  
  **Tags:** api
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-06-26. Score: 1
  
  The last one look OK to me, the JSON parameter AFAIK is there just so I get the results in JSON format rather than XML format.
  
  But are you doing your api call with the REST, in Javascript or in PHP? And did you check the API chapter in the Developer Guide? It can be found here: <https://docs.civicrm.org/dev/en/latest/api/>
  
  > **Comments:**
  > **username_0**: The API explorer does not use `json: 1` but an object as shown in my first and second snippet. The documentation and the API explorer and the resources on the internet are not distinct regarding this. I am using the REST API and tbh I think all implementations are using the same interface.  
  > **username_1**: OK, in that case I would not expect the activity.id but just id? See the example from @username_2?  
  > **username_0**: Thanks for your feedback. Question is not the name of the field, but where to place it and how many variants are legit. Please compare the documentation and the examples in the API browser. They are different.  
  > **username_1**: I immediately believe you :-) And I assume you are volunteering for the next CiviSprint to update the documentation :-)  
  > **username_0**: I know for good, documentation is hard work, don't get me wrong :)  
  > **username_1**: I appreciate that :-) But I sincerely would like to update the Developer Guide documentation at the next CiviSprint with as many people as possible so I am recruiting :-)  
  
  ---
  
  ### Answer by username_2 on 2019-06-26. Score: 1
  
  It looks like you're doing this via REST. The API explorer gives this:
  
  `https://dmaster.demo.civicrm.org/sites/all/modules/civicrm/extern/rest.php?entity=Activity&action=get&api_key=userkey&key=sitekey&json={"sequential":1,"id":123,"options":{"limit":1}}`
  
  If you explain more about what you are trying to do you may get better answers.
  
  > **Comments:**
  > **username_0**: The structure of this request is different [in the docs](https://docs.civicrm.org/dev/en/latest/api/usage/#rest) vs in the API browser, look at the `json` parameter.  
  > **username_2**: REST API call can be specified in various ways - either with key=value pairs or a json object.  See https://civicrm.stackexchange.com/a/4977/225  If you think the documentation is bad, please help improve it: https://docs.civicrm.org/dev/en/latest/documentation/#contributing  
  
  ---
  
  