I had a working script set up to create cases in CiviCRM using REST.
(obviously with the correct payload etc). This worked fine. It returned the specified return:id etc in a nice small JSON. Now, the same script is failing because it can't parse the returned JSON. It seems that the API is now returning a Civi\CCase\Analyzer Object which contains the full case data as XML and as JSON. Is this change intentional? Is it documented anywhere? I'm wondering how to extract the JSON from the returned Analyzer object. Thanks.

  • I'm not seeing any xml when I run it (on a drupal site). Is there something interesting about the way you run it? I tested with: curl -X POST 'http://site/civicrm/extern/rest.php?json=1' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'entity=Case&action=create&api_key=12345&key=12345&contact_id=user_contact_id&case_type_id=1&subject=fromExternRest'
    – Demerit
    Apr 12, 2019 at 17:36
  • Thanks. I tried the same thing as you, using curl, but the response I'm getting is a full dump of the newly-created Case in XML, including all associated activities and relationships, and then the JSON at the end of the output. I'm using Joomla, but I can't imagine that would make a difference? The script has been working fine for months, and I haven't done anything to it.
    – Jern
    Apr 12, 2019 at 19:32
  • The output starts like this, and goes on for a couple of thousand lines: Civi\CCase\Analyzer Object ( [caseId:Civi\CCase\Analyzer:private] => 775 [case:Civi\CCase\Analyzer:private] => Array ( [id] => 775 [case_type_id] => 9 [subject] => fromExternRest [start_date] => 2019-04-12 [status_id] => 1 [is_deleted] => 0 [created_date] => 2019-04-12 21:16:32 [modified_date] => 2019-04-12 21:16:32 [contact_id] => Array ( [1] => 66
    – Jern
    Apr 12, 2019 at 19:36
  • Can you do a grep for var_dump or print_r? I'm thinking some debugging code was added in and is producing that output.
    – Demerit
    Apr 12, 2019 at 19:47
  • OK, I couldn't see anything which looks suspect. But maybe you can spot something. The grep output is here - pastebin.com/nRCKcCky and here: pastebin.com/Hu82Atgi
    – Jern
    Apr 12, 2019 at 23:19

1 Answer 1


Not a direct answer, but following on from the comments here are some more things you can try.

  1. If you haven't already, check the civicrm log. Maybe there is something helpful there. For example maybe there is a recoverable error happening but it dumps some output to stdout instead of the log, which during a REST call will be part of the response output.

  2. It's possible you have some code or an extension that implements the civicrm_caseChange hook and then does some debug output. When looking or grepping be sure to look in any custom php and extension folders defined at admin -> system settings -> directories.

  3. Use diff -r or kdiff or something to compare your civicrm tree to a fresh unzipped 5.12 download to see if there's any differences.

  4. It's definitely print_r output, but it might be coming indirectly from something that calls 'CRM_Core_Error::debug(' or 'CRM_Core_Error::debug_var(', so can try grepping for that. Note I've included the opening bracket in the search string since I'm thinking that will give the least false matches.

  5. Try disabling some extensions one by one.

  6. Run a php step-debugger to see exactly what step it gets output and where it's coming from. This will be time consuming, but you will almost certainly find it. If you can reproduce the problem on a local development copy of the site it will be slightly easier to set this up using that copy.

  • Genius, thank you. The problem was caused by an extension which included a function implementing the caseChange hook (the function is very short, and just sends an email whenever a case is changed). I've pasted it here: pastebin.com/qH94m7EX. I'm not sure why it's outputting the contents of $analyzer, or how this gets into the response of the api create function. Anyway, we don't need it, so I have just commented it out, and the api response is now just the expected json. Thanks very much for your help.
    – Jern
    Apr 13, 2019 at 17:14
  • Great. By the way in that function if you just change print_r($analyzer); to print_r($analyzer, true); it will work as it seems like it was intended. Without the "true" it sends the output to stdout instead of returning a string, which is why you see it in the REST output.
    – Demerit
    Apr 13, 2019 at 17:59
  • Another casualty of when debugging actually causes bugs.
    – Coleman
    Apr 13, 2019 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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