You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
This is the body I am sending to POST request:
And here is the error I am getting :
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
The text was updated successfully, but these errors were encountered: