- Print
- PDF
CLOVA OCR Document API
- Print
- PDF
version
Version | Date | Changes |
---|---|---|
v1.0.0 | 2021-03-04 | First written |
v1.0.2 | 2021-07-22 | foundValuesSum -> foundValueSum Add maskingPolys to ID card |
v1.0.3 | 2021-09-16 | Add alien registration card to ID card |
v1.0.4 | 2022-04-21 | Indicate on the corner of the ID card Add alienRegNumEtc to alien registration card Add name to credit card |
v1.0.5 | 2023-05-25 | Passport MRZ API |
v1.0.6 | 2023-11-23 | Add receipt VAT and discount amount |
Requests
Method | Request URI |
---|---|
POST | Calls to API Gateway's InvokeURL created from CLOVA OCR builder. A unique call URL is generated for each domain. |
Requesting document OCR recognition
Classification | Description | Path |
---|---|---|
Document | Receipt | /document/receipt |
Document | Credit card | /document/credit-card |
Document | Business card | /document/name-card |
Document | Business registration certificate | /document/biz-license |
Document | ID card (resident registration certificate, driver's license, passport) | /document/id-card |
Document | Passport (global) | /document/passport |
Request headers
Header name | Description |
---|---|
X-OCR-SECRET | X-OCR-SECRET:{Client Secret} created when linking API Gateway on the domain |
Content-Type | Application/json: use the main text of JSON in the request. Supports image.data encoded with Base64. - multipart/form-data: use the multipart text in the request. Supports image files transmitted through streaming. |
Request bodies
Content-Type : application/json
- Image recognition request
Classification | Json Model |
---|---|
Image recognition request | { "version": "string", "requestId": "string", "timestamp": 0, "images": [{ "format": "string", "data": "string", "name": "string"}] } |
Detailed descriptions of image recognition request fields
Field name | Requirement status | Type | Description | Restrictions |
---|---|---|---|---|
version | Yes | string | Fix as "V2" | |
requestId | Yes | string | It is the API call UUID. | |
timestamp | Yes | 0 | It is the API call timestamp value. | |
images | Yes | string | This is entered as a JSON array, but only 1 image can be entered currently. (Korean/Japanese) | |
images.format | Yes | string | It sets the image format. | It supports ".jpg," ".jpeg," and ".png" images, as well as single-page ".pdf" and ".tiff" formats. |
image.data | Yes | string | image.data is base64 encoding image bytes. | |
image.name | Yes | string | Enter the name for the image. It is used to identify the image, as well as for checking the response result. |
CURL example:
curl --request POST 'your apigw invoke url' \
--header 'X-OCR-SECRET: your secret key' \
--data-raw '{"images":[{"format":"jpg","name":"demo","data":"your image base64 bytes"}],"requestId":"guide-json-demo","version":"V2","timestamp":1584062336793}'
Content-Type : multipart/form-data
- Image recognition request
KEY | Required | VALUE |
---|---|---|
message | Y | {"version": "string","requestId": "string","timestamp": 0,"images": [{ "format": "string", "name": "string" }]} |
file | Y | image file steam data |
Form Data Message Value Description
Field name | Required | Type | Description | Constraints |
---|---|---|---|---|
version | Yes | string | Fix as "V2" | |
requestId | Yes | string | It is the API call UUID. | |
timestamp | Yes | integer | It is the API call timestamp value. | |
images | Yes | string | It is entered as a JSON array, but only one image can be entered currently. | |
images.format | Yes | string | It sets the image format. | It supports ".jpg," ".jpeg," and ".png" images, as well as single-page ".pdf" and ".tiff" formats. |
image.name | Yes | string | Enter the name for the image. It is used to identify the image, as well as for checking the response result. |
CURL example:
curl --request POST 'your apigw invoke url' \
--header 'X-OCR-SECRET: your secret key' \
--form 'message={"images":[{"format":"png","name":"demo"}],"requestId":"guide-demo","version":"V2","timestamp":1584062336793}' \
--form 'file=@image.png'
Responses
Response bodies
- Image recognition results
Classification | Json Model |
---|---|
Image recognition results | { "uid": "string", "name": "string", "inferResult": "string", "message": "string", "receipt": {}, "creditCard": {}, "bizLicense": {}, "idCard": {}, "nameCard": {}, "passport": {}, "validationResult": { "result": "string", "message": "string"} } |
Detailed description of the Image recognition results field
Field Name | Data Type | Description |
---|---|---|
uid | string | It is a unique ID provided to check the validity of the API, and used to track the validity test request. |
name | string | Name of the requested image |
inferResult | string | Image inference result "SUCCESS": image recognition successful. "FAILURE": image recognition failed. "ERROR": exception to image recognition. |
message | string | "SUCCESS" in case of successful image recognition. An error message is generated when image recognition fails. The error messages are displayed in detail at the bottom. |
receipt | json object | Refer to the receipt object |
creditCard | json object | Refer to the creditCard object |
bizLicense | json object | Refer to the bizLicense object |
idCard | json object | Refer to the idCard object |
nameCard | json object | Refer to the nameCard object |
passport | json object | Refer to the passport object |
validationResult | json object | Validity test result |
validationResult.result | string | Result code "NO_REQUESTED": the validation operation was not executed. "UNCHECKED": the response for the action wasn't confirmed, or the response was not accepted. "ERROR": error in validation operation. "VALID": the validation result is valid. "INVALID": the validation result is invalid. |
validationResult.message | string | It is not a value always returned in the detailed message on the validation test. |
convertedImageInfo | json object | It responds only if the image format is PDF/TIFF. If the request format is PDF/TIFF, the coordinates are based on the converted image. |
convertedImageInfo.width | integer | Default image width. |
convertedImageInfo.height | integer | Default image height. |
convertedImageInfo.pageIndex | integer | Page index of PDF/TIFF |
- receipt object
Classification | Json Model |
---|---|
receipt Field | { "meta": {}, "result": {}, } |
Receipt Object Field Details
Field Name | Data Type | Description |
---|---|---|
meta | json object | Meta information |
meta.estimatedLanguage | string | Language assumed by OCR (en: English, ja: Japanese, ko: Korean) | OCR recognition language |
result | json object | Recognition result |
result.storeInfo | json object | Store Information |
result.storeInfo.poiInfo | PoiObject[] | POI grounding result |
result.storeInfo.name | StringObject | Company name |
result.storeInfo.subName | StringObject | Branch name |
result.storeInfo.bizNum | StringObject | Business registration number |
result.storeInfo.movieName | StringObject | Movie name (item related to movie ticket) |
result.storeInfo.addresses | StringObject[] | Store address |
result.storeInfo.tel | TelObject[] | Telephone number of the store |
result.paymentInfo | json object | Payment information |
result.paymentInfo.date | DateObject | Payment date |
result.paymentInfo.time | TimeObject | Payment time |
result.paymentInfo.cardInfo | json object | Transaction card information |
result.paymentInfo.cardInfo.company | StringObject | Card company name |
result.paymentInfo.cardInfo.number | StringObject | Card number |
result.paymentInfo.confirmNum | BaseObject | Payment number |
result.subResults | json array | Item group information |
result.subResults.items | json array | Recognized item information (menu, etc.) |
result.subResults.items.name | StringObject | Item name |
result.subResults.items.code | StringObject | Item code |
result.subResults.items.count | FloatObject | Item quantity |
result.subResults.items.price | json object | Pricing data |
result.subResults.items.price.price | FloatObject | Price |
result.subResults.items.price.unitPrice | FloatObject | Unit price |
result.totalPrice | json object | Total amount information |
result.totalPrice.price | FloatObject | Total amount |
result.subtotal | FloatObject | Grand total information |
result.subtotal.taxprice | FloatObject | VAT |
result.subtotal.discountprice | FloatObject | Discount amount |
- creditCard object
Classification | Json Model |
---|---|
creditCard Field | { "meta": {}, "result": {}, } |
creditCard Object Field Details
Field Name | Data Type | Description |
---|---|---|
meta | json object | Meta information |
meta.estimatedLanguage | string | Language assumed by OCR (en: English, ja: Japanese, ko: Korean) |
result | json object | Recognition result |
result.number | Field object | Refer to the Field object |
result.validThru | Field object | Refer to the Field object |
result.name | Field object | Name of card owner Refer to the Field object |
- bizLicense object
Classification | Json Model |
---|---|
bizLicense Field | { "meta": {}, "result": {}, } |
bizLicense Object Field Details
Field Name | Data Type | Description |
---|---|---|
meta | json object | Meta information |
meta.estimatedLanguage | string | Language assumed by OCR (en: English, ja: Japanese, ko: Korean) |
result | json object | Recognition result |
result.birth | BaseObject[] | Date of birth |
result.bisAddress | BaseObject[] | Address of Business |
result.bisArea | BaseObject[] | Business Place Location |
result.bisItem | BaseObject[] | Business item |
result.registerNumber | BaseObject[] | Business Registration Number |
result.bisType | BaseObject[] | Business area |
result.companyName | BaseObject[] | Company name |
result.coRepName | BaseObject[] | Name of joint representative |
result.corpName | BaseObject[] | Name of corporation (group) |
result.corpRegisterNum | BaseObject[] | Business Registration Number |
result.coRepSocialNum | BaseObject[] | Resident registration number of joint representative |
result.documentType | StringObject[] | Document type |
result.headAddress | BaseObject[] | Head office address |
result.issuanceDate | BaseObject[] | Issuance date |
result.issuanceReason | BaseObject[] | Reason for issuance |
result.openDate | BaseObject[] | Business start date |
result.repName | BaseObject[] | Name of representative |
result.socialNumber | BaseObject[] | Resident registration number |
result.taxType | BaseObject[] | Type of taxation |
- idCard object
Classification | Json Model |
---|---|
idcard Field | { "meta": {}, "result": {}, } |
idCard Object Field Details
Field Name | Data Type | Description |
---|---|---|
meta | json object | Meta information |
meta.estimatedLanguage | string | Language assumed by OCR (en: English, ja: Japanese, ko: Korean) |
result | json object | Recognition result |
result.isConfident | boolean | Indicator reflecting the required reliability criteria If each ID type contains the required detailed information, it generates "True," but if not, "False." |
result.IDType | string | ID type The return result is "ID," "driver's license," "passport" or "unknown." |
result.rois | BoundingPoly[] | Object corner location information |
result.ic | json object | Resident registration card information |
result.ic.name | StringObject[] | Name (Korean) |
result.ic.personalNum | StringObject[] | Resident registration number |
result.ic.address | StringObject[] | Address |
result.ic.issueDate | DateObject[] | Issuance date |
result.ic.authority | StringObject[] | Issuing institution |
result.dl | json object | Driver's license information |
result.dl.type | BaseObject[] | License type |
result.dl.num | StringObject[] | License number |
result.dl.name | StringObject[] | Name (Korean) |
result.dl.personalNum | StringObject[] | Resident registration number |
result.dl.address | StringObject[] | Address |
result.dl.renewStartDate | DateObject[] | Renewal Period Start Date |
result.dl.renewEndDate | DateObject[] | Renewal Period End Date |
result.dl.condition | StringObject[] | Licensing Condition |
result.dl.code | StringObject[] | License Code |
result.dl.organDonation | BaseObject[] | Organ and tissue donation registration |
result.dl.issueDate | DateObject[] | Issuance date |
result.dl.authority | StringObject[] | Issuing institution |
result.pp | json object | Passport information |
result.pp.type | StringObject[] | Passport type |
result.pp.issueCountry | BaseObject[] | Issuing country |
result.pp.num | StringObject[] | Passport number |
result.pp.surName | StringObject[] | Last name |
result.pp.givenName | StringObject[] | Name |
result.pp.nationality | StringObject[] | Nationality |
result.pp.birthDate | DateObject[] | Date of birth |
result.pp.personalNum | StringObject[] | Resident registration number |
result.pp.sex | StringObject[] | Gender |
result.pp.issueDate | DateObject[] | Issuance date |
result.pp.expireDate | DateObject[] | Expiration date |
result.pp.authority | BaseObject[] | Issuing institution |
result.pp.fullNameKor | StringObject[] | Name (Korean) |
result.pp.MRZ1 | StringObject[] | Machine Readable Zone (MRZ) 1 |
result.pp.MRZ2 | StringObject[] | Machine Readable Zone (MRZ) 2 |
result.ac | json object | Alien registration information |
result.ac.alienRegNum | StringObject[] | Alien Registration Number |
result.ac.sex | StringObject[] | Gender |
result.ac.name | StringObject[] | Name |
result.ac.nationality | StringObject[] | Nationality |
result.ac.visaType | StringObject[] | Visa type |
result.ac.issueDate | DateObject[] | Issuance date |
result.ac.authority | StringObject[] | Issuing institution |
result.ac.authorityEng | StringObject[] | Issuing institution (English) |
result.ac.alienRegNumEtc | StringObject[] | Alien Registration Number, etc. |
- nameCard object
Classification | Json Model |
---|---|
nameCard Field | { "meta": {}, "result": {}, } |
nameCard Object Field Details
Field Name | Data Type | Description |
---|---|---|
meta | json object | Meta information |
meta.estimatedLanguage | string | Language assumed by OCR (en: English, ja: Japanese, ko: Korean) |
result | json object | Recognition result |
result.name | StringObject[] | Name information |
result.nameFurigana | StringObject[] | Furigana name information (respond only when the language is "ja") |
result.company | StringObject[] | Company Information |
result.department | StringObject[] | Department Information |
result.address | StringObject[] | Address information |
result.position | StringObject[] | Job Title Information |
result.mobile | TelObject[] | Mobile phone information |
result.tel | TelObject[] | Telephone information |
result.fax | TelObject[] | Fax information |
result.email | StringObject[] | Email information |
result.homepage | StringObject[] | Website information |
- passport object
Classification | Json Model |
---|---|
passport Field | { " passportResult": {}, } |
passport Object Field Details
Field Name | Data Type | Description |
---|---|---|
passportResult | json object | Recognition result |
passportResult.documentClassCode | MrzString | Document code "Passport" |
passportResult.issuingStateCode | MrzString | Issuing country |
passportResult.firstName | MrzString | Name |
passportResult.lastName1 | MrzString | First surname |
passportResult.lastName2 | MrzString | Second surname |
passportResult.documentNumber | MrzString | Passport number |
passportResult.checkDigitForDocumentNumber | MrzString | Confirmation number on document number |
passportResult.nationality | MrzString | Nationality |
passportResult.dateOfBirth | MrzString | Date of birth |
passportResult.age | MrzInt | Age |
passportResult.checkDigitForDateOfBirth | MrzString | Confirmation number on date of birth |
passportResult.gender | MrzString | Gender |
passportResult.dateOfExpiry | MrzString | Expiration date |
passportResult.checkDigitForDateOfExpiry | MrzString | Confirmation number on expiration date |
passportResult.personalNumber | MrzString | Resident registration number |
passportResult.checkDigitForPersonalNumber | MrzString | Confirmation number on resident registration number |
passportResult.finalCheckDigit | MrzString | Final confirmation number |
passportResult.mrzType | MrzString | MRZ type |
passportResult.mrzLines | MrzString | MRZ text |
passportResult.isExpired | Mrzbool | Expired |
- field object
Classification | Json Model |
---|---|
field Field | { "text": "", "confidence": 0.0, "boundingPoly": {}, "subBoundingPolys": [] } |
field Object Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | Recognition result text |
confidence | float | Reliability of inference result. The higher the value between 0–1, the higher the accuracy. |
boundingPoly | BoundingPoly object | Refer to the boundingPoly object |
subBoundingPolys | BoundingPoly[] | Refer to the boundingPoly object |
- boundingPoly object
Classification | Json Model |
---|---|
boundingPoly | { "vertices":[{}] } |
boundingPoly Object Field Details
Field Name | Data Type | Description |
---|---|---|
vertices | vertices object | Refer to the vertices object |
- vertices object
Classification | Json Model |
---|---|
vertices | { "x": 0.0, "y": 0.0 } |
vertices Object Field Details
Field Name | Data Type | Description |
---|---|---|
x | float | X coordinates |
y | float | Y coordinates |
- baseObject
Classification | Json Model |
---|---|
baseObject | { "text": "", "boundingPolys": [], "keyText":"", "confidenceScore":0.0 } |
baseObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | Parsed text |
boundingPolys | BoundingPoly[] | Refer to the boundingPoly object |
keyText | string | Key value related to the parsed text |
confidenceScore | float | Reliability of inference result. The higher the value between 0–1, the higher the accuracy. |
- dateObject
Classification | Json Model |
---|---|
dateObject | { "text": "", "formatted": {}, "boundingPolys": [], "maskingPolys":[], "keyText":"", "confidenceScore":0.0 } |
dateObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | Parsed text |
formatted | json object | Additional information on parsed text |
formatted.year | string | Year. Indicates year in a four-digit number. Follows the standard ISO 8601 format except that it may be an empty row of letters. |
formatted.month | string | Monthly. Indicates month in a two-digit number. Follows the standard ISO 8601 format except that it may be an empty row of letters. |
formatted.day | string | Date. Indicates date in a two-digit number. Follows the standard ISO 8601 format except that it may be an empty row of letters. |
boundingPolys | BoundingPoly[] | Refer to the boundingPoly object |
maskingPolys | BoundingPoly[] | Personal data masking |
keyText | string | Key value related to the parsed text |
confidenceScore | float | Reliability of inference result. The higher the value between 0–1, the higher the accuracy. |
- timeObject
Classification | Json Model |
---|---|
timeObject | { "text": "", "formatted": {}, "boundingPolys": [], "keyText":"", "confidenceScore":0.0 } |
timeObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | Parsed text |
formatted | json object | Additional information on parsed text |
formatted.hour | string | Hour. Indicates hour in a two-digit number. Follows the standard ISO 8601 format except that it may be an empty row of letters. |
formatted.minute | string | Minute(s). Indicates minutes in a two-digit number. Follows the standard ISO 8601 format except that it may be an empty row of letters. |
formatted.second | string | Second(s). Indicates seconds in a two-digit number. Follows the standard ISO 8601 format except that it may be an empty row of letters. |
boundingPolys | BoundingPoly[] | Refer to the boundingPoly object |
maskingPolys | BoundingPoly[] | Personal data masking |
keyText | string | Key value related to the parsed text |
confidenceScore | float | Reliability of inference result. The higher the value between 0–1, the higher the accuracy. |
- TelObject
Classification | Json Model |
---|---|
TelObject | { "text": "", "formatted": {}, "boundingPolys": [], "keyText":"", "confidenceScore":0.0 } |
TelObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | Parsed text |
formatted | json object | Additional information on parsed text |
formatted.value | string | Text with form indicating telephone number type. While usually a row of numbers, may include a telephone-number identification character (+). May be an empty row of letters if detailed recognition fails. |
boundingPolys | BoundingPoly[] | Refer to the boundingPoly object |
keyText | string | Key value related to the parsed text |
confidenceScore | float | Reliability of inference result. The higher the value between 0–1, the higher the accuracy. |
- FloatObject
Classification | Json Model |
---|---|
FloatObject | { "text": "", "formatted": {}, "boundingPolys": [], "keyText":"", "confidenceScore":0.0 } |
FloatObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | Parsed text |
formatted | json object | Additional information on parsed text |
formatted.value | string | Text with form indicating error type. Type of erroneous row of letters. Useful in indicating item price and count. May be an empty row of letters if detailed recognition fails. |
boundingPolys | BoundingPoly[] | Refer to the boundingPoly object |
keyText | string | Key value related to the parsed text |
confidenceScore | float | Reliability of inference result. The higher the value between 0–1, the higher the accuracy. |
- StringObject
Classification | Json Model |
---|---|
StringObject | { "text": "", "formatted": {}, "boundingPolys": [], "maskingPolys": [], "keyText":"", "confidenceScore":0.0 } |
StringObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | Parsed text |
formatted | json object | Additional information on parsed text |
formatted.value | string | Refined text. Process of refinement differs based on the type of ID. May be an empty row of letters. |
boundingPolys | BoundingPoly[] | Refer to the boundingPoly object |
maskingPolys | BoundingPoly[] | Personal information |
keyText | string | Key value related to the parsed text |
confidenceScore | float | Reliability of inference result. The higher the value between 0–1, the higher the accuracy. |
- PoiObject
Classification | Json Model |
---|---|
PoiObject | { "gid": "", "title": "", "phone": "", "address": "", "roadAddress": "", "biznum": "", "confidence": "" } |
PoiObject Field Details
Field Name | Data Type | Description |
---|---|---|
gid | string | Unique user ID |
title | string | Company name |
phone | string | Phone Number |
address | string | Address |
roadAddress | string | Road name address |
biznum | string | Business registration number (can be null since it is not yet supported officially, but may be added later) |
confidence | string | Reliability (The greater the value, the more accurate it is.) |
18.Checksum object
Classification | Json Model |
---|---|
checksum Field | { "found": "", "foundValueIds": [], "foundValueSum": "", "foundTotalIds": [], "foundTotalSum": "", "foundTotalSum": "" } |
Checksum Object Field Details
Field Name | Data Type | Description |
---|---|---|
found | json object | Flag showing whether checksum field has been discovered |
foundValueIds | int[] | ID list of discovered value cell |
foundValueSum | float | Sum of discovered values |
foundTotalIds | int[] | ID list of all discovered cells |
foundTotalSum | float | Sum of all discovered values |
difference | float | Difference between value and all cells |
19.KeyCell object
Classification | Json Model |
---|---|
KeyCell Field | { "boundingPoly": {}, "depth": "", "formatted": "", "group": "", "value": "" } |
KeyCell Object Field Details
Field Name | Data Type | Description |
---|---|---|
boundingPoly | BoundingPoly | Coordinates of cell corner box |
depth | string | Depth of discovered key cell |
formatted | string | Grounding text of key cell |
group | string | Identifying character for distinguishing between row and column keys |
value | string | Ungrounded text in key cells |
20.ValueCell object
Classification | Json Model |
---|---|
ValueCell Field | { "boundingPoly": {}, "confidence": "", "value": "" } |
ValueCell Object Field Details
Field Name | Data Type | Description |
---|---|---|
boundingPoly | BoundingPoly | Coordinates of cell corner box |
confidence | float | Reliability of value cell |
value | string | Text of value cell |
21.MrzString object
Classification | Json Model |
---|---|
MrzString Field | { "rawText": "", "refinedText ": "", "postprocessed": [0] } |
MrzString Object Field Details
Field Name | Data Type | Description |
---|---|---|
rawText | string | Original text |
refinedText | string | Refined text |
postprocessed | int32 | Refinement method |
22.Mrzbool object
Classification | Json Model |
---|---|
Mrzbool Field | { "rawText": "", "refinedText ": "", "postprocessed": [0] } |
Mrzbool Object Field Details
Field Name | Data Type | Description |
---|---|---|
rawText | string | Original text |
refinedText | bool | Refined text |
postprocessed | int32 | Refinement method |
23.MrzInt object
Classification | Json Model |
---|---|
MrzInt Field | { "rawText": "", "refinedText ": 0, "postprocessed": [0] } |
MrzInt Object Field Details
Field Name | Data Type | Description |
---|---|---|
rawText | string | Original text |
refinedText | int | Refined text |
postprocessed | int32 | Refinement method |
Examples
Document OCR request examples
{
"version": "V2",
"requestId": "string",
"timestamp": 0,
"images": [
{
"format": "jpg",
"name": "test 1",
"data": "data"
}
]
}
Credit card response examples
{
"version": "V2",
"requestId": "string",
"timestamp": 1613984515468,
"images": [
{
"creditCard": {
"result": {
"number": {
"text": "5307123456749012",
"confidence": 0.96435016,
"boundingPoly": {
"vertices": [
{
"x": 64.0,
"y": 218.0
},
{
"x": 582.0,
"y": 222.0
},
{
"x": 582.0,
"y": 265.0
},
{
"x": 64.0,
"y": 261.0
}
]
},
"subBoundingPolys": [
{
"vertices": [
{
"x": 65.0,
"y": 222.0
},
{
"x": 175.0,
"y": 225.0
},
{
"x": 174.0,
"y": 260.0
},
{
"x": 64.0,
"y": 257.0
}
]
},
{
"vertices": [
{
"x": 202.0,
"y": 225.0
},
{
"x": 312.0,
"y": 225.0
},
{
"x": 312.0,
"y": 262.0
},
{
"x": 202.0,
"y": 262.0
}
]
},
{
"vertices": [
{
"x": 340.0,
"y": 225.0
},
{
"x": 445.0,
"y": 225.0
},
{
"x": 445.0,
"y": 260.0
},
{
"x": 340.0,
"y": 260.0
}
]
},
{
"vertices": [
{
"x": 470.0,
"y": 222.0
},
{
"x": 582.0,
"y": 222.0
},
{
"x": 582.0,
"y": 260.0
},
{
"x": 470.0,
"y": 260.0
}
]
}
]
}
}
},
"uid": "5f824ebe5b9744bb81bd3e1ef7f42e4e",
"name": "testV2Demo",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}
]
}
Receipt response examples
{
"version": "V2",
"requestId": "string",
"timestamp": 1613984672273,
"images": [{
"receipt": {
"meta": {
"estimatedLanguage": "ko"
},
"result": {
"storeInfo": {
"name": {
"text": "emart everyday",
"formatted": {
"value": "emart everyday"
},
"boundingPolys": [{
"vertices": [{
"x": 263.0,
"y": 96.0
},
{
"x": 390.0,
"y": 100.0
},
{
"x": 389.0,
"y": 141.0
},
{
"x": 262.0,
"y": 137.0
}
]
}]
},
"subName": {
"text": "Bundang Jeongja II",
"formatted": {
"value": "Bundang Jeongja II"
},
"boundingPolys": [{
"vertices": [{
"x": 530.0,
"y": 102.0
},
{
"x": 611.0,
"y": 102.0
},
{
"x": 611.0,
"y": 122.0
},
{
"x": 530.0,
"y": 122.0
}
]
}]
},
"bizNum": {
"text": "212-81-25544",
"formatted": {
"value": "212-81-25544"
},
"boundingPolys": [{
"vertices": [{
"x": 402.0,
"y": 125.0
},
{
"x": 515.0,
"y": 124.0
},
{
"x": 515.0,
"y": 141.0
},
{
"x": 402.0,
"y": 142.0
}
]
}]
},
"addresses": [{
"text": "120, Jeongjail-ro, Bundang-gu, Seongnam-si, Gyeonggi-do",
"formatted": {
"value": "120, Jeongjail-ro, Bundang-gu, Seongnam-si, Gyeonggi-do"
},
"boundingPolys": [{
"vertices": [{
"x": 401.0,
"y": 144.0
},
{
"x": 432.0,
"y": 144.0
},
{
"x": 432.0,
"y": 165.0
},
{
"x": 401.0,
"y": 165.0
}
]
}]
}],
"tel": [{
"text": "(031)786-1171",
"formatted": {
"value": "0317861171"
},
"boundingPolys": [{
"vertices": [{
"x": 569.0,
"y": 122.0
},
{
"x": 716.0,
"y": 118.0
},
{
"x": 716.0,
"y": 140.0
},
{
"x": 570.0,
"y": 144.0
}
]
}]
}]
},
"paymentInfo": {
"date": {
"text": "2020-04-16",
"formatted": {
"year": "2020",
"month": "04",
"day": "16"
},
"boundingPolys": [{
"vertices": [{
"x": 261.0,
"y": 256.0
},
{
"x": 432.0,
"y": 260.0
},
{
"x": 431.0,
"y": 284.0
},
{
"x": 260.0,
"y": 280.0
}
]
}]
},
"time": {
"text": "20: 11",
"formatted": {
"hour": "20",
"minute": "11",
"second": "00"
},
"boundingPolys": [{
"vertices": [{
"x": 437.0,
"y": 261.0
},
{
"x": 468.0,
"y": 261.0
},
{
"x": 468.0,
"y": 279.0
},
{
"x": 437.0,
"y": 279.0
}
]
}]
},
"cardInfo": {
"company": {
"text": "Shinhan",
"formatted": {
"value": "Shinhan"
},
"boundingPolys": [{
"vertices": [{
"x": 309.0,
"y": 585.0
},
{
"x": 334.0,
"y": 585.0
},
{
"x": 334.0,
"y": 610.0
},
{
"x": 309.0,
"y": 610.0
}
]
}]
},
"number": {
"text": "4221**8666",
"formatted": {
"value": "4221**8666"
},
"boundingPolys": [{
"vertices": [{
"x": 522.0,
"y": 586.0
},
{
"x": 716.0,
"y": 592.0
},
{
"x": 716.0,
"y": 612.0
},
{
"x": 522.0,
"y": 606.0
}
]
}]
}
},
"confirmNum": {
"text": "28672931",
"boundingPolys": [{
"vertices": [{
"x": 522.0,
"y": 586.0
},
{
"x": 716.0,
"y": 592.0
},
{
"x": 716.0,
"y": 612.0
},
{
"x": 522.0,
"y": 606.0
}
]
}]
}
},
"subResults": [{
"items": [{
"name": {
"text": "Seagram Lemon 350 ml",
"formatted": {
"value": "Seagram Lemon 350 ml"
},
"boundingPolys": [{
"vertices": [{
"x": 310.0,
"y": 345.0
},
{
"x": 372.0,
"y": 345.0
},
{
"x": 372.0,
"y": 369.0
},
{
"x": 310.0,
"y": 369.0
}
]
}]
},
"count": {
"text": "2",
"formatted": {
"value": "2"
},
"boundingPolys": [{
"vertices": [{
"x": 601.0,
"y": 348.0
},
{
"x": 615.0,
"y": 348.0
},
{
"x": 615.0,
"y": 365.0
},
{
"x": 601.0,
"y": 365.0
}
]
}]
},
"price": {
"price": {
"text": "1,600",
"formatted": {
"value": "1600"
},
"boundingPolys": [{
"vertices": [{
"x": 662.0,
"y": 347.0
},
{
"x": 716.0,
"y": 347.0
},
{
"x": 716.0,
"y": 367.0
},
{
"x": 662.0,
"y": 367.0
}
]
}]
},
"unitPrice": {
"text": "800",
"formatted": {
"value": "800"
},
"boundingPolys": [{
"vertices": [{
"x": 541.0,
"y": 347.0
},
{
"x": 577.0,
"y": 347.0
},
{
"x": 577.0,
"y": 368.0
},
{
"x": 541.0,
"y": 368.0
}
]
}]
}
}
}]
}],
"totalPrice": {
"price": {
"text": "1,600",
"formatted": {
"value": "1600"
},
"boundingPolys": [{
"vertices": [{
"x": 651.0,
"y": 546.0
},
{
"x": 717.0,
"y": 548.0
},
{
"x": 717.0,
"y": 569.0
},
{
"x": 651.0,
"y": 567.0
}
]
}]
}
}
}
},
"uid": "5b9de1f9765448eca574efc1a4231bbe",
"name": "testV2Demo",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}]
}
Biz license response examples
{
"version": "V2",
"requestId": "string",
"timestamp": 1613984821070,
"images": [{
"bizLicense": {
"meta": {
"estimatedLanguage": "ko"
},
"result": {
"birth": [{
"text": "December 3, 1951",
"boundingPolys": [{
"vertices": [{
"x": 396.0,
"y": 254.0
},
{
"x": 421.0,
"y": 254.0
},
{
"x": 421.0,
"y": 265.0
},
{
"x": 396.0,
"y": 265.0
}
]
}]
}],
"bisAddress": [{
"": "54, Bogong-ro, Sacheon-eup, Sacheon-si, Gyeongsangnam-do",
"boundingPolys": [{
"vertices": [{
"x": 193.0,
"y": 288.0
},
{
"x": 235.0,
"y": 288.0
},
{
"x": 235.0,
"y": 300.0
},
{
"x": 193.0,
"y": 300.0
}
]
}]
}],
"bisArea": [],
"bisItem": [{
"text": "Renting of non-residential buildings (store, own land)",
"boundingPolys": [{
"vertices": [{
"x": 368.0,
"y": 325.0
},
{
"x": 399.0,
"y": 325.0
},
{
"x": 399.0,
"y": 334.0
},
{
"x": 368.0,
"y": 334.0
}
]
}]
}],
"registerNumber": [{
"text": "611-01-99810",
"boundingPolys": [{
"vertices": [{
"x": 290.0,
"y": 210.0
},
{
"x": 386.0,
"y": 211.0
},
{
"x": 386.0,
"y": 227.0
},
{
"x": 290.0,
"y": 225.0
}
]
}]
}],
"bisType": [{
"text": "Real estate and lease business",
"boundingPolys": [{
"vertices": [{
"x": 221.0,
"y": 322.0
},
{
"x": 262.0,
"y": 322.0
},
{
"x": 262.0,
"y": 333.0
},
{
"x": 221.0,
"y": 333.0
}
]
}]
}],
"companyName": [{
"text": "Dongseong Comprehensive Auto Repair",
"boundingPolys": [{
"vertices": [{
"x": 194.0,
"y": 232.0
},
{
"x": 293.0,
"y": 233.0
},
{
"x": 293.0,
"y": 247.0
},
{
"x": 194.0,
"y": 245.0
}
]
}]
}],
"coRepName": [],
"corpName": [],
"corpRegisterNum": [],
"coRepSocialNum": [],
"documentType": [{
"text": "Business Registration Certificate",
"formatted": {
"value": "Business Registration Certificate"
},
"boundingPolys": [{
"vertices": [{
"x": 199.0,
"y": 157.0
},
{
"x": 396.0,
"y": 160.0
},
{
"x": 396.0,
"y": 189.0
},
{
"x": 198.0,
"y": 186.0
}
]
}]
}],
"headAddress": [],
"issuanceDate": [{
"text": "June 29, 2017",
"boundingPolys": [{
"vertices": [{
"x": 225.0,
"y": 623.0
},
{
"x": 259.0,
"y": 623.0
},
{
"x": 259.0,
"y": 637.0
},
{
"x": 225.0,
"y": 637.0
}
]
}]
}],
"issuanceReason": [{
"text": "June 29, 2017",
"boundingPolys": [{
"vertices": [{
"x": 225.0,
"y": 623.0
},
{
"x": 259.0,
"y": 623.0
},
{
"x": 259.0,
"y": 637.0
},
{
"x": 225.0,
"y": 637.0
}
]
}]
}],
"openDate": [{
"text": "June 9, 2014",
"boundingPolys": [{
"vertices": [{
"x": 193.0,
"y": 271.0
},
{
"x": 218.0,
"y": 271.0
},
{
"x": 218.0,
"y": 280.0
},
{
"x": 193.0,
"y": 280.0
}
]
}]
}],
"repName": [{
"text": "Yeong-du Kim",
"boundingPolys": [{
"vertices": [{
"x": 193.0,
"y": 251.0
},
{
"x": 228.0,
"y": 251.0
},
{
"x": 228.0,
"y": 264.0
},
{
"x": 193.0,
"y": 264.0
}
]
}]
}],
"socialNumber": [],
"taxType": [{
"text": "ordinary taxpayer",
"boundingPolys": [{
"vertices": [{
"x": 238.0,
"y": 185.0
},
{
"x": 357.0,
"y": 187.0
},
{
"x": 357.0,
"y": 209.0
},
{
"x": 238.0,
"y": 207.0
}
]
}]
}]
}
},
"uid": "ecf05843a1f444b6943e9d202475c3eb",
"name": "testV2Demo",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}]
}
Name card response examples
{
"version": "V2",
"requestId": "string",
"timestamp": 1613984872349,
"images": [
{
"nameCard": {
"meta": {
"estimatedLanguage": "ko"
},
"result": {
"name": [
{
"text": "Gil-dong Hong",
"boundingPolys": [
{
"vertices": [
{
"x": 286.0,
"y": 194.0
},
{
"x": 348.0,
"y": 194.0
},
{
"x": 348.0,
"y": 266.0
},
{
"x": 286.0,
"y": 266.0
}
]
}
]
}
],
"nameFurigana": [],
"company": [
{
"text": "Woori Bank",
"boundingPolys": [
{
"vertices": [
{
"x": 317.0,
"y": 274.0
},
{
"x": 356.0,
"y": 274.0
},
{
"x": 356.0,
"y": 316.0
},
{
"x": 317.0,
"y": 316.0
}
]
}
]
}
],
"department": [],
"address": [
{
"text": "(Gil-dong Hong)",
"boundingPolys": [
{
"vertices": [
{
"x": 338.0,
"y": 189.0
},
{
"x": 414.0,
"y": 189.0
},
{
"x": 414.0,
"y": 288.0
},
{
"x": 338.0,
"y": 288.0
}
]
}
]
}
],
"position": [
{
"text": "Complaint",
"boundingPolys": [
{
"vertices": [
{
"x": 286.0,
"y": 194.0
},
{
"x": 348.0,
"y": 194.0
},
{
"x": 348.0,
"y": 266.0
},
{
"x": 286.0,
"y": 266.0
}
]
}
]
}
],
"mobile": [
{
"text": "010-1234-5678",
"boundingPolys": [
{
"vertices": [
{
"x": 297.0,
"y": 183.0
},
{
"x": 396.0,
"y": 183.0
},
{
"x": 396.0,
"y": 305.0
},
{
"x": 297.0,
"y": 305.0
}
]
}
]
}
],
"tel": [
{
"text": "123-4567-8901",
"boundingPolys": [
{
"vertices": [
{
"x": 338.0,
"y": 189.0
},
{
"x": 414.0,
"y": 189.0
},
{
"x": 414.0,
"y": 288.0
},
{
"x": 338.0,
"y": 288.0
}
]
}
]
}
],
"fax": [],
"email": [],
"homepage": []
}
},
"uid": "3277149ad2324de0b412669f7eac474a",
"name": "testV2Demo",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}
]
}
ID card response examples
{
"version": "V2",
"requestId": "string",
"timestamp": 1613984543939,
"images": [
{
"idCard": {
"meta": {
"estimatedLanguage": "ko"
},
"result": {
"isConfident": true,
"ic": {
"name": [
{
"text": "Sonic",
"formatted": {
"value": "Sonic"
},
"boundingPolys": [
{
"vertices": [
{
"x": 93.0,
"y": 135.0
},
{
"x": 257.0,
"y": 135.0
},
{
"x": 257.0,
"y": 161.0
},
{
"x": 93.0,
"y": 161.0
}
]
}
]
}
],
"personalNum": [
{
"text": "910623-1062372",
"formatted": {
"value": "910623-1062372"
},
"boundingPolys": [
{
"vertices": [
{
"x": 83.0,
"y": 166.0
},
{
"x": 260.0,
"y": 166.0
},
{
"x": 260.0,
"y": 186.0
},
{
"x": 83.0,
"y": 186.0
}
]
}
]
}
],
"address": [
{
"text": "Le Meilleur Jongno Town, 24, Jongno 1-ga, Jongno-gu, Seoul, Republic of Korea",
"formatted": {
"value": "Le Meilleur Jongno Town, 24, Jongno 1-ga, Jongno-gu, Seoul, Republic of Korea"
},
"boundingPolys": [
{
"vertices": [
{
"x": 43.0,
"y": 232.0
},
{
"x": 148.0,
"y": 232.0
},
{
"x": 148.0,
"y": 255.0
},
{
"x": 43.0,
"y": 255.0
}
]
},
{
"vertices": [
{
"x": 47.0,
"y": 212.0
},
{
"x": 150.0,
"y": 212.0
},
{
"x": 150.0,
"y": 234.0
},
{
"x": 47.0,
"y": 234.0
}
]
},
{
"vertices": [
{
"x": 154.0,
"y": 232.0
},
{
"x": 240.0,
"y": 232.0
},
{
"x": 240.0,
"y": 255.0
},
{
"x": 154.0,
"y": 255.0
}
]
},
{
"vertices": [
{
"x": 156.0,
"y": 212.0
},
{
"x": 219.0,
"y": 212.0
},
{
"x": 219.0,
"y": 234.0
},
{
"x": 156.0,
"y": 234.0
}
]
},
{
"vertices": [
{
"x": 224.0,
"y": 212.0
},
{
"x": 302.0,
"y": 212.0
},
{
"x": 302.0,
"y": 235.0
},
{
"x": 224.0,
"y": 235.0
}
]
},
{
"vertices": [
{
"x": 305.0,
"y": 213.0
},
{
"x": 333.0,
"y": 213.0
},
{
"x": 333.0,
"y": 234.0
},
{
"x": 305.0,
"y": 234.0
}
]
}
]
}
],
"issueDate": [
{
"text": "2011.3. 6.",
"formatted": {
"year": "2011",
"month": "03",
"day": "06"
},
"boundingPolys": [
{
"vertices": [
{
"x": 261.0,
"y": 314.0
},
{
"x": 351.0,
"y": 314.0
},
{
"x": 351.0,
"y": 336.0
},
{
"x": 261.0,
"y": 336.0
}
]
},
{
"vertices": [
{
"x": 354.0,
"y": 314.0
},
{
"x": 376.0,
"y": 314.0
},
{
"x": 376.0,
"y": 334.0
},
{
"x": 354.0,
"y": 334.0
}
]
}
]
}
],
"authority": [
{
"text": "Sodeok, Chairperson of the Sonic Presidential Campaign Committee",
"formatted": {
"Value": "Sodeok, Chairperson of the Sonic Presidential Campaign Committee"
},
"boundingPolys": [
{
"vertices": [
{
"x": 172.0,
"y": 338.0
},
{
"x": 346.0,
"y": 338.0
},
{
"x": 346.0,
"y": 366.0
},
{
"x": 172.0,
"y": 366.0
}
]
},
{
"vertices": [
{
"x": 347.0,
"y": 338.0
},
{
"x": 435.0,
"y": 336.0
},
{
"x": 435.0,
"y": 363.0
},
{
"x": 348.0,
"y": 365.0
}
]
}
]
}
]
},
"idtype": "ID Card"
}
},
"uid": "0012374f247f4e70966d35eaa3c41d2a",
"name": "testV2Demo",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}
]
}
Passport response examples
{
"version": "V2",
"requestId": "string",
"timestamp": 1684203696126,
"images": [
{
"passport": {
"passportResult": {
"documentClassCode": {
"rawText": "P<",
"refinedText": "Passport",
"postprocessed": [
1
]
},
"issuingStateCode": {
"rawText": "KOR",
"refinedText": "Korea (the Republic of)",
"postprocessed": []
},
"firstName": {
"rawText": "HONG",
"refinedText": "HONG",
"postprocessed": []
},
"lastName1": {
"rawText": "GILSOON",
"refinedText": "GILSOON",
"postprocessed": []
},
"lastName2": {
"rawText": "-",
"refinedText": "-",
"postprocessed": []
},
"documentNumber": {
"rawText": "M123A4567",
"refinedText": "M123A4567",
"postprocessed": []
},
"checkDigitForDocumentNumber": {
"rawText": "0",
"refinedText": "0",
"postprocessed": []
},
"nationality": {
"rawText": "KOR",
"refinedText": "Korea (the Republic of)",
"postprocessed": []
},
"dateOfBirth": {
"rawText": "870201",
"refinedText": "1987/02/01",
"postprocessed": []
},
"age": {
"rawText": "",
"refinedText": 36,
"postprocessed": []
},
"checkDigitForDateOfBirth": {
"rawText": "0",
"refinedText": "0",
"postprocessed": []
},
"gender": {
"rawText": "F",
"refinedText": "Female",
"postprocessed": []
},
"dateOfExpiry": {
"rawText": "300815",
"refinedText": "2030/08/15",
"postprocessed": []
},
"checkDigitForDateOfExpiry": {
"rawText": "0",
"refinedText": "0",
"postprocessed": []
},
"personalNumber": {
"rawText": "V2000000000000",
"refinedText": "V2000000000000",
"postprocessed": []
},
"checkDigitForPersonalNumber": {
"rawText": "0",
"refinedText": "0",
"postprocessed": []
},
"finalCheckDigit": {
"rawText": "0",
"refinedText": "0",
"postprocessed": []
},
"mrzType": {
"rawText": "",
"refinedText": "ID-3",
"postprocessed": []
},
"mrzLines": {
"rawText": "PMKORHONG<<GILSOON<<<<<<<<<<<<<<<<<<<<<<<<<<<<\nM123A45670KOR8702010F3008150V20000000000000000",
"refinedText": "PMKORHONG<<GILSOON<<<<<<<<<<<<<<<<<<<<<<<<<<<<\nM123A45670KOR8702010F3008150V20000000000000000",
"postprocessed": [
1
]
},
"isExpired": {
"rawText": "",
"refinedText": false,
"postprocessed": []
}
}
},
"uid": "8f8a04985a6e429e97c3ca4184b3c0e4",
"name": "test 1",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}
]
}
API examples
The following are some examples of CLOVA OCR API implementation for each language.
- Request with multipart/form-data
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONObject;
public class OCRAPIDemo {
public static void main(String[] args) {
String apiURL = "YOUR_API_URL";
String secretKey = "YOUR_SECRET_KEY";
String imageFile = "YOUR_IMAGE_FILE";
try {
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setReadTimeout(30000);
con.setRequestMethod("POST");
String boundary = "----" + UUID.randomUUID().toString().replaceAll("-", "");
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
con.setRequestProperty("X-OCR-SECRET", secretKey);
JSONObject json = new JSONObject();
json.put("version", "V2");
json.put("requestId", UUID.randomUUID().toString());
json.put("timestamp", System.currentTimeMillis());
JSONObject image = new JSONObject();
image.put("format", "jpg");
image.put("name", "demo");
JSONArray images = new JSONArray();
images.put(image);
json.put("images", images);
String postParams = json.toString();
con.connect();
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
long start = System.currentTimeMillis();
File file = new File(imageFile);
writeMultiPart(wr, postParams, file, boundary);
wr.close();
int responseCode = con.getResponseCode();
BufferedReader br;
if (responseCode == 200) {
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else {
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
br.close();
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
private static void writeMultiPart(OutputStream out, String jsonMessage, File file, String boundary) throws
IOException {
StringBuilder sb = new StringBuilder();
sb.append("--").append(boundary).append("\r\n");
sb.append("Content-Disposition:form-data; name=\"message\"\r\n\r\n");
sb.append(jsonMessage);
sb.append("\r\n");
out.write(sb.toString().getBytes("UTF-8"));
out.flush();
if (file != null && file.isFile()) {
out.write(("--" + boundary + "\r\n").getBytes("UTF-8"));
StringBuilder fileString = new StringBuilder();
fileString
.append("Content-Disposition:form-data; name=\"file\"; filename=");
fileString.append("\"" + file.getName() + "\"\r\n");
fileString.append("Content-Type: application/octet-stream\r\n\r\n");
out.write(fileString.toString().getBytes("UTF-8"));
out.flush();
try (FileInputStream fis = new FileInputStream(file)) {
byte[] buffer = new byte[8192];
int count;
while ((count = fis.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
out.write("\r\n".getBytes());
}
out.write(("--" + boundary + "--\r\n").getBytes("UTF-8"));
}
out.flush();
}
}
import requests
import uuid
import time
import json
api_url = 'YOUR_API_URL'
secret_key = 'YOUR_SECRET_KEY'
image_file = 'YOUR_IMAGE_FILE'
request_json = {
'images': [
{
'format': 'jpg',
'name': 'demo'
}
],
'requestId': str(uuid.uuid4()),
'version': 'V2',
'timestamp': int(round(time.time() * 1000))
}
payload = {'message': json.dumps(request_json).encode('UTF-8')}
files = [
('file', open(image_file,'rb'))
]
headers = {
'X-OCR-SECRET': secret_key
}
response = requests.request("POST", api_url, headers=headers, data = payload, files = files)
print(response.text.encode('utf8'))
<?php
$client_secret = "YOUR_SECRET_KEY";
$url = "YOUR_API_URL";
$image_file = "YOUR_IMAGE_FILE";
$params->version = "V2";
$params->requestId = uniqid();
$params->timestamp = time();
$image->format = "jpg";
$image->name = "demo";
$images = array($image);
$params->images = $images;
$json = json_encode($params);
$boundary = uniqid();
$is_post = true;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$post_form = array("message" => $json, "file" => new CURLFILE($image_file));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_form);
$headers = array();
$headers[] = "X-OCR-SECRET: ".$client_secret;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$err = curl_error($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
echo $status_code;
if($status_code == 200) {
echo $response;
} else {
echo "ERROR: ".$response;
}
?>
- Request with application/json
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONObject;
public class OCRGeneralAPIDemo {
public static void main(String[] args) {
String apiURL = "YOUR_API_URL";
String secretKey = "YOUR_SECRET_KEY";
try {
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; charset=utf-8");
con.setRequestProperty("X-OCR-SECRET", secretKey);
JSONObject json = new JSONObject();
json.put("version", "V2");
json.put("requestId", UUID.randomUUID().toString());
json.put("timestamp", System.currentTimeMillis());
JSONObject image = new JSONObject();
image.put("format", "jpg");
image should be public, otherwise, should use data
FileInputStream inputStream = new FileInputStream("YOUR_IMAGE_FILE");
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
inputStream.close();
image.put("data", buffer);
image.put("name", "demo");
JSONArray images = new JSONArray();
images.put(image);
json.put("images", images);
String postParams = json.toString();
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(postParams);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
BufferedReader br;
if (responseCode == 200) {
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else {
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
br.close();
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
}
import requests
import uuid
import time
import base64
import json
api_url = 'YOUR_API_URL'
secret_key = 'YOUR_SECRET_KEY'
image_file = 'YOUR_IMAGE_FILE'
with open(image_file,'rb') as f:
file_data = f.read()
request_json = {
'images': [
{
'format': 'jpg',
'name': 'demo',
'data': base64.b64encode(file_data).decode()
}
],
'requestId': str(uuid.uuid4()),
'version': 'V2',
'timestamp': int(round(time.time() * 1000))
}
payload = json.dumps(request_json).encode('UTF-8')
headers = {
'X-OCR-SECRET': secret_key,
'Content-Type': 'application/json'
}
response = requests.request("POST", api_url, headers=headers, data = payload)
print(response.text)
<?php
$client_secret = "YOUR_SECRET_KEY";
$url = "YOUR_API_URL";
$image_file = "YOUR_IMAGE_FILE";
$params->version = "V2";
$params->requestId = "uuid";
$params->timestamp = time();
$image->format = "jpg";
$image->data = base64_encode(file_get_contents($image_file));
$image->name = "demo";
$images = array($image);
$params->images = $images;
$json = json_encode($params);
$is_post = true;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$headers = array();
$headers[] = "X-OCR-SECRET: ".$client_secret;
$headers[] = "Content-Type:application/json; charset=utf-8";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$err = curl_error($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
echo $status_code;
if($status_code == 200) {
echo $response;
} else {
echo "ERROR: ".$response;
}
?>
Error code
HttpStatusCode | Description |
---|---|
400 | The requested medium variable is invalid or there are issues with limitation conditions. |
401 | Erroneous API secret key (X-OCR-API-KEY) |
500 | Internal server error |
Error Response Body:
{
"code": "Error Code",
"message": "error details message.",
"path": "request API path",
"timestamp": 1570776853475
}
ErrorCode | Description |
---|---|
0001 | Invalid URL |
0002 | Secret key validity test failed. |
0011 | Invalid request body. |
0021 | Unsupported protocol version. |
0022 | Invalid request domain. |
0023 | The number of API requests has reached the upper limit. |
0025 | Calls to this API have exceeded the rate limit. |
0500 | Unknown service error. |
0501 | OCR service error. |