# (Deprecated) Ingest Documents via JSON

<mark style="color:red;">**This API is deprecated and no more supported due to scaling issues.**</mark>

Upload a sale or purchase document with JSON payload.

{% hint style="warning" %}
A maximum of 100 invoice line item objects can be ingested in one request.
{% endhint %}

### Request Method

POST

### Request URL

```
{{BASE_URL}}/integration/v2/ingest/json/{{templateType}}
```

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

### Request Headers

<table><thead><tr><th width="183">Parameter</th><th width="129">Data Type</th><th>Field Validations</th><th>Description</th></tr></thead><tbody><tr><td>x-cleartax-auth-token</td><td>String</td><td>Cannot be empty.</td><td>Mandatory. <a href="../../learn-clear-finance-cloud-basics/access-token">User auth token</a>.</td></tr><tr><td>x-cleartax-gstin</td><td>String</td><td>Cannot be empty</td><td>Mandatory. GSTIN of the taxpayer registered on CFC.</td></tr><tr><td>Content-Type</td><td>String</td><td></td><td>application/json</td></tr></tbody></table>

### Request Path Params

| Parameter    | Data Type | Field Validations                         | Description                                                                                |
| ------------ | --------- | ----------------------------------------- | ------------------------------------------------------------------------------------------ |
| templateType | String    | <p>Enum: </p><p>sales,</p><p>purchase</p> | <p>Type of document. sales - Sales document.</p><p>purchase- Purchase document.</p><p></p> |

### Request Query Params

There are no query parameters for this API.

### Request Body

<table><thead><tr><th width="182">Parameter</th><th width="112.88562596599695">Data Type</th><th width="123">Field Validation</th><th>Description</th></tr></thead><tbody><tr><td>userInputArgs</td><td>Object</td><td>NA</td><td>Mandatory. <a href="#user-input-arguments-object">User Input Arguments Object</a>.</td></tr><tr><td>jsonRecords</td><td>Array</td><td>MaxLength: 100</td><td>Mandatory. An array of <a href="../resources-and-masters/sale-document-line-object">Sale Document Line Objects</a> or <a href="../resources-and-masters/purchase-document-line-object">Purchase Document Line Objects</a> based on <code>templateType</code> used in the path param.</td></tr></tbody></table>

#### User Input Arguments Object

<table><thead><tr><th width="163">Parameter</th><th width="129.88562596599695">Data Type</th><th width="130">Field Validation</th><th>Description</th></tr></thead><tbody><tr><td>templateId</td><td>String</td><td>NA</td><td>Mandatory. For a sale document, the system template ID is "618a5623836651c01c1498ad". For a purchase document, the system template ID is "60e5613ff71f4a7aeca4336b". For custom upload templates, use <a href="../../learn-clear-finance-cloud-basics/how-to-get-custom-upload-template-id">the custom upload template ID</a>.</td></tr><tr><td>groupId</td><td>String</td><td>NA</td><td><p>Unique ID across the PAN to group a set of documents as a single record on the Clear Import History page.</p><p>Default: Autogenerated random ID.</p></td></tr><tr><td>settings</td><td>Object</td><td>NA</td><td>Optional. <a href="#settings-object">Settings Object</a>.</td></tr></tbody></table>

#### Settings Object

<table><thead><tr><th width="163">Parameter</th><th width="129.88562596599695">Data Type</th><th width="130">Field Validation</th><th>Description</th></tr></thead><tbody><tr><td>ignoreHsnValidation</td><td>Boolean</td><td>NA</td><td><p>Optional. Indicates if HSN validation has to be ignored or not. </p><p>true - HSN validation error will be ignored.</p><p>false - HSN validation error will not be ignored.<br>Default: false</p></td></tr></tbody></table>

### Sample Request

#### Sales document

{% code lineNumbers="true" %}

```json
{
    "userInputArgs": {
        "templateId": "618a5623836651c01c1498ad", 
        "groupId": "TEST123",
        "settings": {
            "ignoreHsnValidation": true
        }
    }, 
    "jsonRecords": [
        {
            "documentType": "Invoice", 
            "documentDate": "2022-11-29", 
            "documentNumber": "Inv-123", 
            
            "erpSource": "Tally", 
            "voucherNumber": "Inv-123", 
            "voucherDate": "2022-11-29", 
            
            "isBillOfSupply": "N", 
            "isReverseCharge": "N", 
            "isDocumentCancelled": "N", 

            "supplierName": "Defmacro Software Private Limited", 
            "supplierGstin": "29AAFCD5862R1ZR", 

            "customerName": "Clearsharp Technology Private Limited", 
            "customerAddress": "Cust1 Mst Addr1, Cust1 Mst Addr2, Cust1 Mst Addr3", 
            "customerState": "Karnataka", 
            "customerGstin": "29AAECC3822D1ZY", 
            "placeOfSupply": "Karnataka", 

            "itemDescription": "Item1", 
            "itemCategory": "G", 
            "hsnSacCode": "48", 
            "itemQuantity": 500, 
            "itemUnitCode": "PCS", 
            "itemUnitPrice": 250, 
            "itemDiscount": 0, 
            "itemTaxableAmount": 125000, 
            "cgstRate": 9, 
            "cgstAmount": 11250, 
            "sgstRate": 9, 
            "sgstAmount": 11250, 
            "igstRate": 0, 
            "igstAmount": 0, 
            "cessRate": 0, 
            "cessAmount": 0, 

            "documentTotalAmount": 147500
        }
    ]
}
```

