# Push Annotated Text for a Document to KlearStack

Endpoint Name: `gettext`

Request type : `POST`

Authorization: Bearer token as header

Endpoint Details: The `gettext` endpoint will be used to push annotated text for a document to KlearStack.

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

### Request Body

<table data-header-hidden><thead><tr><th width="188"></th><th width="100"></th><th width="101.636474609375"></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>ocr_text_id</td><td>string</td><td>Yes</td><td>ID received from key “ocr_id” of response from api getdocument</td></tr><tr><td>coordinates</td><td>string</td><td>Yes</td><td><p>JSON list of co-ordinates </p><p>Example : [top_left_x,top_left_y,bottom_right_x,bottom_right_y]</p></td></tr></tbody></table>

### Shell (cURL)

* Request Body

```sh
curl --location "URL/access/klearstack/gettext" \
  --header "Authorization: Bearer your_token_here" \
  --form "company_name=Replace_Company_Name_Here" \
  --form "collection_name=Replace_Collection_Name_Here" \
  --form "ocr_text_id=Replace_OCR_Text_ID_Here" \
  --form "coordinates=[top_left_x, top_left_y, bottom_right_x, bottom_right_y]"
```

### Python

* Request Body

```python
import requests

url = "URL/access/klearstack/gettext"

payload = {'company_name': 'Replace_Company_Name_Here',
'collection_name': 'Replace_Collection_Name_Here',
'ocr_text_id': 'Replace_OCR_Text_ID_Here',
'coordinates': '[top_left_x, top_left_y, bottom_right_x, bottom_right_y]'}
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("ocr_text_id", "Replace_Your_OCR_Text_ID_Here")
  .addFormDataPart("coordinates", "[top_left_x, top_left_y, bottom_right_x, bottom_right_y]")
  .build();
Request request = new Request.Builder()
  .url("URL/access/klearstack/gettext")
  .method("POST", body)
  .addHeader("Authorization", "Bearer Replace_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');

let formData = new FormData();
formData.append('company_name', 'Replace_Your_Company_Name_Here');
formData.append('collection_name', 'Replace_Your_Collection_Name_Here');
formData.append('ocr_text_id', 'Replace_Your_OCR_Text_ID_Here');
formData.append('coordinates', '[top_left_x, top_left_y, bottom_right_x, bottom_right_y]');

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'URL/access/klearstack/gettext',
  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("ocr_text_id", "Replace_Your_OCR_Text_ID_Here");
formData.append("coordinates", "[top_left_x, top_left_y, bottom_right_x, bottom_right_y]");

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

xhr.send(formData);
```

### API Response&#x20;

<table data-header-hidden><thead><tr><th width="138"></th><th></th></tr></thead><tbody><tr><td>Status code</td><td>Example Response</td></tr><tr><td>200</td><td><p>{</p><p>    "text": [</p><p>        "27"</p><p>    ],</p><p>    “release_version”:”7.8.9”</p><p>}</p></td></tr></tbody></table>
