Answers.Body: <p>From api explorer the results are retrieved using rest api where check_permissions is always set to TRUE by default even though its been explicitly set via api params.</p>
  <p>If you have check_permissions set to TRUE than api returns only those fields which are defined for the the entity. In your case the fields would be</p>
  <pre><code>civicrm_api('Contribution', 'getfields', ['version' =&gt; 3, 'action' =&gt; 'get']);
  </code></pre>
  <p>Try adding <code>'check_permissions' =&gt; TRUE</code> as a api parameter in your php code, it should return exact same results you get in api explorer.</p>
  <p>HTH</p>
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-28T10:28:44.577Z
Answers.Text: This worked (once). But when I removed the `check_permissions` param again (or set it to FALSE) I couldn't get back the old value with my PHP script. Instead, an empty string or NULL appears in the `payment_processor_id` attribute of API result now.
Answers.UserDisplayName: emma
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-27T14:19:10.753Z
Answers.LastActivityDate: 2021-09-27T14:19:10.753Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I created a PHP 7 script that uses an API Call to get some information about a specific Contribution with a <code>$contributionID</code> that has been defined before.
  The code (below) works and correctly returns <code>payment_processor_id</code>. BUT I cannot reproduce this in CiviCRM API Explorer v3.</p>
  <p>My code is:</p>
  <pre><code>
   $result2 = civicrm_api3('Contribution', 'get', [
              'sequential' =&gt; &quot;1&quot;,
              'return' =&gt; [&quot;payment_processor&quot;,&quot;instrument_id&quot;,&quot;payment_instrument_id&quot;,&quot;payment_processor_id&quot;],
              'id' =&gt; $contributionID,
          ]);
          $payment_instrument_id = $result2[&quot;values&quot;][&quot;0&quot;][&quot;payment_instrument_id&quot;];
          $payment_processor_id = $result2[&quot;values&quot;][&quot;0&quot;][&quot;payment_processor_id&quot;];
          echo &quot;instrument ID: &quot;;
          var_dump($payment_instrument_id);
          echo &quot;processor ID: &quot;;
          var_dump($payment_processor_id);
  </code></pre>
  <p>where the resulting array does correctly contain a value for <code>payment_instrument_id</code>.
  When I try to reproduce this in API Explorer v3, I get an array response with the following structure:</p>
  <pre><code>    {
      &quot;is_error&quot;: 0,
      &quot;version&quot;: 3,
      &quot;count&quot;: 1,
      &quot;id&quot;: 885,
      &quot;values&quot;: [
          {
              &quot;contact_id&quot;: &quot;2700&quot;,
              &quot;contribution_id&quot;: &quot;885&quot;,
              &quot;payment_instrument_id&quot;: &quot;8&quot;,
              &quot;payment_instrument&quot;: &quot;Lastschrift&quot;,
              &quot;instrument_id&quot;: &quot;8&quot;,
              &quot;id&quot;: &quot;885&quot;
          }
      ]
  }
  </code></pre>
  <p>Obviously, there is no <code>payment_processor_id</code> here. So it is a big puzzle for me how the PHP API call can access an attribute that is not even there.</p>
  <p>I entered the following values in API Explorer:
  <a href="https://i.sstatic.net/LIxfs.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LIxfs.png" alt="Api explorer screenshot" /></a></p>
  <p>You can see that the PHP code the API Explorer produces is exactly the same as I am using in the script.
  Does anybody have any idea why this difference occurs?</p>
  <p>EDIT: If @Pradeep's answer is correct, wouldn't it be logical to add this <code>'check_permissions' =&gt; TRUE</code> parameter in the PHP section of API Explorer? From my perspective, the code snippets in API Explorer should represent as exactly as possible the code that is <em>actually</em> executed.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-27T12:55:45.603Z
Comments.Text: The API explorer only returns the fields that has a non empty value in it. Eg if trxn_id for the contribution is empty, it will not return this value in the API explorer.
Comments.UserDisplayName: jitendra - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-27T13:30:30.247Z
Comments.Text: @jitendra The value is not empty, as the PHP API Call returns a value for the exact same Contribution ID.
Comments.UserDisplayName: emma
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-27T13:55:04.123Z
Comments.Text: Are checking the results for same contribution ID?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-27T14:00:48.810Z
Comments.Text: Yes, I am checking for the exact same Contribution ID.
Comments.UserDisplayName: emma
Tags: <api><php7>
Title: Missing attribute payment_processor_id of entity Contribution in API Explorer v3?
ThreadText: # Missing attribute payment_processor_id of entity Contribution in API Explorer v3?
  
  (Asked by: username_0 on 2021-09-27)
  
  I created a PHP 7 script that uses an API Call to get some information about a specific Contribution with a $contributionID that has been defined before.
  The code (below) works and correctly returns payment_processor_id. BUT I cannot reproduce this in CiviCRM API Explorer v3.
  My code is:
  
   $result2 = civicrm_api3('Contribution', 'get', [
              'sequential' => "1",
              'return' => ["payment_processor","instrument_id","payment_instrument_id","payment_processor_id"],
              'id' => $contributionID,
          ]);
          $payment_instrument_id = $result2["values"]["0"]["payment_instrument_id"];
          $payment_processor_id = $result2["values"]["0"]["payment_processor_id"];
          echo "instrument ID: ";
          var_dump($payment_instrument_id);
          echo "processor ID: ";
          var_dump($payment_processor_id);
  
  where the resulting array does correctly contain a value for payment_instrument_id.
  When I try to reproduce this in API Explorer v3, I get an array response with the following structure:
      {
      "is_error": 0,
      "version": 3,
      "count": 1,
      "id": 885,
      "values": [
          {
              "contact_id": "2700",
              "contribution_id": "885",
              "payment_instrument_id": "8",
              "payment_instrument": "Lastschrift",
              "instrument_id": "8",
              "id": "885"
          }
      ]
  }
  
  Obviously, there is no payment_processor_id here. So it is a big puzzle for me how the PHP API call can access an attribute that is not even there.
  I entered the following values in API Explorer:
  
  You can see that the PHP code the API Explorer produces is exactly the same as I am using in the script.
  Does anybody have any idea why this difference occurs?
  EDIT: If @Pradeep's answer is correct, wouldn't it be logical to add this 'check_permissions' => TRUE parameter in the PHP section of API Explorer? From my perspective, the code snippets in API Explorer should represent as exactly as possible the code that is actually executed.
  
  **Tags:** api, php7
  
  > **Comments:**
  > **username_1**: The API explorer only returns the fields that has a non empty value in it. Eg if trxn_id for the contribution is empty, it will not return this value in the API explorer.  
  > **username_0**: @jitendra The value is not empty, as the PHP API Call returns a value for the exact same Contribution ID.  
  > **username_2**: Are checking the results for same contribution ID?  
  > **username_0**: Yes, I am checking for the exact same Contribution ID.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-09-27. Score: 2
  
  From api explorer the results are retrieved using rest api where check_permissions is always set to TRUE by default even though its been explicitly set via api params.
  If you have check_permissions set to TRUE than api returns only those fields which are defined for the the entity. In your case the fields would be
  civicrm_api('Contribution', 'getfields', ['version' => 3, 'action' => 'get']);
  
  Try adding 'check_permissions' => TRUE as a api parameter in your php code, it should return exact same results you get in api explorer.
  HTH
  Pradeep
  
  > **Comments:**
  > **username_0**: This worked (once). But when I removed the `check_permissions` param again (or set it to FALSE) I couldn't get back the old value with my PHP script. Instead, an empty string or NULL appears in the `payment_processor_id` attribute of API result now.  
  
  ---
  
  