{% endcode %}

#### Purchase document

{% code lineNumbers="true" %}

```json
{
    "userInputArgs": {
        "templateId": "60e5613ff71f4a7aeca4336b", 
        "settings": {
            "ignoreHsnValidation": true
        }
    }, 
    "jsonRecords": [
        {
            "documentType": "Invoice", 
            "documentDate": "2022-11-29", 
            "documentNumber": "Inv-123", 
            
            "erpSource": "Tally", 
            "voucherNumber": "Inv-123", 
            "voucherDate": "2022-11-29", 
            
            "isBillOfSupply": "N", 
            "isReverseCharge": "N", 
            "isDocumentCancelled": "N", 

            "supplierGstin": "29AAECC3822D1ZY", 
            "supplierName": "Clearsharp Technology Private Limited", 
            "supplierAddress": "Cust1 Mst Addr1, Cust1 Mst Addr2, Cust1 Mst Addr3", 
            "supplierState": "Karnataka", 
            
            "customerGstin": "29AAFCD5862R1ZR", 

            "placeOfSupply": "Karnataka", 

            "itemDescription": "Item1", 
            "itemCategory": "G", 
            "hsnSacCode": "48", 
            "itemQuantity": 500, 
            "itemUnitCode": "PCS", 
            "itemUnitPrice": 250, 
            "itemDiscount": 0, 
            "itemTaxableAmount": 125000, 
            "cgstRate": 9, 
            "cgstAmount": 11250, 
            "sgstRate": 9, 
            "sgstAmount": 11250, 
            "igstRate": 0, 
            "igstAmount": 0, 
            "cessRate": 0, 
            "cessAmount": 0, 

            "documentTotalAmount": 147500
        }
    ]
}
```

{% endcode %}

### Response Status Codes

<table><thead><tr><th width="192">HTTP Status Code</th><th>Description</th></tr></thead><tbody><tr><td>200</td><td>For a successfully processed request (may be a success or validation error).</td></tr><tr><td>400</td><td>If the request schema is not valid.</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>500</td><td>If there are any unhandled exceptions on Clear side.</td></tr></tbody></table>

### Response Schema

<table><thead><tr><th width="184">Parameter</th><th width="113">Data Type</th><th width="97">Field Constraints</th><th>Description</th></tr></thead><tbody><tr><td>gstinStats</td><td>Array</td><td>NA</td><td>Upload statistics aggregated at the GSTIN level. An array of <a href="#gstin-stats-object">GSTIN stats object</a>. In case of non-validation errors, this will be an empty Array ([]).</td></tr><tr><td>jsonRecordErrors</td><td>Array</td><td>NA</td><td>Validation Errors. An array of <a href="#json-record-error-details-object">JSON record error details objects</a>. In case there are no errors, this will be an empty Array ([]).</td></tr><tr><td>errors</td><td>Array</td><td>NA</td><td>Non-Validation Errors. An array of <a href="#non-validation-error-details-object">non-validation error details objects</a>. In case there are no errors, this will be an empty Array ([]).</td></tr></tbody></table>

#### GSTIN Stats Object

<table><thead><tr><th width="184">Parameter</th><th width="113">Data Type</th><th width="106">Field Constraints</th><th>Description</th></tr></thead><tbody><tr><td>gstin</td><td>String</td><td>NA</td><td>Seller GSTIN that these stats belong to.</td></tr><tr><td>totalDocumentCount</td><td>Number</td><td>NA</td><td>Total count of documents parsed successfully.</td></tr><tr><td>validRows</td><td>Number</td><td>NA</td><td>Total count of valid document line objects.</td></tr><tr><td>invalidRows</td><td>Number</td><td>NA</td><td>Total count of invalid document line objects.</td></tr></tbody></table>

#### JSON Record Error Details Object

