> 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/update-documents/update-document.md).

# Update Document

Endpoint Name : `update_document`

Request type : `POST`

Authorization : Bearer token as header

Endpoint Details : The `update_documentendpoint` will be used to update the document.

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

### Request Body

<table data-header-hidden><thead><tr><th width="177"></th><th width="106"></th><th width="104.63629150390625"></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>collection_name</td><td>string </td><td>Yes</td><td>Name of collection of document.</td></tr><tr><td>id</td><td>string</td><td>Yes</td><td>ID of document.</td></tr><tr><td>data</td><td>string(JSON)</td><td>Yes</td><td><p>A valid JSON string containing details of updates to be done to fields of Document.</p><p>If coordinates are not available then array will [0,0,0,0]</p><p>Example :</p><p>{<br>"doc_date_value": {</p><p>      "_value": "02-Oct-2022",</p><p>      "_coordinates": [1306,87,1444,107],</p><p>    },</p><p>"doc_number_value": {</p><p>      "_value": "287269549621X10102022",</p><p>      "_coordinates": [1306,87,1444,107],</p><p>    },</p><p>}</p></td></tr></tbody></table>

### Shell (cURL)

* Request Body

```sh
curl --location "URL/access/klearstack/update_document" \
  --header "Authorization: Bearer your_token_here" \
  --form "company_name=Replace_Company_Name_Here" \
  --form "collection_name=Replace_Collection_Name_Here" \
  --form "id=Replace_Document_ID_Here" \
  --form 'data={
    "doc_date_value": {
        "_value": "02-Oct-2022",
        "_coordinates": [1306, 87, 1444, 107]
    },
    "doc_number_value": {
        "_value": "287269549621X10102022",
        "_coordinates": [1306, 87, 1444, 107]
    }
}'
```

### Python

* Request Body

```python
import requests

url = "URL/access/klearstack/getdocument"

payload = {'company_name': 'Replace_Company_Name_Here',
'collection_name': 'Replace_Collection_Name_Here',
'user_id': 'Replace_User_ID_Here',
'document_id': 'Replace_Document_ID_Here'}
files=[

]
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_Your_Company_Name_Here")
  .addFormDataPart("collection_name", "Replace_Your_Collection_Name_Here")
  .addFormDataPart("id", "Replace_Your_Document_ID_Here")
  .addFormDataPart("data", "{\n" +
    "    \"doc_date_value\": {\n" +
    "        \"_value\": \"Replace_Your_Date_Here\",\n" +
    "        \"_coordinates\": [x1, y1, x2, y2]\n" +
    "    },\n" +
    "    \"doc_number_value\": {\n" +
    "        \"_value\": \"Replace_Your_Document_Number_Here\",\n" +
    "        \"_coordinates\": [x1, y1, x2, y2]\n" +
    "    }\n" +
    "}")
  .build();
Request request = new Request.Builder()
  .url("URL/access/klearstack/update_document")
  .method("POST", body)
  .addHeader("Authorization", "Bearer Replace_Your_Token_Here")
  .build();
Response response = client.newCall(request).execute();
```

### Node.js

* Request Body

```javascript
const axios = require('axios');
const FormData = require('form-data');

let formData = new FormData();
formData.append('company_name', 'Replace_Your_Company_Name_Here');
formData.append('collection_name', 'Replace_Your_Collection_Name_Here');
formData.append('id', 'Replace_Your_Document_ID_Here');
formData.append('data', '{\r\n    "doc_date_value": {\r\n        "_value": "Replace_Your_Date_Here",\r\n        "_coordinates": [x1, y1, x2, y2]\r\n    },\r\n    "doc_number_value": {\r\n        "_value": "Replace_Your_Document_Number_Here",\r\n        "_coordinates": [x1, y1, x2, y2]\r\n    }\r\n}');

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

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 formData = new FormData();
formData.append("company_name", "Replace_Your_Company_Name_Here");
formData.append("collection_name", "Replace_Your_Collection_Name_Here");
formData.append("id", "Replace_Your_Document_ID_Here");
formData.append("data", "{\r\n    \"doc_date_value\": {\r\n        \"_value\": \"Replace_Your_Date_Here\",\r\n        \"_coordinates\": [x1, y1, x2, y2]\r\n    },\r\n    \"doc_number_value\": {\r\n        \"_value\": \"Replace_Your_Document_Number_Here\",\r\n        \"_coordinates\": [x1, y1, x2, y2]\r\n    }\r\n}");

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/update_document");
xhr.setRequestHeader("Authorization", "Bearer Replace_Your_Token_Here");

xhr.send(formData);
```

### API Response&#x20;

<table data-header-hidden><thead><tr><th width="140"></th><th></th></tr></thead><tbody><tr><td>Status code</td><td>Example Response</td></tr><tr><td>200</td><td>Json Response</td></tr></tbody></table>
