I am running Comment Driven on my website. I am attempting to implement Services for authorized users to post comments to the website. I created a service requiring session authentication. With that service and a valid cookie, I am able to get/create nodes and get comments, but am unable to create new comments.
Sadly, I am able to post a valid comment if I disable Comment Driven (note: I have used a fake username and password for the website):
curl -u username:password -H "Content-type: application/json" -b testCookies.txt http://dev.bouldermountainbike.org/api/testAuth/comment -d '{"nid":"175","comment":"comment_driven disabled, test comment"}'
{"cid":"3351","uri":"http://dev.bouldermountainbike.org/api/testAuth/comment/3351"}
With Comment Driven reenabled:
curl -u username:password -H "Content-type: application/json" -b testCookies.txt http://dev.bouldermountainbike.org/api/testAuth/comment -d '{"nid":"175","comment":"comment_driven now enabled"}'
["An illegal choice has been detected. Please contact the site administrator. Comment field is required (or a driven property change otherwise)."]
This issue is cross-posted to the Services issues queue, with greater issue detail: http://drupal.org/node/1930348
Comments
Comment #1
arhak commentednot sure that I will have the time to look deeper into this one,
but I would need something to work with
contact me (via d.o. contact form) to send me some credentials
since I would like to inspect your comment form at http://dev.bouldermountainbike.org/node/175
also state your Drupal version
Comment #2
boulderfuzz commenteddone.
Note that the Services maintainers state: "This is an issue with comment driven as services simply 'fakes' doing a form submit." in thread http://drupal.org/node/1930348
Comment #3
arhak commentedBTW at #1930348: post comment yields "comment field is required" your first chunk of code doesn't seem to correspond with D6:
[...] "comment_body":{ "und":[ { "value":"this test comment [...]Comment #4
arhak commentedinstead of posting a nid & comment (via REST) try nid &
cdriven-commentinspecting your comment form you'll notice that it had suffered modifications (by comment_driven) to merge a node form within a comment form
you can decide to implement it like this as a workaround
or you can dig deeper into the matter #741274: Using comment driven programmatically
Comment #5
boulderfuzz commentedRe #3
Yup I realized that my comment JSON was poorly formed, and posted a better version later in the thread. When comment_driven was disabled, Services would properly process the following comment POST:
Comment #6
boulderfuzz commentedbuilding off of #4... thanks for the hint, works great!
Thus, with comment_driven enabled, I can successfully use cdriven-comment to post a new comment:
Comment #7
boulderfuzz commentedNext stumbling block ... I'll continue under the same issue as this pertains to using Comment Driven with Services 3. BTW I spent time looking through related issues e.g. http://drupal.org/node/746870, http://drupal.org/node/816908 and could not determine how to do the following.
With comment submission, users need to also update the node's field_trail_meter. For example, see form at bottom of http://dev.bouldermountainbike.org/node/217 - Trail Condition corresponds to field_trail_meter.
How do I update this field using Comment Driven and Services 3 REST?
At first I thought I would simply format the POST exactly as formatted when you request the node through Services, and pass through cdriven. For example, here's the appropriate section of node 217, in JSON format as returned by Services:
Attempting to submit the new Trail Condition using cdriven-field_trail_meter:
Looks great at first but there's a catch - the comment was submitted successfully, but the node's field_trail_meter is unchanged. Do I have the cdriven field name incorrect?
Comment #8
arhak commented@#7
no, no, the
cdrivenprefix is NOT for everythingnote there are two forms merged into one,
you have to distinguish between what is addressing the comment_form part versus what is aiming the node_form part
see #741274-1: Using comment driven programmatically
PS: when referring to other issues, please type:
- the issue number
- pefixed by
#- and all that between square brackets
that way you write less, the issue gets linked automatically, and we can read the issue title and status in a peek
e.g.
- writing:
#746870: FAQ: what might be the problem with comment-related modules? & #816908: Why add "cdriven" prefix to all the names?- yields: #746870: FAQ: what might be the problem with comment-related modules? & #816908: Why add "cdriven" prefix to all the names?
Comment #9
arhak commentedto make my self clear, your use case is not the same as in #741274-1: Using comment driven programmatically, that is an example to distinguish between which fields get prefixed (those belonging to the comment form) and which fields doesn't (those belonging to the node form)
therefore, you should address your
field_trail_meterfield as if you were submitting it to a node edit formComment #10
boulderfuzz commentedThanks for the tutorial on how to properly reference other issues. And thanks for helping me work through this issue in detail.
If I understand you properly, the following should work:
curl -v -u user:pass -H "Content-type: application/json" -b testCookies.txt https://dev.bouldermountainbike.org/api/testAuth/comment -d '{"nid":"217","cdriven-comment":"using cdriven-comment, attempting to set meter=0","field_trail_meter":[{"value":"0"}]}'... but this syntax still fails to update the node field.
Are you recommending that I do two submissions, one through /comment resource and one through /node resource in Services? I'm trying to avoid that route if at all possible because then I have dissonance between the node versions. It would be best if I could force Services to accept the comment and node updates at once.
Comment #11
arhak commentednot at all
to figure out the proper structure to POST, you should conduct a test on a node edit form first,
once you have a successful REST POST on a node edit form (noting the field you're addressing did change as intended)
then use the same structure for that field on the comment form POST
I'm not telling you to do 2 submissions to achieve your goal,
but to test first with a node edit form, and once you know how to address that field
proceed to do it via comment form
note that deppending on the type of the filed, the structure of field_trail_meter might requiere a different post data
the way to figure that out is conducting a test on the node form itself
Comment #12
arhak commentedComment #13
boulderfuzz commentedI'm back, sorry but I was ill.
I used your test from @#11 to determine the node form's needs, and now know the syntax to successfully update nodes through Services. However, I discovered that Services requires HTTP PUT to update a node (change a field in already-existing node) but we know from earlier work in this thread that HTTP POST is needed to create a new comment. The crux: I cannot reconcile the PUT edit node and POST new comment into a single call to Services. I will demonstrate below to show you what I mean....
Start by saving the current node fieldset, so I can monitor what changes:
curl -u user:pass -b cookieAdmin.txt https://dev.bouldermountainbike.org/api/testAuth/node/390 > trail390.jsonUse Services to submit node edit form via PUT; change node field field_trail_meter (note the node form requires "type" field), this will successfully change field_trail_meter as well as update version number, etc:
Changing field_trail_meter was successful! So I know that syntax is correct.
Note that attempting REST POST to edit the node will fail:
Going back to creating a comment ... as in @#6, I can use Services to create a new comment via POST:
Ultimately I want to update field_trail_meter while creating (POST) a new comment. But this doesn't work; note that although I receive HTTP 200 response for the below, only the comment is updated; field_trail_meter remains unchanged:
Ideas on how to proceed?