# Validate and review data

Source: https://developer.avalara.com/products/returns/integration-guides/managed-returns-emea/cgh2635537924537/

Guide: Avalara Managed Returns API (EMEA)

# Validate and review data

Validate imported VAT data and review invoice-level results before generating drafts.

Use this query to retrieve validation and data preparation results for imported VAT data.

Call this query after the data import status is complete to review invoice-level validation results.

## Retrieve validation and data preparation results

Use the following query to retrieve data preparation results.

**View request:**

```
query VatDataPrepResults($dataTraceId: String!) { vatDataPrepResults(dataTraceId: $dataTraceId) { dataPrepResults { ids { type value } properties { invoiceNumber } results { errorMessage name severity scopes } } errors { extensions { type code status } message } } }
```

Note

-   Returns invoice-level validation results for the uploaded data file
-   Each entry in `dataPrepResults` represents a single document, such as an invoice
-   Each document is identified using ids and `properties.invoiceNumber`
-   The results field contains validation outcomes, including errors and warnings
-   severity and scopes can be used to show detailed validation messages in your UI

Validation results example:

-   INV0001 – PASS
-   INV0002 – PASS
-   INV0003 – FAIL
-   INV0004 – FAIL

## Generate return drafts

Generate VAT return drafts for a return period and monitor the draft generation process.

Use the following mutation to start draft generation for a return period.

**View request:**

```
mutation VatStartDraftGeneration($input: StartDraftGenerationInput!) {
  vatStartDraftGeneration(input: $input) {
    id
  }
}
```

**Variables example:**

```
{
  "input": {
    "returnPeriodId": 67890,
    "dataTraceId": ""
  }
}
```

The request returns an id that is used to track the draft generation process.

## Check draft generation status

Use the following query to monitor the draft generation process.

**View request:**

```
query VatDraftGenerationStatus($dataTraceId: String!) {
  vatDraftGenerationStatus(dataTraceId: $dataTraceId) {
    id
    status
    currentStep
    steps
    description
  }
}
```

Poll this query until the status is Complete or a terminal error state is returned.

Note

-   Draft generation creates return artifacts for the specified Return period
-   Artifacts can include JSON eFile payloads, PDF reports, and reconciliation outputs
-   Draft generation is typically triggered after data validation is complete
-   The id returned from the mutation is used as the `dataTraceId` for status tracking

## Retrieve return drafts

Retrieve the generated draft files for a return period after draft generation is complete.

Use the following query to retrieve return draft files.

**View request:**

```
query VatReturnDrafts($returnPeriodId: Int!) {
  vatReturnDrafts(returnPeriodId: $returnPeriodId) {
    id
    fileName
    mimeType
    contentBase64
    dateCreated
    fileSize
  }
}
```

Note

-   Returns draft artifacts for the specified Return period
-   Draft artifacts can include JSON eFile payloads, PDF summary reports, and CSV reconciliation files
-   `contentBase64` contains the file content encoded as Base64
-   You can decode the file content and store or present the files in your system

**Usage guidelines:**

-   Generated draft files are used for review, approval, and downstream filing and reconciliation workflows
-   File names and file contents can be used to verify that the expected draft artifacts were generated