Answers.Body: <p>This looks like a 2-parter so I'll just answer your first question about how to fetch all emails &amp; phones for a contact. Please start a new post for your curl question.</p>
  <p>APIv4 <em>does</em> fetch all fields (aka <code>SELECT *</code>) by default, but only fields that actually belong to the entity. If you inspect the <code>civicrm_contact</code> table in SQL you'll see that <code>email</code> is not actually a column. Rather it's a join to another table.</p>
  <p>APIv4 can do a lot of fancy stuff with joins, but you have to ask it to (if it did <em>all</em> the fancy stuff by default it would probably blow up your server or at least significantly slow it down).</p>
  <p>It's all a bit too much to explain in one StackExchange answer, so I recommend you go and check out the docs on:</p>
  <ol>
  <li><a href="https://docs.civicrm.org/dev/en/latest/api/v4/implicit-joins/" rel="nofollow noreferrer">Implicit Joins</a></li>
  <li><a href="https://docs.civicrm.org/dev/en/latest/api/v4/explicit-joins/" rel="nofollow noreferrer">Explicit Joins</a></li>
  </ol>
  <p>And in addition to the API Explorer, try playing with SearchKit. It's a bit more user-friendly and can generate the types of aggregate joins you wanted (e.g. fetching multiple emails per contact) with just a few clicks. Then click on the &quot;Query Info&quot; tab and SearchKit will show you the APIv4 params it has generated to do all the fancy stuff you asked for.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-26T00:20:03.633Z
Answers.LastActivityDate: 2023-10-26T00:20:03.633Z
Answers.UserDisplayName: Coleman
Body: <p>I played around with the ApiExplorer for API4
  While the doc says default select would be * it doesn't return all contact details.
  So I added the SELECT for phone_primary and email_primary and joined the phoneDB.
  This worked for one phonenumber, but all the other phonenumber which can be set for a
  contact (e.g. fax,mobile) don't show up.</p>
  <p>Anyway, I tried to use the curl example from the ApiExplorer and it worked so far it returns all contacts and a lot senseless details.
  However, limit the request is not working at all. It always returns all contacts.
  Also phone and email are always missing no matter what I do.</p>
  <p>My Postman request looks like this:</p>
  <blockquote>
  <p><a href="https://demo.circle-interactive.co.uk/civicrm/ajax/api4/Contact/get?select=" rel="nofollow noreferrer">https://demo.circle-interactive.co.uk/civicrm/ajax/api4/Contact/get?select=</a>
  [&quot;email_primary.<em>&quot;, &quot;phone.</em>&quot;, &quot;first_name&quot;, &quot;last_name&quot;,
  &quot;phone.mobile_provider_id&quot;, &quot;organization_name&quot;]&amp;join= [[&quot;Phone AS
  phone&quot;, &quot;LEFT&quot;]]&amp;limit=5</p>
  <p>This are my params in Postman: {&quot;select&quot;: [&quot;email_primary.<em>&quot;,
  &quot;phone.</em>&quot;, &quot;first_name&quot;, &quot;last_name&quot;, &quot;phone.mobile_provider_id&quot;,
  &quot;organization_name&quot;],   &quot;join&quot;: [[&quot;Phone AS phone&quot;, &quot;LEFT&quot;]],<br />
  &quot;limit&quot;: 5}</p>
  </blockquote>
  <p>This is what API-Explorer shows as valid curl example. But it's not working as curl or Postman request.
  As mentioned a lot senseless contact details are returned but phone and email are always missing in the result.</p>
  <blockquote>
  <p>CRM_URL='https://demo.circle-interactive.co.uk/civicrm/ajax/api4/Contact/get' CRM_AUTH='X-Civi-Auth: Bearer MY_API_KEY'</p>
  <p>curl -X POST -H &quot;$CRM_AUTH&quot; &quot;$CRM_URL&quot; <br />
  -d 'params=%7B%22select%22%3A%5B%22email_primary.%2a%22%2C%22phone.%2a%22%2C%22first_name%22%2C%22last_name%22%2C%22phone.mobile_provider_id%22%2C%22organization_name%22%5D%2C%22join%22%3A%5B%5B%22Phone%20AS%20phone%22%2C%22LEFT%22%5D%5D%2C%22limit%22%3A5%7D'</p>
  </blockquote>
  <p>While emails and phonenumber are returned in the ApiExplorer for API3 with a similar request, the curl example for API3 is not working at all. (Invalid url)</p>
  <p>I don't get it where the problem is.
  Are this ApiExplorer examples still up to date?
  Any suggestions?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-10-25T18:45:15.317Z
