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":[
,
]
}
}]
}
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":[
]
},
{
"is_error":0,
"version":3,
"count":1,
"id":62,
"values":[
]
}]
}
}
}
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":[
,
]
}
}]
}