# Uploading encoded documents to an entity

This endpoint allows you to upload base64 encoded entity documents directly via API, instead of using a URL. You may want to do this to fully customise the look and feel of the verification process within your website or application.

{% hint style="warning" %}
Note: You don't need to use this endpoint if you're verifying entities using a verification link.
{% endhint %}

Each call can only receive one document. Make sure to send the necessary data in the docSubType parameter.

***

## Upload documents to your applicant

<mark style="color:green;">`POST`</mark> `/api-entity-document-upload-encoded`

Upload a base64 encoded document to an entity, ready for processing.

| Name          | Value                 |
| ------------- | --------------------- |
| Content-Type  | `multipart/form-data` |
| Authorization | `Bearer YOUR_TOKEN`   |

**Body**

<table><thead><tr><th>Name</th><th width="165">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>applicantId</code></td><td>string</td><td>Unique applicantId generated on applicant creation <mark style="color:red;">(required)</mark></td></tr><tr><td><code>docSubType</code></td><td>string</td><td>The corporate document type - see next page for the different types.<mark style="color:orange;">(optional)</mark></td></tr><tr><td><code>fileName</code></td><td>string</td><td>The name of the file, including the extension (<code>.jpg</code>, <code>.jpeg</code>, <code>.png</code>, and <code>.pdf)</code> <mark style="color:red;">(required)</mark></td></tr><tr><td><code>docFile</code></td><td>string</td><td>File content in <a href="https://developer.mozilla.org/en-US/docs/Glossary/Base64">base64 encoded</a> format <mark style="color:red;">(required)</mark></td></tr></tbody></table>

#### Request

{% tabs %}
{% tab title="cURL" %}

```sh
curl -X POST https://enterprise.personr.co/api/1.1/wf/api-entity-document-upload-encoded \
    -H "Content-Type: multipart/form-data" \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
    -F "applicantId=4242424242424x424242424242424242" \
    -F "docSubType=Certificate of incorporation" \
    -F "fileName=document.pdf" \
    -F "docFile=/9j/4AAQSkZJRgABAQAAAQABAAD..." \
```

{% endtab %}

{% tab title="Node.js" %}

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

const formData = new FormData();

const base64FileContent = '/9j/4AAQSkZJRgABAQAAAQABAAD...';

formData.append('applicantId', '4242424242424x424242424242424242');
formData.append('docSubType', 'Certificate of incorporation');
formData.append('fileName', 'document.pdf');
formData.append('docFile', base64FileContent);

const config = {
  method: 'post',
  url: 'https://enterprise.personr.co/api/1.1/wf/api-entity-document-upload-encoded',
  headers: { 
    'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
    ...formData.getHeaders(),
  },
  data: formData,
  maxBodyLength: Infinity,
  maxContentLength: Infinity,
};

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

{% endtab %}

{% tab title="Javascript" %}

```javascript
const fs = require('fs');
const fetch = require('node-fetch');

const fileBase64 = "/9j/4AAQSkZJRgABAQAAAQABAAD..."

const url = "https://enterprise.personr.co/api/1.1/wf/api-entity-document-upload-encoded";

const payload = {
  applicantId: "4242424242424x424242424242424242",
  docSubType: "Certificate of incorporation",
  fileName: "document.pdf",
  docFile: fileBase64
};

fetch(url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_ACCESS_TOKEN"
  },
  body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "uri"
require "net/http"
require "json"

base64_file = "/9j/4AAQSkZJRgABAQAAAQABAAD..."

url = URI("https://enterprise.personr.co/api/1.1/wf/api-entity-document-upload-encoded")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer YOUR_ACCESS_TOKEN"

payload = {
  applicantId: "4242424242424x424242424242424242",
  docSubType: "Certificate of incorporation",
  fileName: "document.pdf",
  docFile: base64_file
}

request.body = payload.to_json

response = https.request(request)
puts response.read_body
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://enterprise.personr.co/api/1.1/wf/api-entity-document-upload-encoded"

base64_file = "/9j/4AAQSkZJRgABAQAAAQABAAD..."

payload = {
    "applicantId": "4242424242424x424242424242424242",
    "docSubType": "Certificate of incorporation",
    "fileName": "document.pdf",
    "docFile": base64_file
}

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_ACCESS_TOKEN"
}

response = requests.post(url, headers=headers, json=payload)

print(response.text)
```

{% endtab %}
{% endtabs %}

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "applicantId": "4242424242424x424242424242424242",
    "documentSubType": "Certificate of incorporation"
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "statusCode": 400,
    "message": "Error: invalid applicantId"
}
```

{% endtab %}
{% endtabs %}

{% hint style="success" %}
Once all required documents have been uploaded, head to[Requesting to start the verification process](/api-documentation/entities/requesting-to-start-the-verification-process.md)to confirm everything has been uploaded, and to start the verification check.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.personr.co/api-documentation/entities/uploading-documents-to-an-entity/uploading-encoded-documents-to-an-entity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
