Submitting contact forms

Prerequisites

  1. 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.

  2. 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

  1. Make sure you set the Content-Type HTTP header in your REST POST request correctly (to application/json or application/hal+json).
  2. Make sure you set the X-CSRF-Token HTTP header in your REST POST request correctly (see Securing your REST requests).
  3. Create your JSON body to submit the form (see below).
  4. 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:

  1. Go to the contact forms overview page (Manage > Structure > Contact forms).
  2. Next to the relevant form, find "REST API documentation" in the dropdown.

results matching ""

    No results matching ""