Charging UserPoints for flagging a node with Rules in PHP I am trying to charge points for flagging a node with Rules in PHP, an I am using the following code.

 //Get variables and load user.
$uid = [userpoints-transaction:user:uid];
$account = user_load($uid);

// Check the user has enough points.
if ($loaded_points &gt; 10) {

  // DON'T KNOW HOW TO TAKE 10 POINTS.

  // Flag a node.
  $flag = flag_get_flag('purchase') or die('no "purchase" flag defined');
  $flag-&gt;flag('flag', $node-&gt;nid);
  // Search for the newly created flagging entity.
  $flag = flag_get_user_flags('node', $node-&gt;nid);

  foreach ($flag as $flagging_object) {
    $flagging_id = $flagging_object-&gt;flagging_id;
  }

  // Load the entity found and create or update a field value.
  $flagging = entity_load_single('flagging', $flagging_id);
  $flagging-&gt;purchase['und'][0]['value'] = 'DONT KNOW DEFAULT VALUE OF FLAGGING';

  // Save the updated flagging entity object.
  entity_save('flagging', $flagging);
}

drupal_set_message($msg);


I don't know how to charge them 10 points and what the default value is when flagging a node.
When you simply want to grant 10 userpoints to a user after flagging a node, you're making things way to complicated! This can be done without custom coding at all. Here's what you have to do:


Create a new rule.
Add an event "A node has been flagged, under YOUR_FLAG".
Add an action "Grant points to a user" and give it an amount of 10.
Done!