Answers.Body: <p>At the point hook_post is called the timeline (activities) hasn't been created and the association with the client (CaseContact object) hasn't either.</p>
  
  <p>See <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/Case.php" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/Case.php</a> and <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/Activity/OpenCase.php" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/Activity/OpenCase.php</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-25T17:54:27.790Z
Answers.Text: do you know if there is an API call that will do this or do I need to do an SQL query directly on the database? Thanks!
Answers.UserDisplayName: Josh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-26T01:29:50.240Z
Answers.Text: Neither api nor sql will get you anything at that point since it isn't in the database yet. You could store the case id somewhere and do hook post on CaseContact when that arrives and compare its case id. But what is your end goal? Maybe a cron hook is better?
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-26T01:37:35.817Z
Answers.Text: Or try the postProcess hook instead on the case form object.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-26T06:36:07.050Z
Answers.Text: That is the reason I asked if it was at exactly the same point in the process :-) The Case transaction is completed right at the end and before that most stuff is not in the database yet! Cost me quite a bit of headache in the past.....:-)
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-26T19:26:01.710Z
Answers.Text: @Demerit  When I look at the documentation I am not sure what hook that is. Which hook are you talking about? Thanks!
Answers.UserDisplayName: Josh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-27T02:48:39.327Z
Answers.Text: https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postProcess/
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-27T18:22:27.930Z
Answers.Text: Because the data is coming from Webform I do not see how to make this work. My plan right now is to use the Drupal queue.
Answers.UserDisplayName: Josh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-25T15:09:54.203Z
Answers.LastActivityDate: 2017-07-25T15:09:54.203Z
Answers.UserDisplayName: Demerit
Answers.Body: <p>So that is it clear for others in the future ErikH has the answer above in the comments.  </p>
  
  <p>That is the reason I asked if it was at exactly the same point in the process :-) The Case transaction is completed right at the end and before that most stuff is not in the database yet! Cost me quite a bit of headache in the past.....:-) – ErikH - CiviCooP Jul 26 at 6:36</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-31T03:42:17.000Z
Answers.LastActivityDate: 2017-07-31T03:42:17.000Z
Answers.UserDisplayName: Josh
Body: <p>I am trying to get data out of the API and when I look at it in API explorer I find what I am looking for but the data is incomplete in my module.  </p>
  
  <p>For example, I am using civicrm_post($op, $objectName, $objectId, &amp;$objectRef) and I know this is working because I have if ($objectName != "Case" || $op != "create") and my code in the if is firing.  </p>
  
  <pre><code>    civicrm_initialize();
  $result = civicrm_api3('Case', 'get', array(
            'sequential' =&gt; 1,
            'id' =&gt; $objectId,
            ));
  </code></pre>
  
  <p>Here is the result from the API call in my module:</p>
  
  <pre><code>Array
  </code></pre>
  
  <p>(
      [is_error] => 0
      [version] => 3
      [count] => 1
      [id] => 352
      [values] => Array
          (
              [0] => Array
                  (
                      [id] => 352
                      [case_type_id] => 5
                      [subject] => Test Case Subject
                      [start_date] => 2017-07-24
                      [status_id] => 4
                      [is_deleted] => 0
                      [contact_id] => Array
                          (
                          )</p>
  
  <pre><code>                [client_id] =&gt; Array
                      (
                      )
  
                  [contacts] =&gt; Array
                      (
                      )
  
                  [activities] =&gt; Array
                      (
                      )
  
              )
  
      )
  </code></pre>
  
  <p>)</p>
  
  <p>Here is the result from the API Explorer:</p>
  
  <pre><code>{
  
  "is_error": 0,
  "version": 3,
  "count": 1,
  "id": 352,
  "values": [
      {
          "id": "352",
          "case_type_id": "5",
          "subject": "Test Case Subject",
          "start_date": "2017-07-24",
          "status_id": "4",
          "is_deleted": "0",
          "custom_70": "IL",
          "custom_72": "Peoria County",
          "custom_76": "1",
          "custom_78": "2",
          "custom_92": "Farmers",
          "custom_100": "1500943386-26151211",
          "custom_95": "Test",
          "custom_96": [
              "1"
          ],
          "custom_97": [
              "1"
          ],
          "custom_98": [
              "1"
          ],
          "custom_99": [
              "1"
          ],
          "contact_id": {
              "1": "9025"
          },
          "client_id": {
              "1": "9025"
          },
          "contacts": [
              {
                  "contact_id": "9025",
                  "sort_name": "Applications , Test",
                  "display_name": "Test Applications",
                  "email": "test@aplications.com",
                  "phone": "",
                  "birth_date": "1919-04-04",
                  "role": "Client"
              }
          ],
          "activities": [
              "21781",
              "21782"
          ]
      }
  ]
  </code></pre>
  
  <p>}</p>
  
  <p>Any help is appreciated.  </p>
  
  <p>Thanks,
  Josh </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-25T01:29:46.743Z
