Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Drupal 7 + Services 3.2

I am using Postman for Chrome (a http client) to test the API.

What I want to do is login a user then create a node with the user by using the Drupal service API.

Below are what I tried:

Firstly, I logged in the user with JSON POST request to http://mysite.com/api/user/login :

enter image description here

Successfully, got return JSON:

{
    "sessid": "KrZjlcY3rFr8v6iLoskcVQN9DmDWsg5yZqIjBeydEBY",
    "session_name": "SESS9fe39db36ccd7afd64e034fefa0129e1",
    "user": {
        "uid": "31",
        "name": "test_user",
        "mail": "[email protected]",
        "theme": "",
        "signature": "",
        "signature_format": "filtered_html",
        "created": "1352985941",
        "access": "1352991170",
        "login": 1352991510,
        "status": "1",
        "timezone": "",
        "language": "",
        "picture": null,
        "init": "[email protected]",
        "data": false,
        "roles": {
            "2": "authenticated user"
        },
        "rdf_mapping": {
            "rdftype": [
                "sioc:UserAccount"
            ],
            "name": {
                "predicates": [
                    "foaf:name"
                ]
            },
            "homepage": {
                "predicates": [
                    "foaf:page"
                ],
                "type": "rel"
            }
        }
    }
}

Then I tried to create an article via the API by sending the JSON POST request. (the user has article create permission)

enter image description here

I got "401 Unauthorized" response.

So I guess I need to include the session cookie info to send the POST request for article create??

I have the session info previously returned:

"sessid": "KrZjlcY3rFr8v6iLoskcVQN9DmDWsg5yZqIjBeydEBY",
"session_name": "SESS9fe39db36ccd7afd64e034fefa0129e1",

How can I utilize it to make a successful JSON POST request for creating an article?

Thanks!

share|improve this question
hi, I have the same problem. Did you got it worked? – Rama raju dantuluri Jun 25 at 12:52

2 Answers

Hope this will help you,

  • To make the HTTP requests, Im using the Firefox add-on POSTER.

    enter image description here

    {
      "type" : "article",
      "title" : "Test article with language",
      "language" : "und"
    }
  • If node is created successfully you will get a response with a link.

    enter image description here

  • Examples

    {
      "type": "article",
      "title": "Test article",
      "body": { 
        "und": [{ 
          "value": "test body!"
         }]
      },
      "language" : "und"
    }
    
    {
       "title":"Review",
       "type":"establishment_review",
       "field_establishment":[
          {
             "nid":{
                "nid":"[nid:26686]"
             }
          }
       ],
       "field_fivestar_value":[
          {
             "rating":"20",
             "target":"0"
          }
       ],
       "field_review":[
          {
             "value":"comments about the restaurant"
          }
       ]
    }
    

  • You can refer this

  • I have answered How do I POST a new node using the Services module question. You can refer for more information.

share|improve this answer
{
   "title": "Just another drupal Post",
   "type": "Article"
}

notice no comma after the type:article tag so that your json works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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