Answers.Body: <p>So, for posterity's sake, I wanted to share the answer I figured out.</p>
  
  <p>When I looked at the Source view of the email in CiviCRM, I realized that the code had pasted as</p>
  
  <pre><code>
  &lt;p&gt;id:&amp;nbsp;{contact.contact_id}&lt;/p&gt;
  
  &lt;p&gt;smarty id: {$contact_id}&lt;/p&gt;
  
  &lt;p&gt;{crmAPI var=&amp;#39;result&amp;#39; entity=&amp;#39;Contact&amp;#39; action=&amp;#39;get&amp;#39; id=203}&lt;/p&gt;
  
  &lt;p&gt;{$result|@debug_print_var}&lt;/p&gt;
  
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>{capture assign=contact_id}{contact.contact_id}{/capture}
  
  id: {contact.contact_id}
  
  smarty id: {$contact_id}
  
  {crmAPI var='result' entity='Contact' action='get' id=203}
  
  {$result|@debug_print_var}
  </code></pre>
  
  <p>When I composed the code correctly in the Source view rather than the HTML view, everything worked as expected!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-23T21:15:36.917Z
Answers.LastActivityDate: 2019-09-23T21:15:36.917Z
Answers.UserDisplayName: pyfi
Body: <p>Using the Explorer, I built up the smarty code I need for a template to pull in address information on a contact for use in an email:</p>
  
  <pre><code>{crmAPI var='result' entity='Address' action='get' contact_id=203}
  {foreach from=$result.values item=address}
    {$address.some_field}
  {/foreach}
  </code></pre>
  
  <p>and it produces the desired output in the Explorer when executed.</p>
  
  <p>In an email though, the expected output never renders, and when I add the smarty expression <code>{result|@debug_print_var}</code>, I get <code>null</code> for the value of the variable in the message.</p>
  
  <p>The fact that I'm getting <code>null</code> suggests to me that smarty is in fact running, but I can't for the life of me figure out why it can't seem to make an API call. Thoughts?</p>
  
  <p>Thanks for the help!</p>
  
  <p>N.B.: I'm running CiviCRM 5.17.4 on Drupal 7.67 and Ubuntu 16.04.</p>
  
  <p><strong>Update</strong></p>
  
  <p>With the following email code:</p>
  
  <pre><code>{capture assign=contact_id}{contact.contact_id}{/capture}
  
  id: {contact.contact_id}
  
  smarty id: {$contact_id}
  
  {crmAPI var='result' entity='Contact' action='get' id=203}
  
  {$result|@debug_print_var}
  </code></pre>
  
  <p>This is the email that renders when sending to contact # 203:</p>
  
  <pre><code>id: 203
  
  smarty id: 203
  
  null
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-23T10:36:41.970Z
Comments.Text: The above code looks like it is pasted from the API explorer. Can you also paste the code that you've entered in the message template? is the contact id hardcoded in it too?
Comments.UserDisplayName: jitendra - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-23T11:58:53.240Z
Comments.Text: I used exactly the same code in the message to reduce the risk that I had messed something up. The contact id is hardcoded in this test (though it will eventually be dynamic).
Comments.UserDisplayName: pyfi
Tags: <civimail><api><smarty>
Title: Smarty only generating nulls from API calls
ThreadText: # Smarty only generating nulls from API calls
  
  (Asked by: username_0 on 2019-09-23)
  
  Using the Explorer, I built up the smarty code I need for a template to pull in address information on a contact for use in an email:
  
  ```
  {crmAPI var='result' entity='Address' action='get' contact_id=203}
  {foreach from=$result.values item=address}
    {$address.some_field}
  {/foreach}
  
  ```
  
  and it produces the desired output in the Explorer when executed.
  
  In an email though, the expected output never renders, and when I add the smarty expression `{result|@debug_print_var}`, I get `null` for the value of the variable in the message.
  
  The fact that I'm getting `null` suggests to me that smarty is in fact running, but I can't for the life of me figure out why it can't seem to make an API call. Thoughts?
  
  Thanks for the help!
  
  N.B.: I'm running CiviCRM 5.17.4 on Drupal 7.67 and Ubuntu 16.04.
  
  **Update**
  
  With the following email code:
  
  ```
  {capture assign=contact_id}{contact.contact_id}{/capture}
  
  id: {contact.contact_id}
  
  smarty id: {$contact_id}
  
  {crmAPI var='result' entity='Contact' action='get' id=203}
  
  {$result|@debug_print_var}
  
  ```
  
  This is the email that renders when sending to contact # 203:
  
  ```
  id: 203
  
  smarty id: 203
  
  null
  
  ```
  
  **Tags:** civimail, api, smarty
  
  > **Comments:**
  > **username_1**: The above code looks like it is pasted from the API explorer. Can you also paste the code that you've entered in the message template? is the contact id hardcoded in it too?  
  > **username_0**: I used exactly the same code in the message to reduce the risk that I had messed something up. The contact id is hardcoded in this test (though it will eventually be dynamic).  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-09-23. Score: 4 | Accepted answer
  
  So, for posterity's sake, I wanted to share the answer I figured out.
  
  When I looked at the Source view of the email in CiviCRM, I realized that the code had pasted as
  
  ```
  
  <p>id:&nbsp;{contact.contact_id}</p>
  
  <p>smarty id: {$contact_id}</p>
  
  <p>{crmAPI var=&#39;result&#39; entity=&#39;Contact&#39; action=&#39;get&#39; id=203}</p>
  
  <p>{$result|@debug_print_var}</p>
  
  ```
  
  instead of
  
  ```
  {capture assign=contact_id}{contact.contact_id}{/capture}
  
  id: {contact.contact_id}
  
  smarty id: {$contact_id}
  
  {crmAPI var='result' entity='Contact' action='get' id=203}
  
  {$result|@debug_print_var}
  
  ```
  
  When I composed the code correctly in the Source view rather than the HTML view, everything worked as expected!
  
  
  ---
  
  