Get All Users' Subscriptions via API

Discussion in 'Customization & add-ons' started by dealershift, Jun 28, 2012.

  1. dealershift

    dealershift New Member

    Joined:
    Mar 10, 2012
    Messages:
    22
    I'm trying to get all users with their active subscriptions or I need to check to see if a specific subscription is active for each user.

    I have included the boostrap.php file successfully, but can't seem to get it to work . Any help would be greatly appreciated.

    Here is what I have so far (Not much)
    PHP:
    require_once('../amember/bootstrap.php');
    $user Am_Di::getInstance()->userTable;
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Here is how you cab check if subscription is active for logged in user:
    PHP:
    require_once('../amember/bootstrap.php');
    $user am_Di::getInstance()->auth->getUser();
    if(!
    $user) {
    // user is not logged in
    }else{
      
    $products $user->getActiveProductIds();
      if(
    in_array(1$products)){
      
    // user have product1
      
    }
    }
  3. dealershift

    dealershift New Member

    Joined:
    Mar 10, 2012
    Messages:
    22
    Thanks for the response. I will be using a CRON job to check all users, so they won't be logged in. Is there a way to do it without having the user logged in?


  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Sure here is code for any user:
    PHP:
    require_once('../amember/bootstrap.php');
    $user am_Di::getInstance()->userTable->load($user_idfalse);
    if(!
    $user) {
    // user is not found
    }else{
      
    $products $user->getActiveProductIds();
      if(
    in_array(1$products)){
      
    // user have product1
      
    }
    }

Share This Page