Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not able to POST comment on node #1057

Open
giteshdang opened this issue May 6, 2019 · 0 comments
Open

not able to POST comment on node #1057

giteshdang opened this issue May 6, 2019 · 0 comments

Comments

@giteshdang
Copy link

giteshdang commented May 6, 2019

Dear Mates,
I am trying to post a comment to a node using POST method to the endpoint api/v1.1/comments
Note: Endpoint is custom created and copied from restful_example module with my own endpoint url.

/** * @file * Contains \Drupal\restful_example\Plugin\resource\comment\Comments__1_0. */
namespace Drupal\lsd_restful_api\Plugin\resource\comment;

use Drupal\restful\Plugin\resource\ResourceEntity;
use Drupal\restful\Plugin\resource\ResourceInterface;
use Drupal\lsd_restful_api\Plugin\resource\comment\DataProviderCommentNew;

/**
 * Class Comments__1_1
 * @package Drupal\restful_example\Plugin\resource\comment
 *
 * @Resource(
 *   name = "comments:1.1",
 *   resource = "comments",
 *   label = "Comments",
 *   description = "Export the comments with all authentication providers.",
 *   authenticationTypes = {
 *      "token",
 *     "basic_auth"
 *   },
 *   authenticationOptional = TRUE,
 *   dataProvider = {
 *     "entityType": "comment",
 *     "bundles": FALSE,
 *   },
 *   majorVersion = 1,
 *   minorVersion = 1
 * )
 */
class Comments__1_1 extends ResourceEntity implements ResourceInterface {

  /**
   * {@inheritdoc}
   */
  protected function publicFields() {
    $public_fields = parent::publicFields();

    $public_fields['nid'] = array(
      'property' => 'node',
      'sub_property' => 'nid',
    );

    // Add a custom field for test only.

      $public_fields['comment_text'] = array(
        'property' => 'body',
        'sub_property' => 'value',
      );

    return $public_fields;
  }

  /**
   * {@inheritdoc}
   */
  protected function dataProviderClassName() {
    return DataProviderCommentNew::class;
  }

}

This is the body I am sending to POST request:

{
  "nid" : "38565",
  "comment_text" :  "this is comment from API"
}

And here is the error I am getting :

{
    "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4",
    "title": "You do not have access to create a new resource.",
    "status": 403,
    "detail": "Forbidden"
}

As you can see above error clearly shows that I do not have access to create new resource. So I have crossed check the permissions and everything seems fine with the commenting permission. Not sure what is happening or what is wrong with the API. Please help me on this. It would really be appreciated. Thank you in advance.

Kind regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant