Drupal 8 webform rest api | Drupal 8 webform remote post example | Drupal 9 webform rest api with example

Dear Friends, As we know that Drupal as a headless technology booming right now, so we have lots of things to do.

In this article we are going to learn, How to submit webform data using rest api with an example.

Also, Read

Let’s Start step by step

Step 1: Download Webform and Webform Rest module

You can download directly from Drupal.org

  • Webform Module Download from Drupal.org
  • Webform Rest Module Download from Drupal.org

Note: If you have downloaded it from drupal.org then place it in proper path inside /web/module/contrib/

You can download using composer

lando composer require drupal/webform 
Download Drupal 9 Webform Module
Download Drupal 9 Webform Module
lando composer require drupal/webform_rest 
Download Drupal 9 Webform  Rest Module
Download Drupal 9 Webform Rest Module

Step 2: Install Webform, Webform UI and Webform Rest Module

You can install using your Drupal UI

Go to Main Navigation -> Extends and search here for your module and click on install.

Install module using Drupal UI
Install module using Drupal UI

You can install using Drush

lando drush en webform webform_ui webform_rest

Note: if composer ask for, enabled more module then type Yes and hit enter.

Step 3: Make sure you have installed & Enable Rest UI module, Or download and install from here

Step 4: Go to Main Navigation -> Configuration -> Web Services -> Rest

Enable Webform Rest API
Enable Webform Rest API

Step 5: Search for /webform_rest/submit and click on Enable to enable this API.

Search for /webform_rest/submit and click on Enable
Search for /webform_rest/submit and click on Enable

Step 6: Configure the API as below screenshot and click on Save configuration.

Step 7: Go to Structure and Click on Webform

Add Webform in Drupal 9
Add Webform in Drupal 9

Step 8: Click on Add Webform to add form.

Add Webform
Add Webform

Step 9: Choose field and field type and add field to the form.

Select field for form

Step 10: Configure the field type save + element to add more field in this form.

Webform Field Configuration
Webform Field Configuration

Step 11: Now you go to postman and prepare json data as per screenshot attached and configure below things.

  • Provide endpoint : /webform_rest/submit
  • Choose Method : POST
  • Type: Basci Auth
  • Provide your Drupal administrator credential.
Authorization Setup for Webform Rest API
Authorization Setup for Webform Rest API

Step 12: Click on Headers and provide below data.

  • Header: Content-Type : application/json
Header Setup for Webform Rest API
Header Setup for Webform Rest API

Step 13: Click on Postman Body And Prepare Your Data in Json Format.

Prepare webform field data in json format
Prepare webform field data in json format
{
  "webform_id": "contact_us",
  "name": "Pradip Mehta",
  "mobile_number": "9716442211",
  "email_id": "pradipmehta10@gmail.com"
}

Note: You have done successfully, after success, this api will return SID in response.

Result after submitted data using Webform Rest API via postman
Result after submitted data using Webform Rest API via postman

Let me know using contact us page, if you are facing any challenges.

Pradip Mehta

I am a well-organized professional in Drupal Development and PHP web development with strong script handling knowledge or automation process with PHP. I have advanced computer skills and am a proficient multitasker.