# Case filing documents tutorial
source: https://developer.mastercard.com/mastercom-extended/documentation/tutorials-and-guides/casefilingdocuments-tutorial/index.md

## Overview {#overview}

This tutorial will show you the process of senders and receivers managing documents for pre-arbitration, arbitration, pre-compliance or compliance cases.

#### What you will learn {#what-you-will-learn}

> * How to retrieve processed documents associated with cases
> * How to attach a new document to a case after a document failed to process
> * How to retrieve statuses for documents associated with cases

## Before you start {#before-you-start}

Before starting this tutorial, ensure that you have already completed the following:

* [Mastercom Extended API Client Generation Tutorial](https://developer.mastercard.com/mastercom-extended/documentation/tutorials-and-guides/clientgeneration-tutorial/index.md)
* [Quick Start Guide](https://developer.mastercard.com/mastercom-extended/documentation/quick-start-guide/index.md)

## Step 1: Retrieve processed documents associated with cases {#step-1-retrieve-processed-documents-associated-with-cases}

The sender or receiver retrieves all documents from a case, whether attached by the sender or receiver.

API Reference: `GET /cases/{case_id}/documents`

To retrieve all documents from a case, create a `CaseFilingDocumentsApi` object. Then use method `caseFilingDocumentsApi.retrieveCaseDocuments`.

This method expects the `caseId` and the desired document format to be provided.

```java
public class Main {
  public static void main(String[] args) {
    // API client set up here...    
    CaseFilingDocumentsApi caseFilingDocumentsApi = new CaseFilingDocumentsApi(BaseClassUtil.getClient());
    try {
      DocumentRetrieve result = caseFilingDocumentsApi.retrieveCaseDocuments("5415063", "ORIGINAL");
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling CaseFilingDocumentsApi#retrieveCaseDocuments");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Review the possible error codes associated with this request {#review-the-possible-error-codes-associated-with-this-request}

| HTTP Code |      Error      |                     Error Description                      | Error Code |
|-----------|-----------------|------------------------------------------------------------|------------|
| 400       | INVALID_REQUEST | Invalid `caseId` or User have not Provisioned              | 200001     |
| 400       | INVALID_REQUEST | `caseId` is invalid                                        | 200001     |
| 400       | INVALID_REQUEST | Document is not available in System for requested `caseId` | 200001     |

Review additional error codes [here](https://developer.mastercard.com/mastercom-extended/documentation/code-and-formats/errorsandexceptions/index.md).

#### Verify response {#verify-response}

You should receive a 200 OK response. Returns `fileName` and `file`.

## Step 2: Attach a new document to a case after a document failed to process {#step-2-attach-a-new-document-to-a-case-after-a-document-failed-to-process}

The sender or receiver attaches a new document to an existing case when the previous document failed to process. Document processing status can be retrieved from [Step 3](https://developer.mastercard.com/mastercom-extended/documentation/tutorials-and-guides/casefilingdocuments-tutorial/index.md) leveraging `GET /cases/documents/attributes`.

API Reference: `PUT /cases/{case_id}/documents`

To attach a new document to an existing case when the previous document failed to process, create a `CaseFilingDocumentsApi` object. Then use method `caseFilingDocumentsApi.retryDocumentUpload`.

This method expects a `caseId` and a request body to be provided. The request body is an instantiation of the `CaseTakeActionDocumentRetry` object.

This method does not have any response body.

```java
public class Main {
  public static void main(String[] args) {
    // API client set up here...    
    CaseFilingDocumentsApi caseFilingDocumentsApi = new CaseFilingDocumentsApi(BaseClassUtil.getClient());
    
    CaseTakeActionDocumentRetry body = new CaseTakeActionDocumentRetry();
    body.setDocumentMemo("Cardholder letter.");
    body.setDocumentUploadedId("e59c3a2a9f4311ee8855eeee0afc63f1");
    body.setRebuttalParty(CaseTakeActionDocumentRetry.RebuttalPartyEnum.SENDER);
    try {
      caseFilingDocumentsApi.retryDocumentUpload("5415063", body);
    } catch (ApiException e) {
      System.err.println("Exception when calling CaseFilingDocumentsApi#retryDocumentUpload");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Review the possible error codes associated with this request {#review-the-possible-error-codes-associated-with-this-request-1}

| HTTP Code |        Error        |               Error Description               | Error Code | Action Type |
|-----------|---------------------|-----------------------------------------------|------------|-------------|
| 400       | INVALID_REQUEST     | Invalid `caseId` or User have not Provisioned | 200001     | Doc Retry   |
| 400       | INVALID_REQUEST     | Document is not required for given Case       | 200001     | Doc Retry   |
| 400       | INVALID_INPUT_VALUE | Invalid input value for field `action`        | 230000     | Doc Retry   |

Review additional error codes [here](https://developer.mastercard.com/mastercom-extended/documentation/code-and-formats/errorsandexceptions/index.md).

#### Verify response {#verify-response-1}

You should receive a 204 Success- No Content response.

## Step 3: Retrieve statuses for documents associated with cases {#step-3-retrieve-statuses-for-documents-associated-with-cases}

The sender or receiver retrieves the processing status of documents associated with cases.

API Reference: `GET /cases/documents/attributes`

To retrieve the processing status of documents associated with cases, create a `CaseFilingDocumentsApi` object. Then use method `caseFilingDocumentsApi.obtainCasesDocumentAttributes`.

This method expects a query parameter containing a list of `caseIds`.

This method does not expect any request body.

```java
public class Main {
  public static void main(String[] args) {
    // API client set up here...    
    CaseFilingDocumentsApi caseFilingDocumentsApi = new CaseFilingDocumentsApi(BaseClassUtil.getClient());
    
    List<String> caseIds = new ArrayList<>();
    caseIds.add("543421");
    try {
      CasesDocumentAttributes result = caseFilingDocumentsApi.obtainCasesDocumentAttributes(caseIds);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling CaseFilingDocumentsApi#obtainCasesDocumentAttributes");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Review the possible error codes associated with this request {#review-the-possible-error-codes-associated-with-this-request-2}

| HTTP Code |       Error Code       |    Description     |
|-----------|------------------------|--------------------|
| 400       | BAD_REQUEST            | Bad request        |
| 401       | NOT_AUTHORIZED_REQUEST | Unauthorized       |
| 403       | FORBIDDEN              | Forbidden          |
| 404       | RESOURCE_UNKNOWN       | Resource not found |

Review additional error codes [here](https://developer.mastercard.com/mastercom-extended/documentation/code-and-formats/errorsandexceptions/index.md).

#### Verify response {#verify-response-2}

You should receive a 200 OK response. Returns `caseId` and `documentStatus`.

Return to [Tutorials](https://developer.mastercard.com/mastercom-extended/documentation/tutorials-and-guides/index.md).
