3

I had searched the article, and i still can't figure out how to use services userpoints with xmlrpc.(My Environment drupal 7,Service 3.x, userpoints )

i read the readme in the userpoints module.

$result = xmlrpc($server_url, 'userpoints.points', $key, $uid, $points, $tid, $event, $description);

i wrote this code in the other sites,and tried to add/subtract the points.It doesn't work.

I tried function xmlrpc() in drupal API and follow the api rules, it doesn't work either. drupal api function: xmlrpc($url, $args, $options = array())

the code i wrote:

$key='1234';// casually set
$uid=1;
$points=1;
$tid=18;
$event='event testing';
$description='description testing';
$result = xmlrpc('http://my.domain/userpoints-api/', array(
  'userpoints.points' => array($key, $uid,$points,$tid,$event,$description),
));
dpm($result);

$result is nothing. Does anybody have the experience on this? Thank you guys. Please help me.

i check the access.log i got the message belowed

210.65.11.209 - - [23/Aug/2013:15:49:50 +0800] "POST /userpoints-api/add HTTP/1.0" 200 767 "-" "Drupal (+drupal.org/)
10
  • No results, no errors in watchdog, none in apache error.log?
    – Mołot
    Commented Aug 23, 2013 at 6:51
  • @Mołot Yes,there's nothing happened. I user dpm() can't print anything. Thank you for answering. Do u have any suggestions on this situation? Or something wrong on the code i wrote?
    – cobenash
    Commented Aug 23, 2013 at 7:02
  • Code looks OK, at least good OK to throw sane error so... weird. Try to turn on as high error reporting levels as you can on both ends and run it again. I guess it would be to much to hope you can ettercap communication between these 2 machines?
    – Mołot
    Commented Aug 23, 2013 at 7:06
  • @Molot Is is possible that the setting of the userpoints service is wrong? The endpoints link i used in the browser appears the message"XML-RPC server accepts POST requests only."Is it the problem? Thank you for answering my question
    – cobenash
    Commented Aug 23, 2013 at 7:14
  • Yes it is but I can't know it. As far as I remember Drupal should use POST, but that's the part where I would like you to use Ettercap and simply see if it in fact is doing it. But I understand it might be hard to impossible. Can you access the log of refused / invalid connections?
    – Mołot
    Commented Aug 23, 2013 at 7:17

2 Answers 2

0

I didn't test xmlrpc($server_url, 'userpoints.points', $key, $uid, $points, $tid, $event, $description) is worked or not.

Instead, I use POSTMAN extension from chrome store to post data to the userpoints service api endpoints path.

enter image description here

  1. The userpoints alias must be filled, the data here is "pointss".
  2. url:http:userdomain/userpoints_api/pointss method:POST
  3. header: Content-type | application/xml
  4. raw/xml
<?xml version="1.0"?>
<methodCall>
   <methodName>pointss.add</methodName>
   <params>
     <param>
           <name>uid</name>
           <value><int>1</int></value>
           <name>points</name>
           <value><int>170</int></value>
           <name>tid</name>
           <value><int>18</int></value>
           <name>operation</name>
           <value><string>test for operation</string></value>
           <name>description</name>
           <value><string>test for description</string></value>
           <name>entity_type</name>
           <value><string>node</string></value>
           <name>entity_id</name>
           <value><int>1</int></value>
     </param>
   </params>
</methodCall>

Done.

0

Userpoints Services support Rest Server and XmlRPC Server

i changed the code of the userpoints_service

Now We Can use Rest Server on userpoints

 /**
 * Implementation of hook_services_resources().
 */