<table><thead><tr><th width="184">Parameter</th><th width="113">Data Type</th><th width="130">Field Constraints</th><th>Description</th></tr></thead><tbody><tr><td>recordIndex</td><td>Number</td><td>NA</td><td>Array index of the record in request jsonRecords. The index starts from 0.</td></tr><tr><td>recordErrors</td><td>Array</td><td>NA</td><td>Array of <a href="#record-error-details-object">record error details objects</a>.</td></tr><tr><td>externalId</td><td>String</td><td>NA</td><td>External ID that was sent in the request to identify the document, if any. In case an external ID was not sent, this field will not exist.</td></tr><tr><td>externalLineItemId</td><td>String</td><td>NA</td><td>External ID that was sent in the request to identify the document line item, if any. In case an external ID was not sent, this field will not exist.</td></tr></tbody></table>

#### Record Error Details Object

<table><thead><tr><th width="184">Parameter</th><th width="113">Data Type</th><th width="130">Field Constraints</th><th>Description</th></tr></thead><tbody><tr><td>errorId</td><td>String</td><td>NA</td><td>Error ID</td></tr><tr><td>columnName</td><td>Array</td><td>NA</td><td>Array of strings representing field keys in the jsonRecords of the request that has an error.</td></tr><tr><td>errorMessage</td><td>String</td><td>NA</td><td>User friendly error message.</td></tr></tbody></table>

#### Non-Validation Error Details Object

<table><thead><tr><th width="173">Parameter</th><th width="113">Data Type</th><th width="130">Field Constraints</th><th>Description</th></tr></thead><tbody><tr><td>errorCode</td><td>String</td><td>NA</td><td>Error code</td></tr><tr><td>errorMessage</td><td>String</td><td>NA</td><td>Error message.</td></tr><tr><td>errorField</td><td></td><td>NA</td><td>Error field.</td></tr><tr><td>errorValues</td><td></td><td>NA</td><td>Error values.</td></tr><tr><td>errorResolution</td><td></td><td>NA</td><td>Error resolution.</td></tr></tbody></table>

### Sample Response

Success - HTTP Status Code - 200

{% code lineNumbers="true" %}

```json
{
  "gstinStats": [
    {
      "gstin": "29AAFCD5862R1ZR",
      "totalDocumentCount": 1,
      "validRows": 1,
      "invalidRows": 0
    }
  ],
  "jsonRecordErrors": [...],
  "errors": null
}
```

{% endcode %}

Validation Error - HTTP Status Code - 200

{% code lineNumbers="true" %}

```json
{
  "gstinStats": [
    {
      "gstin": "29AAFCD5862R1ZR",
      "totalDocumentCount": 0,
      "validRows": 0,
      "invalidRows": 1
    }
  ],
  "jsonRecordErrors": [
    {
      "recordIndex": 0,
      "externalId": "INVOICE_maxitc123_06ADECO9084R5Z4_29AAFCD5862R000_2022_0",
      "externalLineItemId": "INVOICE_maxitc123_06ADECO9084R5Z4_29AAFCD5862R000_2022_0",
      "recordErrors": [
        {
          "errorId": "HSN_OR_SAC_TYPE_ERROR",
          "columnName": ["hsnSacCode"],
          "errorMessage": "1234 is not a valid HSN "
        }
      ]
    }
  ],
  "errors": null
}
```

{% endcode %}

Non-Validation Error - HTTP Status Code - 401

{% code lineNumbers="true" %}

```json
{
  "gstinStats": [],
  "jsonRecordErrors": [],
  "errors": [
    {
      "errorCode": "AUTHORIZATION_FAILED",
      "errorMessage": "Invalid Auth Token",
      "errorField": null,
      "errorValues": null,
      "errorResolution": null
    }
  ]
}
```

{% endcode %}

Non-Validation Error - HTTP Status Code - 500

{% code lineNumbers="true" %}

```json
{
  "gstinStats": [],
  "jsonRecordErrors": [],
  "errors": [
    {
      "errorCode": "INTERNAL_ERROR",
      "errorMessage": "Internal Service Error",
      "errorField": null,
      "errorValues": null,
      "errorResolution": null
    }
  ]
}
```

{% endcode %}

### API Validations

There are more than 200 field validations as well as business validations on the Clear API side. For data validation errors, the validation error message will be sent back in the \`jsonRecordErrors\` field in the response.

### API Constraints

1. This API needs to be authenticated with a valid user authentication token. If the auth token is not present or is invalid, the API will return HTTP Status Code 401.
2. If the auth token is valid, but the user does not have the authorization, then the API will return HTTP Status Code 403. The user, whose auth token is used, should have permission to create a document.

{% hint style="info" %}

#### Integrating for MaxITC?

If you are integrating with Max ITC, once the documents are uploaded, trigger the reconciliation using the [Trigger MaxITC Workflow API](https://docs.cleartax.in/cleartax-docs/max-itc-api/max-itc-api-reference/max-itc-apis/trigger-max-itc-workflow).
{% endhint %}
