drupal-7drupal-services

Drupal custom service (services module)


I have registered a service, when I call it, the call itself works, but the data returned is "false". I don't know what I am doing wrong, and I can't find info about it. Can anyone help me out please ?

function services_sso_server_extension_services_resources() {
    return array(
        'mia' => array(
            'actions' => array(
                'retrieve' => array(
                    //'help' => 'retrieves the corresponding user on the server',
                    'file' => array('type' => 'inc', 'module' => 'services_sso_server_extension', 'name' => 'resources/extension'),
                    'callback' => '_sso_server_retrieve',
                    'args' => array(
                        array(
                            'name' => 'id',
                            'type' => 'int',
                            'description' => 'The id of the note to get',
                            'source' => array('path' => '0'),
                            'optional' => TRUE,
                        ),
                    ),
                    'access callback' => '_sso_server_access',
                    'file' => array('type' => 'inc', 'module' => 'services_sso_server_extension', 'name' => 'resources/extension'),
                    'access arguments' => array('view'),
                    'access arguments append' => TRUE,
                ),
                'action' => array(
                    //'help' => 'retrieves the corresponding user on the server',
                    'file' => array('type' => 'inc', 'module' => 'services_sso_server_extension', 'name' => 'resources/extension'),
                    'callback' => '_sso_server_get_action',
                    'args' => array(
                        array(
                            'name' => 'clientsid',
                            'type' => 'varchar',
                            'description' => 'The sid of the client to which the communication is bound',
                            'source' => array('path' => '0'),
                            'optional' => TRUE,
                        ),
                    ),
                    'access callback' => '_sso_server_access',
                    'file' => array('type' => 'inc', 'module' => 'services_sso_server_extension', 'name' => 'resources/extension'),
                    'access arguments' => array('view'),
                    'access arguments append' => TRUE,
                ),
            ),
        ),
    );
}

I use this code somewhere else to call it:

 function services_checkuser() {
    global $user;
    $sid = $user->sid;

    $options = array(
        'headers' => array(
            'Cookie' => $_SESSION['gsid'],
            'Accept' => 'application/json',
            'clientsid' => $sid
        ),
        'method' => 'POST',
    );

    $response = drupal_http_request('http://sso.server:8080/usercheck/mia/action', $options);
    $data = json_decode($response->data);
}

Solution

  • Ok I found out how to post the data:

    $data = array('gsid' => $gsid);
    
    $options = array(
        'headers' => array(
            'Cookie' => $_SESSION['broker_sid'],
            'Accept' => 'application/json',
        ),
        'method' => 'POST',
        'data' => http_build_query($data)
    );