Announcement

Collapse
No announcement yet.

API get only few fields from the user

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • API get only few fields from the user

    Hey guys!
    I was following the documentation (PHP composer) and I was able to retrieve user details using this construction:
    $response = $client->request(Client::METHOD_GET, 'User/' . $id);​

    However it returns everything, for instance, related opportunities, can I limit and pull first name and phone only?

    I was trying this:
    $response = $client->request(Client::METHOD_GET, 'User/' . $id, [
    'select' => 'id', 'firstName', 'phoneNumber'
    ]);​


    But it still returns everything, any ideas?

    Thanks

  • #2
    Hey Russ

    Not sure if it can bee applied when requesting one resource but as a workaround i know that when trying to get a list you can specify more parameters to the Get request so you can apply this to your use case, see code below (with comments for each option) :

    PHP Code:
    $url 'User';

    $where = [
        [
            
    'type' => 'equals',
            
    'attribute' => 'id',
            
    'value' => {$id},
        ],
    ];

    // the list of available primary filters can obtained in a select manager class (active) users
    $primaryFilter 'active';

    // every param is optional
    $params = [
        
    'offset' => 0,
        
    'maxSize' => 1,
        
    'where' => $where,
        
    'primaryFilter' => $primaryFilter,
        
    'select' => 'id,name,type'// specify here the fields (attributes) to be returned
        
    'orderBy' => 'createdAt',
        
    'order' => 'desc',
    ];

    $response $client->request('GET'$url$params);​​ 

    This should return a list of users which contains only one user as per your where parameters (then you can just loop through the list and get the user) - see select option which allow you to specify which attributes should be returned by the request.

    hope this helps
    Last edited by rabii; 07-10-2023, 10:00 AM.

    Comment


    • #3
      Originally posted by rabii View Post
      Hey Russ

      Not sure if it can bee applied when reauesting one resource but as a workaround i know that when trying to get a list you can specify more parameters to the get request so you can apply this to your use case, see code below (with comments for each option) :

      PHP Code:
      $url 'User';

      $where = [
      [
      'type' => 'equals',
      'attribute' => 'id',
      'value' => {$id},
      ],
      ];

      // the list of available primary filters can obtained in a select manager class (active) users
      $primaryFilter 'active';

      // every param is optional
      $params = [
      'offset' => 0,
      'maxSize' => 1,
      'where' => $where,
      'primaryFilter' => $primaryFilter,
      'select' => 'id,name,type'// specify here the fields (attributes) to be returned
      'orderBy' => 'createdAt',
      'order' => 'desc',
      ];

      $response $client->request('GET'$url$params);​​ 

      This should return a list of users which contains only one user as per your where parameters (then you can just loop through the list and get the user) - see select option which allow you to specify which attributes should be returned by the request.

      hope this helps
      Nice, list instead of details, got it, thanks

      Comment


      • rabii
        rabii commented
        Editing a comment
        you are welcome
    Working...
    X