> For the complete documentation index, see [llms.txt](https://klearstack.gitbook.io/klearstack-api-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://klearstack.gitbook.io/klearstack-api-documentation/retry-failed-documents/retry-failed-documents.md).

# Retry Failed Documents

Endpoint Name: `retry_failed_documents`

Request type : `POST`

Authorization : None

Endpoint Details: The `retry_failed_documents` endpoint will be used to get the access token and the refresh token, The validity of the access token will be some minutes, and the refresh token will be days.

<table data-header-hidden><thead><tr><th width="109.6363525390625"></th><th></th></tr></thead><tbody><tr><td>Method</td><td>URL</td></tr><tr><td>POST</td><td><code>URL/access/klearstack/retry_failed_documents</code></td></tr></tbody></table>

### Request Body

<table data-header-hidden><thead><tr><th width="172.6363525390625"></th><th width="94"></th><th width="123.27276611328125"></th><th></th></tr></thead><tbody><tr><td>Parameters</td><td>Values</td><td>Required </td><td>Description</td></tr><tr><td>company_name</td><td>string</td><td>Yes</td><td>Name of the company for which the user is logging in.</td></tr><tr><td>batch_id</td><td>string</td><td>Yes</td><td>Batch id received from upload API</td></tr></tbody></table>

### Request Code Samples

#### Shell

* Request Body

```sh
curl --location "URL/access/klearstack/retry_failed_documents" \
  --form "company_name=Replace_Company_Name_Here" \
  --form "batch_id=Replace_batch_id_Here"
```

#### Python

* Request Body

```python
import requests

url = "URL/access/klearstack/retry_failed_documents"

payload = {'company_name': 'Replace_Company_Name_Here',
'batch_id': 'Replace_batch_id_Here'}
files=[

]
headers = {}

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

print(response.text)
```

#### Java (OkHttp)

* Request Body

```java
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
  .addFormDataPart("company_name","Replace_Company_Name_Here")
  .addFormDataPart("batch_id","Replace_batch_id_Here")
  .build();
Request request = new Request.Builder()
  .url("URL/access/klearstack/retry_failed_documents")
  .method("POST", body)
  .build();
Response response = client.newCall(request).execute();
```

#### Nodejs (Axios)

* Request Body

```typescript
const axios = require('axios');
const FormData = require('form-data');
let data = new FormData();
data.append('company_name', 'Replace_Company_Name_Here');
data.append('batch_id', 'Replace_batch_id_Here');

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'URL/access/klearstack/retry_failed_documents',
  headers: { 
    ...data.getHeaders()
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});
```

#### Javascript (XHR)

* Request Body

```javascript
// WARNING: For POST requests, body is set to null by browsers.
var data = new FormData();
data.append("company_name", "Replace_Company_Name_Here");
data.append("batch_id", "Replace_batch_id_Here");

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "URL/access/klearstack/retry_failed_documents");

xhr.send(data);
```

### API Response

<table data-header-hidden><thead><tr><th width="143"></th><th></th></tr></thead><tbody><tr><td>Status code</td><td>Example Response</td></tr><tr><td>200</td><td><code>{"success": True, "message": "Retry initiated successfully"}</code></td></tr><tr><td>500</td><td><code>{"success": False, "message": "Failed to initiate retry", "details": 'details'}</code></td></tr><tr><td>400</td><td><code>{"success": False, "message": "No batch found with the provided batch_id"}</code></td></tr><tr><td>400</td><td><code>{"success": False, "message": "Batch status is not 'failed'. Only failed batches can be retried."}</code></td></tr></tbody></table>
