1

Using Drupal Services I am able to log in but each time I post a node it posts as anonymous. I get the session id and session name upon login but can´t pass it along with a POST no matter what i try.

I have tried including it in the json string, as a header and within the URL - without any result. I'm testing using the Chrome Postman as REST client.

What am I doing wrong?

Thank you for any help!

var session_id = $('#session_id').text();
$.ajax({
  type: "POST",
  url: 'http://www.website.com/active_services/node?sessid='+session_id, 
  data: JSON.stringify(noden),
  headers : {
    "Authorization" : session_id,
    "sessid" : session_id,
    "sessionid" : session_id,
  }, 
  beforeSend: function (req){
    req.setRequestHeader("Authorization",session_id);
    req.setRequestHeader("sessid",session_id);
    req.setRequestHeader("sessionid",session_id);
    req.setRequestHeader("Content-Type", "application/json");
  },    
  dataType: 'json',
  contentType: 'application/json',
  success: function(data){
    console.log(data);
 }
  • Are you using any REST client to test this out ? – niksmac Mar 9 '13 at 2:35
1

I am using POSTMAN to test my REST calls to server.

When i try http://mysite.com/api/endpoint/users/login.json

with parametes

  1. Content-Type - application/json

  2. username - A valid username on site

  3. password - users password

I get a json looks like this

{
    "sessid": "6nRaPdlYfV4mDt0cgUHfGwNmWJZNvUfKM618DYY4unc",
    "session_name": "SESS4356595e5cb4b5df8f18058cfbd8d13a",
    "user": {
        "uid": "144",

From that i suspect you should pass sessid and session_name to get it work.

Try it and let me know whether its working if not we find some other solution which works :)

enter image description here

  • Thank you for your response! I have always been able to receive the session name and ID without a problem. The problem is that I can't pass them when I'm POSTing a node-create. I test using Chrome Postman as well. How should I setup my ajax POST above so the session info gets correctly transferred and I post as a signed in user? @Nikhilm – MDDY Mar 9 '13 at 10:43
  • Just login to website in other tab :) – niksmac Mar 11 '13 at 11:08
  • But im not using a browser, I'm creating an iPhone app that connects to the Drupal services API. Any ideas? :) @Nikhilm – MDDY Mar 11 '13 at 11:50

Your Answer

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

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