0

I'd like to be able to create a topic on an existing forum, using the REST API exposed by the Services module. This is drupal7 and services 3.x .

via the REST interface, I can successfully:

  • query the index of forums GET /rest/node?parameters\[type\]=forum
  • retrieve a single forum post. GET /rest/node/8
  • update forum posts (via PUT) PUT /rest/node/8 ...

I have not been able to create a forum post. I tried many different variations of the JSON payload, and have not yet found the secret to success.

Example:

curl -i -X POST \
  -H Cookie:SESSe6a353351df0bfa8deadcafe=B0ZkiW3-U2x93yJU-deadbeef \
  -H X-CSRF-Token:PSCd5qIdddax0Mh5gfnOM872hdj893-eeeeffff \
  -H Accept:application/json \
  -H content-type:application/json \
  http://myserver/rest/node \
  -d '{
    "title": "This is a test post", 
    "body": {
      "und": [{
        "value" : "This is a test post. Please ignore.",
        "summary": "test1",
        "format": "filtered_html"
      }]
    },
    "type": "forum", 
    "language": "und",
    "status": "1",
    "forum_tid": "8"
  }'

The error looks like this

{
  "form_errors": {
    "taxonomy_forums][und":"An illegal choice has been detected. Please contact the site administrator."
  }
}

I have tried many variations of the payload, and always get the same error. I think the error means I need to pass different data. But I don't know which different data. Help?

0

Er, yes, I just succeeded in creating a Forum topic, after many trials. This was successful :

curl -i -X POST \
  -H Cookie:SESSe6a353351df0bfa8deadcafe=B0ZkiW3-U2x93yJU-deadbeef \
  -H X-CSRF-Token:PSCd5qIdddax0Mh5gfnOM872hdj893-eeeeffff \
  -H Accept:application/json \
  -H content-type:application/json \
  http://myserver/rest/node \
  -d '{
    "type": "forum", 
    "title": "test post?", 
    "language": "und",
    "taxonomy_forums": {
      "und": "1"
    },
    "body": {
      "und": [{
        "value" : "test post",
        "summary": "this is a test1",
        "format": "full_html"
      }]
    }
  }'

The key difference was, I think, adding this to the JSON:

    "taxonomy_forums": {
      "und": "1"
    },

I guessed this, based on a view of the Firefox firebug Net panel, when using the UI to post a new forum topic. This number specifies the forum to which the new topic should be associated. It is a different matter to get the list of forum topics!

Maybe this will help others.

  • The drupal services module needs "smartdocs". – Cheeso Mar 16 '15 at 23:36

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.