> 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/auto-classification/upload-document-with-auto-classification-feature.md).

# Upload Document With Auto Classification Feature

Endpoint Name: `URL/access/klearstack/autoclassify`

Request type : `POST`

Authorization: Bearer token as header

Endpoint Details: The `autoclassify` endpoint will be used to update enable / disable fields or update the settings of fields.

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

### Request Body

<table data-header-hidden><thead><tr><th width="187"></th><th width="84"></th><th width="101.181884765625"></th><th></th></tr></thead><tbody><tr><td>Params</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>classification_type</td><td>string</td><td>Yes</td><td>"Page Classification" or "Document Classification" as value</td></tr><tr><td>file</td><td>binary</td><td>Yes</td><td>Single image (jpg/jpeg/png) or pdf file.</td></tr></tbody></table>

### Shell (cURL)

* Request Body

```sh
curl --location "URL/access/klearstack/autoclassify" \
  --header "Authorization: Bearer your_token_here" \
  --form "company_name=Replace_Company_Name_Here" \
  --form "classification_type=Replace_classification_type_Here" \
  --form "file=@\"C:/Users/user/Downloads/xyz.pdf\""
  
```

### Python

* Request Body

```python
import requests

url = "URL/access/klearstack/autoclassify"

payload = {'company_name': 'Replace_Company_Name_Here',
'classification_type': 'Replace_classification_type_Here'}
files=[
  ('file',('xyz.pdf',open('C:/Users/user/Downloads/xyz.pdf','rb'),'application/pdf'))
]
headers = {
  'Authorization': 'Bearer your_token_here'
  }

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("classification_type","Replace_classification_type_Here")
  .addFormDataPart("file","C:/Users/user/Downloads/xyz.pdf",
    RequestBody.create(MediaType.parse("application/octet-stream"),
    new File("C:/Users/user/Downloads/xyz.pdf")))
  .build();
Request request = new Request.Builder()
  .url("URL/access/klearstack/autoclassify")
  .method("POST", body)
  .addHeader("Authorization", "Bearer your_token_here")
  .build();
Response response = client.newCall(request).execute();
```

### Node.js (Axios)

* Request Body

```javascript
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
let data = new FormData();
data.append('company_name', 'Replace_Company_Name_Here');
data.append('classification_type', 'Replace_classification_type_Here');
data.append('file', fs.createReadStream('C:/Users/user/Downloads/xyz.pdf'));

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'URL/access/klearstack/autoclassify',
  headers: { 
    'Authorization': 'Bearer your_token_here', 
    ...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("classification_type", "Replace_classification_type_Here");
data.append("file", fileInput.files[0], "C:/Users/user/Downloads/xyz.pdf");
 
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/autoclassify");
xhr.setRequestHeader("Authorization", "Bearer your_token_here");

xhr.send(data);
```

### API Response

<table data-header-hidden><thead><tr><th width="147"></th><th></th></tr></thead><tbody><tr><td>Status code</td><td>Example Response</td></tr><tr><td>200</td><td><code>{'status': 'success', 'description': 'File uploaded and classification initiated successfully','OCR_ref_no': batch_id}</code></td></tr><tr><td>400</td><td><code>{'status': 'fail', 'description': 'Missing required fields: {field}'}</code></td></tr><tr><td>500</td><td><code>{'error': error}</code></td></tr></tbody></table>
