# Send E-Invoice via Email

You can use this API to send E-Invoices to your customers via the Email.

### Request Method

POST

### Request URL

```
{{BASE_URL}}/v1/emails
```

{% hint style="info" %}
Replace the `{{BASE_URL}}` with the one mentioned [here](https://docs.cleartax.in/cleartax-docs/e-invoicing-ksa-api/e-invoicing-ksa-api-reference) based on whether you are using sandbox or production.
{% endhint %}

{% hint style="danger" %}
Rate Limit : 10 API requests per minute
{% endhint %}

### Request Headers

| Parameter             | Data Type | Field Validations                              | Description                                                                                                  |
| --------------------- | --------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| x-cleartax-auth-token | String    | Cannot be empty                                | Mandatory. User auth token.                                                                                  |
| VAT                   | String    | Cannot be empty                                | Mandatory. VAT or Group VAT of the entity.                                                                   |
| branch                | String    | Should be a valid branch from the user account | Optional. Branch name (store name) added in the user account which maps to a VAT or Group VAT of the entity. |

### Request Path Params

There are no path params for this API.&#x20;

### Request Query Params

There are no query params for this API.&#x20;

### Request Body

| Parameter      | Data Type | Field Validations | Description                                                                |
| -------------- | --------- | ----------------- | -------------------------------------------------------------------------- |
| Attachments    | Object    | Cannot be null    | Mandatory. Attachment Details Object.                                      |
| PreviewDetails | Object    | Cannot be null    | Mandatory, Communication Details like Template Type and Email Information. |

#### Attachment Details Object

| Parameter       | Data Type     | Field Validations           | Description                                                                                                      |
| --------------- | ------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| documentDetails | List\<Object> |                             | Mandatory, Invoice Details for which e-Invoice is to be sent in attachments.                                     |
| printTemplateId | String        |                             | Mandatory. Template id of the e-Invoice template that has to be sent. e.g., :- “39” (Standard Invoice Template). |
| documentType    | String        | <p>Enum:</p><p>EINVOICE</p> | Mandatory. Type of document that needs to be printed.                                                            |

Document Details Object

| Parameter     | Data Type | Field Validations              | Description                                                    |
| ------------- | --------- | ------------------------------ | -------------------------------------------------------------- |
| InvoiceNumber | String    |                                | Mandatory. Invoice Number (Invoice Reference Number).          |
| IssueDate     | String    | YYYY-MM-DD                     | Mandatory                                                      |
| InvoiceType   | String    | <p>Enum:</p><p>INV,CRN,DBN</p> | Mandatory. INV - Invoice, CRN - Credit Note, DBN - Debit Note. |
| Seller VAT    | String    |                                | Mandatory, This VAT should match with the header VAT.          |

#### Preview Details Object

| Parameter           | Data Type     | Field Validations | Description                  |
| ------------------- | ------------- | ----------------- | ---------------------------- |
| EmailTemplate       | Object        | Can not be null.  | Mandatory, Subject in email. |
| CounterPartyDetails | List\<Object> | Can not be null.  | Mandatory.                   |

Email Template Object

| Parameter | Data Type | Field Validations                                    | Description |
| --------- | --------- | ---------------------------------------------------- | ----------- |
| Type      | String    | Enum: INVOICE\_GENERATED, INVOICE\_PAYMENT\_REMINDER |             |

Counterparty Details Object

| Parameter      | Data Type     | Field Validations | Description                                                                       |
| -------------- | ------------- | ----------------- | --------------------------------------------------------------------------------- |
| ContactDetails | List\<Object> | Can not be Null   | Mandatory, Email Recipients - You can send multiple recipients for sending email. |

Contact Details Object

| Parameter          | Data Type | Field Validations | Description |
| ------------------ | --------- | ----------------- | ----------- |
| Email              | String    |                   |             |
| EmailRecipientType | String    | Enum: TO, CC, BCC | Mandatory.  |

### Sample Request

```json
{
   "Attachments": {
       "documentDetails": [
     {
       "IssueDate": "2022-07-20",
       "InvoiceNumber": "2056",
       "InvoiceType": "INV",
       "Vat": "300492946900003"
     }
   ],
       "documentType": "EINVOICE",
       "printTemplateId": "40"
   },
   "PreviewDetails": {
   "Template": {
           "Type": "INVOICE_GENERATED"
       },
       "CounterParties": [
           {
               "Contacts": [
                   {
                       "Email": "dharmendra.maurya@cleartax.in",
                       "EmailRecipientType": "TO"
                   }
               ]
           }
       ]
       
   }
}
```

### Response Status Codes

<table><thead><tr><th width="190">HTTP Status Code</th><th>Description</th></tr></thead><tbody><tr><td>200</td><td>For a successful retrieval, if Invoice is not present, validation errors.</td></tr><tr><td>401</td><td>If the user is not authenticated for the operation.</td></tr><tr><td>403</td><td>If the user is not authorized for the operation.</td></tr><tr><td>429</td><td>Too many requests</td></tr><tr><td>5XX</td><td>Unhandled exception.</td></tr></tbody></table>

### Sample Response (Success)

Success - HTTP Status Code - 200

### Sample Response (Error)

HTTP Status Code - 200

Response Body

```json
{
   "ErrorList": [
       {
           "ErrorCode": "6002",
           "ErrorMessage": "Document Number cannot be empty",
           "ErrorSource": "CLEARTAX",
           "Path": "attachments.documentDetails[0].documentNumber"
       }
   ]
}
```

### API Validations

1. All documents given should be present in CT system.
2. printTemplateId should be present in CT system.

### API Constraints

1. All documents given should be in generated or failed state e.g., “CT QR Code status = GENERATED”.
2. Each customer is allowed to send a limited number of requests per minute to prevent server overload. If the limit is exceeded, the server will respond with a 429 Too Many Requests status code.
