0

I am trying to use Drupal Webform REST. I got an error "The 'restful post webform_rest_submit' permission is required." on browser console. I have enabled modules and REST resources as mentioned. I used Authorization, the Auth generated in Postman, using basic auth. I am struggling to use 'x-csrf-token' in postman. I want to use submit the form by an anonymous user. Do I still need Authorization, will just token not work on same-origin?

const handleSubmit = async (e) => {
    e.preventDefault(); 

    await axios({
      method: 'GET',
      url: `${baseurl.URL}/session/token`,
      headers: {
        'Accept': 'application/vnd.api+json',
      }
    })
    .then(response =>  response)
    .then((token)=>{
      console.log("CSRF TODKEN", token.data);
      axios({
        method: 'post',
        url: `${baseurl.URL}/webform_rest/submit?_format=json`,
        headers:{
          'Accept': 'application/vnd.api+json',
          'Content-Type': 'application/json',
          'X-CSRF-Token': token.data,
          'Authorization':'Basic $S$EDSnVMXDICYbVGJ'
        },
        data: {
          "webform_id": "contact_form",
          "name":name,
          "email": email,
          "subject": subject,
          "message": message
        }
      })
    })
    .then(response => {
      console.log(response)
      response.status === 200 && console.log("Form successfully submitted")
    })
    .catch(err => console.log("SUBMIT FAIL ERROR ",err))```
Rdb
  • 59
  • 2
  • 12

1 Answers1

3

It worked. I gave permission to "Access POST on Webform Submit resource" to anonymous users.

Rdb
  • 59
  • 2
  • 12