0

I need to load data from a Drupal View into an external (non-Drupal) site using PHP.

I'm using XML-RPC for PHP.

I'm able to connect to the system and login, but I'm unable to retrieve a View. I get the following error: HTTP/1.1 401 Unauthorized: Missing required argument view_name

I haven't been able to find documentation on format of the RPC call required for views and how the session id is passed. Any pointers would be greatly appreciated. Code below. The name of the view I'm trying to get is "configurations".

require_once ("xmlrpc.inc");

// SYSTEM.CONNECT
$f = new xmlrpcmsg('system.connect');
$c = new xmlrpc_client($XMLRPC_SERVER);
$r = &$c -> send($f);

// SYSTEM.CONNECT SUCCESS
if (!$r -> faultCode()) {

    print('system connected...');
    $v = php_xmlrpc_decode($r -> value());
    $system_sessid = htmlspecialchars($v["sessid"]);

    // USER.LOGIN
    $f_login = new xmlrpcmsg('user.login', array(php_xmlrpc_encode('USERNAME'), php_xmlrpc_encode('PASSWORD')));
    $c_login = new xmlrpc_client($XMLRPC_SERVER);
    $c_login -> setDebug(1);
    $r_login = &$c_login -> send($f_login);

    // USER.LOGIN SUCCESS
    if (!$r_login -> faultCode()) {

        $v = php_xmlrpc_decode($r_login -> value());
        $sessid = htmlspecialchars($v["sessid"]);
        print('logged in...' . $sessid);

            $f_configs = new xmlrpcmsg('views.retrieve', array(php_xmlrpc_encode('configurations-xmlrpc')), array(php_xmlrpc_encode('configurations-xmlrpc')), array(php_xmlrpc_encode('configurations-xmlrpc')));

            $c_configs = new xmlrpc_client($XMLRPC_SERVER);
            $c_configs -> setDebug(1);
            $r_configs = &$c_configs -> send($f_configs);

            if (!$r_configs -> faultCode()) {
                print('got configs');
            } else {
                print('error getting configs...');
            }

        } else {
            print('error logging in...');
        }
} else {
    print('error connecting to system');
}

1 Answer 1

0

I think you forgot to send the the view_name that is a non-optinal argument. Check the code of the resource:

'view_name' => array(
  'name' => 'view_name',
  'type' => 'string',
  'description' => 'The name of the view to get.',
  'source' => array('path' => '0'),
  'optional' => FALSE,
),

Your Answer

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

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