Get user details by user email via PHP code?

Discussion in 'Integration' started by ichsie, Jan 12, 2018.

  1. ichsie

    ichsie New Member

    Joined:
    Jul 8, 2013
    Messages:
    1
    We are datasn.io and would like to offer our users the option to create API keys to access our data collections like this:

    https://datasn.io/aaa/bbb/ccc/ddd/?api_key=xxxxxx

    Our code base would then look up the API key in our database with its associated user email. And then we will find the user details in aMember pro by the email to make sure it's actively subscribed to our plans.

    I know Am_Lite but it seems to only return the info of logged in user but in our scenario, API requests are authenticated by the API key instead of by any user credentials.

    So is there any way to find the details (general info, subscribed plan, active or not, etc.) of a particular user by the email even when he or she's not logged in? Which file or class should I include for this?

    P.S. I'd prefer not to use the REST API as it's slow in nature.

    Thank you so much!
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,862
    Hello,

    You can rely on aMember code base:

    PHP:
    <?php

    require_once 'path/to/amember/bootstrap.php';

    /* @var $user User */
    $user Am_Di::getInstance()->userTable->findFirstByEmail('user@example.com');

    $pids $user->getActiveProductIds(); //array of product ids  
    Best Regards.

Share This Page