> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mailpigeon.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Submit

> This endpoint submits validates and saves your form submissions.  Assuming you have a form set up with the fields - ```name```, ```email```, ```phone```, ```enquiry``` and ```message```, you would send a POST request to this endpoint with the following body 

### Body

<ParamField body="name" type="string">
  This can be used in any context you like.
</ParamField>

<ParamField body="email" type="string">
  This can be used in any context you like.
</ParamField>

<ParamField body="phone" type="integer">
  This can be used in any context you like.
</ParamField>

<ParamField body="enquiry" type="boolean">
  This can be used in any context you like.
</ParamField>

<ParamField body="message" type="string">
  This can be used in any context you like.
</ParamField>

### Response

<ResponseField name="data" type="object">
  Contains the status of the call and the error message if any.

  <Expandable title="Toggle object">
    <ResponseField name="message" type="string">
      This is the message that will denote the success or failure of the call.
    </ResponseField>

    <ResponseField name="error" type="string">
      This is the error message if any.

      <Expandable title="Toggle object">
        <ResponseField name="message" type="string">
          This is the error message if any.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="status" type="object">
  Contains the status of the call and the HTTP status code.

  <Expandable title="Toggle object">
    <ResponseField name="code" type="integer">
      This is the HTTP status code.
    </ResponseField>

    <ResponseField name="message" type="string">
      This is the message that will denote the success or failure of the call.
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```javascript Javascript Request
  var myHeaders = new Headers();
  myHeaders.append("Content-Type", "application/json");

  var raw = JSON.stringify({
    name: "John Doe",
    email: "name@company.com",
    phone: 1234567890,
    enquiry: true,
    message: "This is a test message",
  });

  var requestOptions = {
    method: "POST",
    headers: myHeaders,
    body: raw,
    redirect: "follow",
  };

  fetch("https://api.mailpigeon.app/api/v1/submit", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.log("error", error));
  ```

  ```bash Bash Request
  curl --location --request POST 'https://api.mailpigeon.app/api/v1/submit' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer <apikey>' \
  --data-raw '{
      "name": "John Doe",
      "email": "name@company.com",
      "phone": 1234567890,
      "enquiry": true,
      "message": "This is a test message"
  }'
  ```

  ```python Python Request
  import requests
  import json

  url = "https://api.mailpigeon.app/api/v1/submit"

  payload = json.dumps({
    "name": "John Doe",
    "email": "name@company.com",
    "phone": 1234567890,
    "enquiry": true,
    "message": "This is a test message"
  })
  headers = {
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```

  ```php PHP Request
  <?php

  $curl = curl_init();

  curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://api.mailpigeon.app/api/v1/submit',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS =>'{
      "name": "John Doe",
      "email": "name@company.com",
      "phone": 1234567890,
      "enquiry": true,
      "message": "This is a test message"
  }',
    CURLOPT_HTTPHEADER => array(
      'Content-Type: application/json'
    ),
  ));

  $response = curl_exec($curl);

  curl_close($curl);
  echo $response;
  ```
</RequestExample>

<ResponseExample>
  ```json Success
  {
    "data": {
      "message": "Submission successful"
    },
    "status": {
      "code": 201,
      "message": "Created"
    }
  }
  ```

  ```json No form fields
  {
    "data": {
      "message": "Submission failed",
      "error": {
        "message": "No fields found for this project"
      }
    },
    "status": {
      "code": 400,
      "message": "Bad Request"
    }
  }
  ```

  ```json Invalid API Key
  {
    "data": {
      "message": "Submission failed",
      "error": {
        "message": "Invalid API Key"
      }
    },
    "status": {
      "code": 401,
      "message": "Unauthorized"
    }
  }
  ```

  ```json Invalid Types
  {
    "data": {
      "message": "Submission failed",
      "errors": ["Field 'email' is not of type string"]
    },
    "status": {
      "code": 400,
      "message": "Bad Request"
    }
  }
  ```
</ResponseExample>
