Score:0

Drupal Webform REST

jp flag
Rdb

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 do 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))```
cn flag
Does the anonymous user have the `restful post webform_rest_submit permission`? All users, both anonymous and auth, need a CSRF token to submit webforms via REST.
jp flag
Rdb
Thank you very much, Patrick Kenny. It worked. I was missing permission to "Access POST on Webform Submit resource".
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.