Body: <p>Using API 4 (php), how do I retreive a custom field value for a specific contact, using the custom field id instead of the custom field name.</p>
  <p>This works (for contact with id=1234), but requires the use of the custom field name (Extra_Info.My_Custom_Field_Name), but I want to use the custom field id of say 37:</p>
  <pre><code>$result = civicrm_api4('Contact', 'get', [ 
    'checkPermissions' =&gt; FALSE, 
    'select' =&gt; [ 'Extra_Info.My_Custom_Field_Name', ], 
    'where' =&gt; [ ['id', '=', '1234'], ], 
    'limit' =&gt; 1,
  ]);
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-17T08:38:53.853Z
Comments.Text: I'm curious why you want to do that?  One of the benefits of APIv4 vs APIv3 is that you don't need to mess around with those field numbers.
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-17T12:52:44.220Z
Comments.Text: @aidan Mostly because that is how I was trying to do it originally and could not figure out how to do it that way...  so now I just want to know how!
Comments.UserDisplayName: jsherk
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-20T08:54:06.647Z
Comments.Text: Ah!  I don't that you can do that directly.  You could use `CustomField::get()->addSelect('name', 'custom_group_id:name')->addWhere('id', '=', 37)` to get the field and group names to plug into your existing query.
Comments.UserDisplayName: Aidan
Tags: <contacts><custom-fields><api><apiv4>
Title: api pull custom field value based on id not label
ThreadText: # api pull custom field value based on id not label
  
  (Asked by: username_0 on 2023-02-17)
  
  Using API 4 (php), how do I retreive a custom field value for a specific contact, using the custom field id instead of the custom field name.
  This works (for contact with id=1234), but requires the use of the custom field name (Extra_Info.My_Custom_Field_Name), but I want to use the custom field id of say 37:
  $result = civicrm_api4('Contact', 'get', [ 
    'checkPermissions' => FALSE, 
    'select' => [ 'Extra_Info.My_Custom_Field_Name', ], 
    'where' => [ ['id', '=', '1234'], ], 
    'limit' => 1,
  ]);
  
  **Tags:** contacts, custom-fields, api, apiv4
  
  > **Comments:**
  > **username_1**: I'm curious why you want to do that?  One of the benefits of APIv4 vs APIv3 is that you don't need to mess around with those field numbers.  
  > **username_0**: @aidan Mostly because that is how I was trying to do it originally and could not figure out how to do it that way...  so now I just want to know how!  
  > **username_1**: Ah!  I don't that you can do that directly.  You could use `CustomField::get()->addSelect('name', 'custom_group_id:name')->addWhere('id', '=', 37)` to get the field and group names to plug into your existing query.  
  
  ---
  
  ## 0 answers
  
  