Submitting contact forms
Prerequisites
To be able to submit contact form submissions via the REST API, you will need to whitelist the IP address of the client application that is trying to submit these requests. See IP whitelisting for information on how to do so.
You need to have at least one contact form configured in your Narwhal CMS backend. See Managing contact forms for instructions on how to do so.
Submit contact form via REST
Instructions
- Make sure you set the
Content-Type
HTTP header in your RESTPOST
request correctly (toapplication/json
orapplication/hal+json
). - Make sure you set the
X-CSRF-Token
HTTP header in your RESTPOST
request correctly (see Securing your REST requests). - Create your JSON body to submit the form (see below).
- Perform call: e.g.
POST https://domainname.com/contact_message?_format=json
Contact form JSON body
The JSON body consists of a JSON object with 5 properties:
- contact_form: the machine name of the contact form you wish to submit.
- name: the name of the person submitting the contact message (usually provided by the visitor of your frontend app).
- mail: the email address of the person submitting the contact message (usually provided by the visitor of your frontend app).
- subject: the subject of the contact form message (value provided by your frontend app or provided by the visitor of your app).
- message: the message body of the contact form submission (usually provided by the visitor of your frontend app).
Example JSON body
{
"contact_form": "feedback",
"name": "John Doe",
"mail": "[email protected]",
"subject": "REST contact form subject",
"message": "Test message submitted by frontend application."
}
Extra documentation
You can find specific REST API documentation per contact form, by clicking the "REST API documentation" link:
- Go to the contact forms overview page (Manage > Structure > Contact forms).
- Next to the relevant form, find "REST API documentation" in the dropdown.