0

So after installing UUID, the service module no longer has 'create' with the entity type 'node'.

On looking at UUID documentation, it says that I can use update to both create or update content.

Now update works via PUT, right?

So I got the cookie, X-CSRF-Token which work, and am trying to make a put call to http://d7.local/test/node/e9e521e2-1717-4a5e-a7f8-26f7d9012154. (test is the endpoint.)

  1. I don't like this method as I have to generate a random UUID on my end (client), and on the offchance that the UUID is already present on the server, I would update something else instead of creating a new node.

  2. The bigger problem is that it doesn't work at all. In fact, on further debugging I find that _uuid_services_entity_update() is not even able to function.

Now I'm sure I'm screwing up on major areas, so please help me out, and tell me how I should go ahead with creating a node using the UUID Services module.

function content_submit($form, &$form_state) {
  $cookie = retrieve_session_cookie();
  $server_url = variable_get('server_url');
  $token = drupal_http_request($server_url . '/services/session/token',array('headers'=>array('Cookie' => $cookie)))->data;
  $params = array(
    "type" => "article",
    "language" => "en",
    "title" => $form_state["values"]["question"],
    "body" = "This is the body"
   ), 
  );

  $args = array(
    'method' => 'PUT',
    'headers' =>array('Content-Type' => 'application/json','Cookie' => $cookie, 'X-CSRF-Token' => $token),
    'data' => drupal_json_encode($params),
    );
  //Desperate man hoping any of them will work
  $response = drupal_json_decode(drupal_http_request($server_url . '/test/node/e9e521e2-1717-4a5e-a7f8-26f7d9012154', $args)->data);
  $response = drupal_json_decode(drupal_http_request($server_url . '/test/node', $args)->data);
  $response = drupal_json_decode(drupal_http_request($server_url . '/test/node', $args)->data);

  return;
}


function retrieve_session_cookie() {
  $login_details = '{"username" : "' . variable_get('server_username') . '", "password" : "' . variable_get('server_password') . '"}';
  $url = variable_get('server_url') . '/test/user/login';
  $options = array(
    'method' => 'POST',
    'headers' =>array('Content-Type' => 'application/json'),
    'data' => $login_details ,
    );
  $result = drupal_json_decode(drupal_http_request($url,$options)->data);
  $sessid = $result["sessid"];
  $session_name = $result["session_name"];
  $cookie = $session_name . '=' . $sessid;
  return $cookie;
}

I figured out what the issue was, but I am far from being pleased: In the JSON, I also had to pass the uuid (e9e521e2-1717-4a5e-a7f8-26f7d9012154) and then it works.

I have no idea which UUID is present on the site. If I am using an existing UUID, won't some content get updated? Generating the UUID on the second site doesn't look like a good idea.

Surely there must be a better way to go about this. Can anyone guide me on this?

  • Can you edit the question to include the code you've tried that didn't work please? Bear in mind that UUID is still in alpha, so this will likely be a bug report which needs to go to the module's issue queue – Clive Sep 24 '13 at 14:42
  • @Clive - Updated the code – Pratik Bothra Sep 24 '13 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.