Receiving this error when trying to add a new user on the remote site. Where should user_raw come from?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mhrabovcin’s picture

Hello,

here is my sandbox project that provides these resources - http://drupal.org/sandbox/mhrabovcin/1424044 please note that this is bypassing any drupal validation and raw data are saved only via API functions like user_save.

Martin

Nick_vh’s picture

Status: Active » Fixed

This is included in the project now. So i think we can close this one

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jpstrikesback’s picture

Status: Closed (fixed) » Active

I'm seeing this with services_raw installed, very odd. I've tried upping it's module weight, a lite refactor (moved methods into a .resource.inc file and the services_resources implementation back into the .module) no dice.

Debug:
ServicesException::__set_state(array(
'data' => 'Could not find resource node_raw.',
'message' => 'Could not find resource node_raw.',
'string' => '',
'code' => 404,
'file' => '/srv/bindings/.../code/sites/all/modules/services/services.runtime.inc',
'line' => 355,
'trace' =>
array (
0 =>
array (
'file' => '/srv/bindings/.../code/sites/all/modules/services/servers/rest_server/includes/RESTServer.inc',
'line' => 76,
'function' => 'services_error',
'args' =>
array (
0 => 'Could not find resource node_raw.',
1 => 404,
),
),
1 =>
array (
'file' => '/srv/bindings/.../code/sites/all/modules/services/servers/rest_server/rest_server.module',
'line' => 34,
'function' => 'handle',
'class' => 'RESTServer',
'type' => '->',
'args' =>
array (
0 => 'node_raw/create',
1 => 'endpoint',

mhrabovcin’s picture

Can you export your services endpoint settings?

jpstrikesback’s picture

Here we are:

$endpoint = new stdClass();
$endpoint->disabled = FALSE; /* Edit this to true to make a default endpoint disabled initially */
$endpoint->api_version = 3;
$endpoint->name = 'node_bus';
$endpoint->server = 'rest_server';
$endpoint->path = 'node_bus';
$endpoint->authentication = array(
  'services' => 'services',
);
$endpoint->server_settings = array(
  'formatters' => array(
    'bencode' => TRUE,
    'json' => TRUE,
    'jsonp' => TRUE,
    'php' => TRUE,
    'rss' => TRUE,
    'xml' => TRUE,
  ),
  'parsers' => array(
    'application/json' => TRUE,
    'application/vnd.php.serialized' => TRUE,
    'application/x-www-form-urlencoded' => TRUE,
    'application/xml' => TRUE,
    'multipart/form-data' => TRUE,
    'text/xml' => TRUE,
  ),
);
$endpoint->resources = array(
  'node' => array(
    'operations' => array(
      'retrieve' => array(
        'enabled' => '1',
      ),
      'create' => array(
        'enabled' => '1',
      ),
      'update' => array(
        'enabled' => '1',
      ),
      'delete' => array(
        'enabled' => '1',
      ),
      'index' => array(
        'enabled' => '1',
      ),
    ),
    'relationships' => array(
      'files' => array(
        'enabled' => '1',
      ),
      'comments' => array(
        'enabled' => '1',
      ),
    ),
    'targeted_actions' => array(
      'attach_file' => array(
        'enabled' => '1',
      ),
    ),
  ),
  'user' => array(
    'operations' => array(
      'retrieve' => array(
        'enabled' => '1',
      ),
    ),
    'actions' => array(
      'login' => array(
        'enabled' => '1',
      ),
      'logout' => array(
        'enabled' => '1',
        'settings' => array(
          'services' => array(
            'resource_api_version' => '1.0',
          ),
        ),
      ),
    ),
  ),
  'node_raw' => array(
    'alias' => 'rawnode',
    'operations' => array(
      'create' => array(
        'enabled' => '1',
      ),
      'update' => array(
        'enabled' => '1',
      ),
    ),
    'targeted_actions' => array(
      'attach_file' => array(
        'enabled' => '1',
      ),
    ),
  ),
  'field' => array(
    'operations' => array(
      'update' => array(
        'enabled' => '1',
      ),
    ),
  ),
  'user_raw' => array(
    'operations' => array(
      'retrieve' => array(
        'enabled' => '1',
      ),
    ),
  ),
);
$endpoint->debug = 1;
mhrabovcin’s picture

I see the problem, you have aliased your node_raw resource to rawnode
'alias' => 'rawnode',

jpstrikesback’s picture

With or without Alias I still get the same 404 unfortunately...(I mean with the alias in the config and visiting either the endpoint or the aliased endpoint, and also without the alias in the resource config)

jpstrikesback’s picture

OK, I've played with the endpoint a little more:

GET = 404
POST = 404
PUT = 401 :) so it wants a PUT, all my node_raw/create requests from services client are sent as POST, is that correct?

jpstrikesback’s picture

OK I believe I have found the issue after learning a little about services, etc...

Services is expecting a POST with no path arguments to initiate the create action.

Because ServicesClientConnectionHttpRequest->http_method defaults to 'GET' ServicesClientConnectionRestServer::prepareRequest() always skips over the special REST CRUD actions as that block has if (empty($request->http_method) as it's first condition, and it is (AFAIK) never empty at this point since the default is 'GET'. Then it moves on and eventually appends /create to the url, sends a POST and RESTServer has no idea what to do with this.

mhrabovcin’s picture

Title: [services_error] => Could not find resource user_raw. » Broken REST requests when creating CRUD request via REST plugin
Assigned: Unassigned » mhrabovcin
mhrabovcin’s picture

I've added patch which fixes the problem and added better comments for decision logic in REST plugin.

mhrabovcin’s picture

Status: Active » Needs review
Nick_vh’s picture

+++ b/services_client_connection/plugins/ServicesClientConnectionRestServer.incundefined
@@ -94,10 +94,10 @@ class ServicesClientConnectionRestServer extends ServicesClientConnectionServer
+    if (in_array($request->action, array_keys($this->rest_actions))) {

you can add !empty() here and then resort to elseif without condition?

mhrabovcin’s picture

Status: Needs review » Fixed

http_method is always initialized by default to 'GET'. Committed to repo.

jpstrikesback’s picture

Excellent, thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.