function userpoints_service_services_resources() {
  return array(
    'userpoints' => array(
      'retrieve' => array(
        'help' => 'Retrieve the amount of points a user has',
        'file' => array('file' => 'inc', 'module' => 'userpoints_service'),
        'callback' => 'userpoints_service_get',
        'access callback' => 'userpoints_service_view_access',
        'access arguments append' => TRUE,
        'args' => array(
          array(
            'name' => 'uid',
            'type' => 'int',
            'optional' => FALSE,
            'description' => 'The User ID for which the points should be loaded. Defaults to the .',
            'source' => array('path' => 0),
          ),
          array(
            'name' => 'tid',
            'type' => 'all',
            'optional' => TRUE,
            'source' => array('path' => 1),
            'description' => t('An optional Term ID for the category.'),
          ),
          array(
            'name' => 'type',
            'type' => 'string',
            'optional' => TRUE,
            'source' => array('path' => 2),
            'description' => t('The type of points, either max or current, to which it defaults.'),
          ),
        ),
      ),
      'update'=>array(
        'help' => 'Add or subtract a given amount of points for a user',
          'file' => array('file' => 'inc', 'module' => 'userpoints_service'),
          'callback' => 'userpoints_service_add',
          'access callback' => 'userpoints_admin_access',
          'access arguments' => array('add'),
          'args' => array(
            array(
              'name' => 'uid',
              'type' => 'int',
              'optional' => FALSE,
              'description' => 'A valid Drupal User ID.',
              'source' => array('path' => 0),
            ),
            array(
              'name' => 'points',
              'type' => 'int',
              'optional' => FALSE,
              'source' => array('param' => 'points'),
              'description' => 'Number of points to add/subtract.',
            ),
            array(
              'name' => 'tid',
              'type' => 'int',
              'optional' => TRUE,
              'source' => array('data' => 'tid'),
              'description' => t('An optional Term ID for the category.'),
            ),
            array(
              'name' => 'operation',
              'type' => 'string',
              'optional' => TRUE,
              'source' => array('data' => 'operation'),
              'description' => t('An operation string for this transaction.'),
            ),
            array(
              'name' => 'description',
              'type' => 'string',
              'optional' => TRUE,
              'source' => array('data' => 'description'),
              'description' => t('An optional description of this transaction.'),
            ),
            array(
              'name' => 'entity_type',
              'type' => 'string',
              'optional' => TRUE,
              'source' => array('data' => 'entity_type'),
              'description' => t('An optional description of this transaction.'),
            ),
            array(
              'name' => 'entity_id',
              'type' => 'int',
              'optional' => TRUE,
              'source' => array('data' => 'entity_id'),
              'description' => t('An optional description of this transaction.'),
            ),
          ),
      ),
      'index' => array(
        'help' => 'Index of all users with points',
        'file' => array('file' => 'inc', 'module' => 'userpoints_service'),
        'callback' => 'userpoints_service_index',
        'access callback' => 'userpoints_service_view_access',
        'args' => array(
          array(
            'name' => 'page',
            'optional' => TRUE,
            'type' => 'int',
            'description' => 'The zero-based index of the page to get, defaults to 0.',
            'default value' => 0,
            'source' => array('param' => 'page'),
          ),
          array(
            'name' => 'tid',
            'type' => 'string',
            'optional' => TRUE,
            'source' => array('param' => 'tid'),
            'description' => t('An optional Term ID for the category.'),
          ),
          array(
            'name' => 'sort',
            'type' => 'string',
            'optional' => TRUE,
            'default value' => 'points',
            'source' => array('param' => 'sort'),
            'description' => t('Sort field'),
          ),
          array(
            'name' => 'dir',
            'type' => 'string',
            'optional' => TRUE,
            'default value' => 'DESC',
            'source' => array('param' => 'dir'),
            'description' => t('Sort direction'),
          ),
        ),
      ),
      'actions' => array(
        'add' => array(
          'help' => 'Add or subtract a given amount of points for a user',
          'file' => array('file' => 'inc', 'module' => 'userpoints_service'),
          'callback' => 'userpoints_service_add',
          'access callback' => 'userpoints_admin_access',
          'access arguments' => array('add'),
          'args' => array(
            array(
              'name' => 'uid',
              'type' => 'int',
              'optional' => FALSE,
              'description' => 'A valid Drupal User ID.',
              'source' => array('path' => 0),
            ),
            array(
              'name' => 'points',
              'type' => 'int',
              'optional' => FALSE,
              'source' => array('param' => 'points'),
              'description' => 'Number of points to add/subtract.',
            ),
            array(
              'name' => 'tid',
              'type' => 'int',
              'optional' => TRUE,
              'source' => array('data' => 'tid'),
              'description' => t('An optional Term ID for the category.'),
            ),
            array(
              'name' => 'operation',
              'type' => 'string',
              'optional' => TRUE,
              'source' => array('data' => 'operation'),
              'description' => t('An operation string for this transaction.'),
            ),
            array(
              'name' => 'description',
              'type' => 'string',
              'optional' => TRUE,
              'source' => array('data' => 'description'),
              'description' => t('An optional description of this transaction.'),
            ),
            array(
              'name' => 'entity_type',
              'type' => 'string',
              'optional' => TRUE,
              'source' => array('data' => 'entity_type'),
              'description' => t('An optional description of this transaction.'),
            ),
            array(
              'name' => 'entity_id',
              'type' => 'int',
              'optional' => TRUE,
              'source' => array('data' => 'entity_id'),
              'description' => t('An optional description of this transaction.'),
            ),
          ),
        ),
      ),
    ),
  );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.