Comments.Text: Can you please say more about which data is showing up in the api explorer that's not showing up in `$result` when your code runs? (maybe edit your question to include the two different results?)
Comments.UserDisplayName: Noah Miller
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-25T12:03:55.757Z
Comments.Text: At exactly the same point in the process?
Comments.UserDisplayName: ErikH - CiviCooP
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-25T17:50:29.167Z
Comments.Text: @NoahMiller I have added the results.  I was trying not to make the post so long.
Comments.UserDisplayName: Josh
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-25T17:52:38.813Z
Comments.Text: @ErikH-CiviCooP I added sleep (30) to try and get it as close as possible and I still get the same results.
Comments.UserDisplayName: Josh
Tags: <api><civicase>
Title: Different Result in Code Than API Explorer
ThreadText: # Different Result in Code Than API Explorer
  
  (Asked by: username_0 on 2017-07-25)
  
  I am trying to get data out of the API and when I look at it in API explorer I find what I am looking for but the data is incomplete in my module.  
  For example, I am using civicrm_post($op, $objectName, $objectId, &$objectRef) and I know this is working because I have if ($objectName != "Case" || $op != "create") and my code in the if is firing.  
      civicrm_initialize();
  $result = civicrm_api3('Case', 'get', array(
            'sequential' => 1,
            'id' => $objectId,
            ));
  
  Here is the result from the API call in my module:
  Array
  
  (
      [is_error] => 0
      [version] => 3
      [count] => 1
      [id] => 352
      [values] => Array
          (
              [0] => Array
                  (
                      [id] => 352
                      [case_type_id] => 5
                      [subject] => Test Case Subject
                      [start_date] => 2017-07-24
                      [status_id] => 4
                      [is_deleted] => 0
                      [contact_id] => Array
                          (
                          )
                  [client_id] => Array
                      (
                      )
  
                  [contacts] => Array
                      (
                      )
  
                  [activities] => Array
                      (
                      )
  
              )
  
      )
  
  )
  Here is the result from the API Explorer:
  {
  
  "is_error": 0,
  "version": 3,
  "count": 1,
  "id": 352,
  "values": [
      {
          "id": "352",
          "case_type_id": "5",
          "subject": "Test Case Subject",
          "start_date": "2017-07-24",
          "status_id": "4",
          "is_deleted": "0",
          "custom_70": "IL",
          "custom_72": "Peoria County",
          "custom_76": "1",
          "custom_78": "2",
          "custom_92": "Farmers",
          "custom_100": "1500943386-26151211",
          "custom_95": "Test",
          "custom_96": [
              "1"
          ],
          "custom_97": [
              "1"
          ],
          "custom_98": [
              "1"
          ],
          "custom_99": [
              "1"
          ],
          "contact_id": {
              "1": "9025"
          },
          "client_id": {
              "1": "9025"
          },
          "contacts": [
              {
                  "contact_id": "9025",
                  "sort_name": "Applications , Test",
                  "display_name": "Test Applications",
                  "email": "test@aplications.com",
                  "phone": "",
                  "birth_date": "1919-04-04",
                  "role": "Client"
              }
          ],
          "activities": [
              "21781",
              "21782"
          ]
      }
  ]
  
  }
  Any help is appreciated.  
  Thanks,
  username_0
  
  **Tags:** api, civicase
  
  > **Comments:**
  > **username_1**: Can you please say more about which data is showing up in the api explorer that's not showing up in `$result` when your code runs? (maybe edit your question to include the two different results?)  
  > **username_2**: At exactly the same point in the process?  
  > **username_0**: @NoahMiller I have added the results.  I was trying not to make the post so long.  
  > **username_0**: @ErikH-CiviCooP I added sleep (30) to try and get it as close as possible and I still get the same results.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2017-07-25. Score: 2
  
  At the point hook\_post is called the timeline (activities) hasn't been created and the association with the client (CaseContact object) hasn't either.
  
  See <https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/Case.php> and <https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/Activity/OpenCase.php>
  
  > **Comments:**
  > **username_0**: do you know if there is an API call that will do this or do I need to do an SQL query directly on the database? Thanks!  
  > **username_3**: Neither api nor sql will get you anything at that point since it isn't in the database yet. You could store the case id somewhere and do hook post on CaseContact when that arrives and compare its case id. But what is your end goal? Maybe a cron hook is better?  
  > **username_3**: Or try the postProcess hook instead on the case form object.  
  > **username_2**: That is the reason I asked if it was at exactly the same point in the process :-) The Case transaction is completed right at the end and before that most stuff is not in the database yet! Cost me quite a bit of headache in the past.....:-)  
  > **username_0**: @username_3  When I look at the documentation I am not sure what hook that is. Which hook are you talking about? Thanks!  
  > **username_3**: https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postProcess/  
  > **username_0**: Because the data is coming from Webform I do not see how to make this work. My plan right now is to use the Drupal queue.  
  
  ---
  
  ### Answer by username_0 on 2017-07-31. Score: 1
  
  So that is it clear for others in the future ErikH has the answer above in the comments.
  
  That is the reason I asked if it was at exactly the same point in the process :-) The Case transaction is completed right at the end and before that most stuff is not in the database yet! Cost me quite a bit of headache in the past.....:-) – username_2 Jul 26 at 6:36
  
  
  ---
  
  