Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-15891

Inconsistency in returned json for chained get and chained create

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.5.5, 4.6
    • Fix Version/s: 4.6.7
    • Component/s: CiviCRM API
    • Labels:
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code

      Description

      I noticed something strange about the JSON that API calls return.

      Suppose I want to get a contact and its websites, using chaining. This is the request I use:

      /dev1/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&json={"sequential":1,"id":9076,"api.Website.get":{}}&api_key=yoursitekey&key=yourkey

      Here is the result:

      {
      "is_error":0,
      "version":3,
      "count":1,
      "id":9076,
      "values":[{
      "contact_id":"9076",
      "contact_type":"Individual",
      // ...
      "api.Website.get":{
      "is_error":0,
      "version":3,
      "count":2,
      "values":[

      { "id":"59", "contact_id":"9076", "url":"http:\/\/example.com" }

      ,

      { "id":"60", "contact_id":"9076", "url":"http:\/\/example.org" }

      ]
      }
      }]
      }

      Now if I create a new contact, and I provide websites using a chained create action like this:

      /dev1/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=create&sequential=1&json={"last_name":"Smith","contact_type":"Individual","api.Website.create":[

      {"url":"http://smith.org"}

      ,

      {"url":"http://smath.org"}

      ]}&api_key=yoursitekey&key=yourkey

      This is the result I get:

      {
      "is_error":0,
      "version":3,
      "count":1,
      "id":9077,
      "values":{
      "0":{
      "id":"9077",
      "contact_type":"Individual",
      // ...
      "9077":{
      "api.Website.create":[{
      "is_error":0,
      "version":3,
      "count":1,
      "id":61,
      "values":[

      { "id":"61", "contact_id":"9077", "url":"http:\/\/smith.org", "website_type_id":"" }

      ]
      },
      {
      "is_error":0,
      "version":3,
      "count":1,
      "id":62,
      "values":[

      { "id":"62", "contact_id":"9077", "url":"http:\/\/smath.org", "website_type_id":"" }

      ]
      }]
      }
      }
      }

      So there are some extra indices ("0") and Id's ("9077"), which makes the parsing of the json harder (for me at least ). It appears to me that 'sequential=1' is ignored.

      I think the correct result would be:

      {
      "is_error":0,
      "version":3,
      "count":1,
      "id":9077,
      "values":[{
      "id":"9077",
      "contact_type":"Individual",
      // ...
      "api.Website.create":{
      "is_error":0,
      "version":3,
      "count":2,
      "id":61,
      "values":[

      { "id":"61", "contact_id":"9077", "url":"http:\/\/smith.org", "website_type_id":"" }

      ,

      { "id":"62", "contact_id":"9077", "url":"http:\/\/smath.org", "website_type_id":"" }

      ]
      }
      }]
      }

        Attachments

          Activity

            People

            • Assignee:
              eileen Eileen McNaughton
              Reporter:
              johanv Johan Vervloet
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: