1

Drupal 8 has a REST resource for all content type "Content" and let us to specified settings for all of content type in admin/config/services/rest/resource/entity%3Anode/edit ,but is globally, I mean if let users post data to Content type, they can Post data to all of content types and(But what I need is I don't let them to do this), I didn't find any option to restrict to specified content type. enter image description here

I also take a look at permission and RESTful Web Services permission is for "Access POST on Content resource" and there is not any option for content types individually. enter image description here

I want to know how can achieve this that REST POST feature exists for specified content type(s) and for some content type GET exists and for some content type REST not allowed?

Update(more deatils about what I want)
I want anonymous user can POST contenttype1 content with REST , I give permission to anonymous user to create contenttype1 content, and Authentication providerssection I checkcookieandbasic_auth` methods, but when try to post data with following code it told me authentication required (I ran this snippet in browser console )

(function($){

                    jQuery.ajax({
                        url: '/rest/session/token',
                        method: 'GET',
                        success: function (token, status, xhr) {
                            var postData = {}
                            postData.title = [{'value': 'My Basic Page'}];
                            postData.field_enroll_email = [{'value': 'zhilevan@gmail.com'}];
                            postData.type = 'enroll';
                            jQuery.ajax({
                                url: "/entity/node",
                                method: "POST",
                                data: JSON.stringify(postData),
                                headers: {"Accept": "application/json", "X-CSRF-Token": token, "Content-Type": "application/json"},
                                success: function (data, status, xhr) {
                                    console.log(data);
                                }
                            });
                        }
                    });
})(jQuery);
2

I mean if let users post data to Content type, they can Post data to all of my content types and I didn't find any option to restrict to specified content type.

Doesn't /admin/people/permissions stop them?

Permission

  • Basic page: Create new content
  • Article: Create new content

and for some content type GET exists

Don't you have to create a views rest export first before data is available to GET?

You can restrict here by adding a filter of type to your view.

  • Thanks for attention, But I think I didn't explain well and you misunderstand, when told POST I mean REST POST. – Yuseferi Jul 12 '16 at 13:56
  • @zhilevan I understood you correctly. Do user role permissions not apply to REST? Have you tested with a user that is not super admin (user/1) – No Sssweat Jul 12 '16 at 13:57
  • I didn't try but I dont want users can use content edit/create form, I only want they can create by REST ( only in mobile application and not in site). ( although it is not hard for me to prevent user access content edit/create form ( specified role(s) I mean). I try that and inform you. tnx for your note – Yuseferi Jul 12 '16 at 15:05
  • 1
    What you're asking now seems like a different question. You can definitely give create permission only for a specific type and then both REST and the UI will respect that. If you want to allow only REST then you will need to think of something else and e.g. alter the routes for the forms. – Berdir Jul 12 '16 at 19:19
  • @Berdir no,I asked a question, I want anonymous user can post data to contenttype1 with REST. – Yuseferi Jul 13 '16 at 6:38

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.