Comments.Text: It sounds like there are 2 parts to your question. StackExchange is set up to answer one question at a time, so it might have been better to ask one question about how to fetch all contact Emails and another about how to properly encode curl requests.
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-10-25T20:33:37.637Z
Comments.Text: Well, actually I just added all details I gathered while trying to make it work.
  Yes, the problem is just to get email and phone numbers when fetching a contacts 
  I don't know If it's a problem of curl format, wrong examples or an api4 bug. Maybe the api3 api4 inconsistence behavior is another way to narrow down the problem?!?
Comments.UserDisplayName: Gesko
Tags: <contacts><email><apiv4><phone><missing>
Title: Get Phone or Email with API4 not possible?
ThreadText: # Get Phone or Email with API4 not possible?
  
  (Asked by: username_0 on 2023-10-25)
  
  I played around with the ApiExplorer for API4
  While the doc says default select would be \* it doesn't return all contact details.
  So I added the SELECT for phone\_primary and email\_primary and joined the phoneDB.
  This worked for one phonenumber, but all the other phonenumber which can be set for a
  contact (e.g. fax,mobile) don't show up.
  
  Anyway, I tried to use the curl example from the ApiExplorer and it worked so far it returns all contacts and a lot senseless details.
  However, limit the request is not working at all. It always returns all contacts.
  Also phone and email are always missing no matter what I do.
  
  My Postman request looks like this:
  
  > <https://demo.circle-interactive.co.uk/civicrm/ajax/api4/Contact/get?select=>
  > ["email\_primary.*", "phone.*", "first\_name", "last\_name",
  > "phone.mobile\_provider\_id", "organization\_name"]&join= [["Phone AS
  > phone", "LEFT"]]&limit=5
  >
  > This are my params in Postman: {"select": ["email\_primary.*",
  > "phone.*", "first\_name", "last\_name", "phone.mobile\_provider\_id",
  > "organization\_name"], "join": [["Phone AS phone", "LEFT"]],  
  > "limit": 5}
  
  This is what API-Explorer shows as valid curl example. But it's not working as curl or Postman request.
  As mentioned a lot senseless contact details are returned but phone and email are always missing in the result.
  
  > CRM\_URL='https://demo.circle-interactive.co.uk/civicrm/ajax/api4/Contact/get' CRM\_AUTH='X-Civi-Auth: Bearer MY\_API\_KEY'
  >
  > curl -X POST -H "$CRM\_AUTH" "$CRM\_URL"   
  > -d 'params=%7B%22select%22%3A%5B%22email\_primary.%2a%22%2C%22phone.%2a%22%2C%22first\_name%22%2C%22last\_name%22%2C%22phone.mobile\_provider\_id%22%2C%22organization\_name%22%5D%2C%22join%22%3A%5B%5B%22Phone%20AS%20phone%22%2C%22LEFT%22%5D%5D%2C%22limit%22%3A5%7D'
  
  While emails and phonenumber are returned in the ApiExplorer for API3 with a similar request, the curl example for API3 is not working at all. (Invalid url)
  
  I don't get it where the problem is.
  Are this ApiExplorer examples still up to date?
  Any suggestions?
  
  **Tags:** contacts, email, apiv4, phone, missing
  
  > **Comments:**
  > **username_1**: It sounds like there are 2 parts to your question. StackExchange is set up to answer one question at a time, so it might have been better to ask one question about how to fetch all contact Emails and another about how to properly encode curl requests.  
  > **username_0**: Well, actually I just added all details I gathered while trying to make it work. Yes, the problem is just to get email and phone numbers when fetching a contacts  I don't know If it's a problem of curl format, wrong examples or an api4 bug. Maybe the api3 api4 inconsistence behavior is another way to narrow down the problem?!?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-10-26. Score: 2
  
  This looks like a 2-parter so I'll just answer your first question about how to fetch all emails & phones for a contact. Please start a new post for your curl question.
  
  APIv4 *does* fetch all fields (aka `SELECT *`) by default, but only fields that actually belong to the entity. If you inspect the `civicrm_contact` table in SQL you'll see that `email` is not actually a column. Rather it's a join to another table.
  
  APIv4 can do a lot of fancy stuff with joins, but you have to ask it to (if it did *all* the fancy stuff by default it would probably blow up your server or at least significantly slow it down).
  
  It's all a bit too much to explain in one StackExchange answer, so I recommend you go and check out the docs on:
  
  1. [Implicit Joins](https://docs.civicrm.org/dev/en/latest/api/v4/implicit-joins/)
  2. [Explicit Joins](https://docs.civicrm.org/dev/en/latest/api/v4/explicit-joins/)
  
  And in addition to the API Explorer, try playing with SearchKit. It's a bit more user-friendly and can generate the types of aggregate joins you wanted (e.g. fetching multiple emails per contact) with just a few clicks. Then click on the "Query Info" tab and SearchKit will show you the APIv4 params it has generated to do all the fancy stuff you asked for.
  
  
  ---
  
  