# OCR a base64-encoded string POST https://api-sandbox.payabli.com/api/Import/ocrDocumentJson/{typeResult} Content-Type: application/json Use this endpoint to submit a Base64-encoded image file for OCR processing. The accepted file formats include PDF, JPG, JPEG, PNG, and GIF. Specify the desired type of result (either 'bill' or 'invoice') in the path parameter `typeResult`. The response will contain the OCR processing results, including extracted data such as bill number, vendor information, bill items, and more. Reference: https://docs.payabli.com/developers/api-reference/import/ocr-a-base64-encoded-string ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Ocr Document Json version: endpoint_ocr.OcrDocumentJson paths: /Import/ocrDocumentJson/{typeResult}: post: operationId: ocr-document-json summary: Ocr Document Json description: >- Use this endpoint to submit a Base64-encoded image file for OCR processing. The accepted file formats include PDF, JPG, JPEG, PNG, and GIF. Specify the desired type of result (either 'bill' or 'invoice') in the path parameter `typeResult`. The response will contain the OCR processing results, including extracted data such as bill number, vendor information, bill items, and more. tags: - - subpackage_ocr parameters: - name: typeResult in: path required: true schema: $ref: '#/components/schemas/type_ocr:typeResult' - name: requestToken in: header required: true schema: type: string responses: '200': description: OCR document processing result content: application/json: schema: $ref: '#/components/schemas/type_ocr:PayabliApiResponseOCR' requestBody: description: Base64-encoded file content for OCR processing content: application/json: schema: $ref: '#/components/schemas/type_ocr:FileContentImageOnly' components: schemas: type_ocr:typeResult: type: string type_:FileContentFtype: type: string enum: - value: pdf - value: doc - value: docx - value: jpg - value: jpeg - value: png - value: gif - value: txt type_ocr:FileContentImageOnly: type: object properties: ftype: $ref: '#/components/schemas/type_:FileContentFtype' filename: type: string description: The name of the file to be uploaded furl: type: string description: Optional URL link to the file fContent: type: string description: Base64-encoded file content type_:IsSuccess: type: boolean type_:ResponseText: type: string type_:Responsecode: type: integer type_ocr:OcrBillItem: type: object properties: itemTotalAmount: type: number format: double itemTaxAmount: type: number format: double itemTaxRate: type: number format: double itemProductCode: type: string itemProductName: type: string itemDescription: type: string itemCommodityCode: type: string itemUnitOfMeasure: type: string itemCost: type: number format: double itemQty: type: integer itemMode: type: integer itemCategories: type: array items: type: string type_ocr:OcrBillItemAdditionalData: type: object properties: category: type: string currency_code: type: string type: type: string reference_number: type: string type_:Email: type: string format: email type_:AdditionalDataString: type: string type_:Contacts: type: object properties: contactEmail: $ref: '#/components/schemas/type_:Email' description: Contact email address. contactName: type: string description: Contact name. contactPhone: type: string description: Contact phone number. contactTitle: type: string description: Contact title. additionalData: $ref: '#/components/schemas/type_:AdditionalDataString' type_ocr:OcrVendorBillingData: type: object properties: id: type: integer bankName: type: string routingAccount: type: string accountNumber: type: string typeAccount: type: string bankAccountHolderName: type: string bankAccountHolderType: type: string bankAccountFunction: type: integer type_ocr:OcrVendorAdditionalData: type: object properties: web: type: string type_ocr:OcrVendor: type: object properties: vendorNumber: type: string name1: type: string name2: type: string ein: type: string phone: type: string email: type: string address1: type: string address2: type: string city: type: string state: type: string zip: type: string country: type: string mcc: type: string locationCode: type: string contacts: type: array items: $ref: '#/components/schemas/type_:Contacts' billingData: $ref: '#/components/schemas/type_ocr:OcrVendorBillingData' paymentMethod: type: string vendorStatus: type: integer remitAddress1: type: string remitAddress2: type: string remitCity: type: string remitState: type: string remitZip: type: string remitCountry: type: string payeeName1: type: string payeeName2: type: string customerVendorAccount: type: string internalReferenceId: type: integer format: int64 customField1: type: string customField2: type: string additionalData: $ref: '#/components/schemas/type_ocr:OcrVendorAdditionalData' type_ocr:OcrAttachment: type: object properties: ftype: type: string filename: type: string fileDescriptor: type: string furl: type: string fContent: type: string type_ocr:OcrResultData: type: object properties: billNumber: type: string netAmount: type: number format: double billDate: type: string format: date-time dueDate: type: string format: date-time comments: type: string billItems: type: array items: $ref: '#/components/schemas/type_ocr:OcrBillItem' mode: type: integer accountingField1: type: string accountingField2: type: string additionalData: $ref: '#/components/schemas/type_ocr:OcrBillItemAdditionalData' vendor: $ref: '#/components/schemas/type_ocr:OcrVendor' endDate: type: string format: date-time frequency: type: string terms: type: string status: type: integer lotNumber: type: string attachments: type: array items: $ref: '#/components/schemas/type_ocr:OcrAttachment' type_ocr:OcrResponseData: type: object properties: resultData: $ref: '#/components/schemas/type_ocr:OcrResultData' type_ocr:PayabliApiResponseOCR: type: object properties: isSuccess: $ref: '#/components/schemas/type_:IsSuccess' responseText: $ref: '#/components/schemas/type_:ResponseText' responseCode: $ref: '#/components/schemas/type_:Responsecode' responseData: $ref: '#/components/schemas/type_ocr:OcrResponseData' description: Details of the OCR processing result required: - isSuccess - responseText - responseCode ``` ## SDK Code Examples ```typescript import { PayabliClient, PayabliEnvironment } from "@payabli/sdk-node"; async function main() { const client = new PayabliClient({ environment: PayabliEnvironment.Sandbox, apiKey: "YOUR_API_KEY_HERE", }); await client.ocr.ocrDocumentJson("typeResult", {}); } main(); ``` ```python from payabli import payabli from payabli.environment import payabliEnvironment client = payabli( environment=payabliEnvironment.SANDBOX, api_key="YOUR_API_KEY_HERE" ) client.ocr.ocr_document_json( type_result="typeResult" ) ``` ```csharp using PayabliApi; using System.Threading.Tasks; namespace Usage; public class Example { public async Task Do() { var client = new PayabliApiClient( apiKey: "YOUR_API_KEY_HERE", clientOptions: new ClientOptions { BaseUrl = PayabliApiEnvironment.Sandbox } ); await client.Ocr.OcrDocumentJsonAsync( "typeResult", new FileContentImageOnly() ); } } ``` ```go package example import ( client "github.com/payabli/sdk-go/v/client" option "github.com/payabli/sdk-go/v/option" payabli "github.com/payabli/sdk-go/v" context "context" ) func do() { client := client.NewClient( option.WithBaseURL( payabli.Environments.Sandbox, ), option.WithApiKey( "YOUR_API_KEY_HERE", ), ) request := &payabli.FileContentImageOnly{} client.Ocr.OcrDocumentJson( context.TODO(), "typeResult", request, ) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api-sandbox.payabli.com/api/Import/ocrDocumentJson/typeResult") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["requestToken"] = '' request["Content-Type"] = 'application/json' request.body = "{}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api-sandbox.payabli.com/api/Import/ocrDocumentJson/typeResult") .header("requestToken", "") .header("Content-Type", "application/json") .body("{}") .asString(); ``` ```php request('POST', 'https://api-sandbox.payabli.com/api/Import/ocrDocumentJson/typeResult', [ 'body' => '{}', 'headers' => [ 'Content-Type' => 'application/json', 'requestToken' => '', ], ]); echo $response->getBody(); ``` ```swift import Foundation let headers = [ "requestToken": "", "Content-Type": "application/json" ] let parameters = [] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api-sandbox.payabli.com/api/Import/ocrDocumentJson/typeResult")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```