1

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.

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/

  • 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. – Daniel W. Jun 26 at 8:15
  • OK, in that case I would not expect the activity.id but just id? See the example from @Aidan? – ErikH - CiviCooP Jun 26 at 8:18
  • 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. – Daniel W. Jun 26 at 8:21
  • I immediately believe you :-) And I assume you are volunteering for the next CiviSprint to update the documentation :-) – ErikH - CiviCooP Jun 26 at 8:31
  • I know for good, documentation is hard work, don't get me wrong :) – Daniel W. Jun 26 at 8:35
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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