> This is Payabli documentation. For a complete page index, fetch https://docs.payabli.com/llms.txt — append .md to any page URL for lightweight markdown. For section-level indexes, query parameters, and other AI-optimized access methods, see https://docs.payabli.com/ai-agents.md

# 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.0
info:
  title: payabliApi-oas
  version: 1.0.0
paths:
  /Import/ocrDocumentJson/{typeResult}:
    post:
      operationId: OcrDocumentJson
      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:
        - Ocr
      parameters:
        - name: typeResult
          in: path
          description: >-
            The type of object to create in Payabli. Accepted values are `bill`
            and `invoice`.
          required: true
          schema:
            $ref: '#/components/schemas/typeResult'
        - name: requestToken
          in: header
          description: >
            Long-lived API token sent in the `requestToken` header. See [API
            token authentication](/developers/api-tokens).
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OCR document processing result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PayabliApiResponseOCR'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FileContentImageOnly'
servers:
  - url: https://api-sandbox.payabli.com/api
    description: Sandbox
  - url: https://api.payabli.com/api
    description: Production
components:
  schemas:
    typeResult:
      type: string
      description: >-
        The type of object to create in Payabli. Accepted values are `bill` and
        `invoice`.
      title: typeResult
    FileContentFtype:
      type: string
      enum:
        - pdf
        - doc
        - docx
        - jpg
        - jpeg
        - png
        - gif
        - txt
      description: The MIME type of the file (if content is provided).
      title: FileContentFtype
    FileContentImageOnly:
      type: object
      properties:
        ftype:
          $ref: '#/components/schemas/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
      title: FileContentImageOnly
    IsSuccess:
      type: boolean
      description: |
        Boolean indicating whether the operation was successful. A `true` value
        indicates success. A `false` value indicates failure.
      title: IsSuccess
    ResponseText:
      type: string
      description: |
        Response text for operation: 'Success' or 'Declined'.
      title: ResponseText
    Responsecode:
      type: integer
      description: |
        Code for the response. Learn more in
        [API Response Codes](/developers/api-reference/api-responses).
      title: Responsecode
    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
      title: OcrBillItem
    OcrBillItemAdditionalData:
      type: object
      properties:
        category:
          type: string
        currency_code:
          type: string
        type:
          type: string
        reference_number:
          type: string
      title: OcrBillItemAdditionalData
    Email:
      type: string
      format: email
      description: Email address.
      title: Email
    AdditionalDataString:
      type: string
      description: >
        Custom dictionary of key:value pairs. You can use this field to store
        any

        data related to the object or for your system. Example usage:


        ```json

        {
          "additionalData": {
            "key1": "value1",
            "key2": "value2",
            "key3": "value3"
          }
        }

        ```
      title: AdditionalDataString
    Contacts:
      type: object
      properties:
        contactEmail:
          $ref: '#/components/schemas/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/AdditionalDataString'
      title: Contacts
    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
      title: OcrVendorBillingData
    OcrVendorAdditionalData:
      type: object
      properties:
        web:
          type: string
      title: OcrVendorAdditionalData
    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/Contacts'
        billingData:
          $ref: '#/components/schemas/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/OcrVendorAdditionalData'
      title: OcrVendor
    OcrAttachment:
      type: object
      properties:
        ftype:
          type: string
        filename:
          type: string
        fileDescriptor:
          type: string
        furl:
          type: string
        fContent:
          type: string
      title: OcrAttachment
    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/OcrBillItem'
        mode:
          type: integer
        accountingField1:
          type: string
        accountingField2:
          type: string
        additionalData:
          $ref: '#/components/schemas/OcrBillItemAdditionalData'
        vendor:
          $ref: '#/components/schemas/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/OcrAttachment'
      title: OcrResultData
    OcrResponseData:
      type: object
      properties:
        resultData:
          $ref: '#/components/schemas/OcrResultData'
      title: OcrResponseData
    PayabliApiResponseOCR:
      type: object
      properties:
        isSuccess:
          $ref: '#/components/schemas/IsSuccess'
        responseText:
          $ref: '#/components/schemas/ResponseText'
        responseCode:
          $ref: '#/components/schemas/Responsecode'
        responseData:
          $ref: '#/components/schemas/OcrResponseData'
          description: Details of the OCR processing result
      required:
        - isSuccess
        - responseText
        - responseCode
      title: PayabliApiResponseOCR
  securitySchemes:
    APIKeyAuth:
      type: apiKey
      in: header
      name: requestToken
      description: >
        Long-lived API token sent in the `requestToken` header. See [API token
        authentication](/developers/api-tokens).
    BearerAuth:
      type: http
      scheme: bearer
      description: >
        OAuth2 Bearer access token from the client-credentials flow. See [OAuth
        authentication](/developers/oauth-authentication).

```

## Examples



**Request**

```json
{}
```

**Response**

```json
{
  "isSuccess": true,
  "responseText": "string",
  "responseCode": 1,
  "responseData": {
    "resultData": {
      "billNumber": "string",
      "netAmount": 1.1,
      "billDate": "2024-01-15T09:30:00Z",
      "dueDate": "2024-01-15T09:30:00Z",
      "comments": "string",
      "billItems": [
        {
          "itemTotalAmount": 1.1,
          "itemTaxAmount": 1.1,
          "itemTaxRate": 1.1,
          "itemProductCode": "string",
          "itemProductName": "string",
          "itemDescription": "string",
          "itemCommodityCode": "string",
          "itemUnitOfMeasure": "string",
          "itemCost": 1.1,
          "itemQty": 1,
          "itemMode": 1,
          "itemCategories": [
            "string"
          ]
        }
      ],
      "mode": 1,
      "accountingField1": "string",
      "accountingField2": "string",
      "additionalData": {
        "category": "string",
        "currency_code": "string",
        "type": "string",
        "reference_number": "string"
      },
      "vendor": {
        "vendorNumber": "string",
        "name1": "string",
        "name2": "string",
        "ein": "string",
        "phone": "string",
        "email": "string",
        "address1": "string",
        "address2": "string",
        "city": "string",
        "state": "string",
        "zip": "string",
        "country": "string",
        "mcc": "string",
        "locationCode": "string",
        "contacts": [
          {
            "contactEmail": "string",
            "contactName": "string",
            "contactPhone": "string",
            "contactTitle": "string",
            "additionalData": "string"
          }
        ],
        "billingData": {
          "id": 1,
          "bankName": "string",
          "routingAccount": "string",
          "accountNumber": "string",
          "typeAccount": "string",
          "bankAccountHolderName": "string",
          "bankAccountHolderType": "string",
          "bankAccountFunction": 1
        },
        "paymentMethod": "string",
        "vendorStatus": 1,
        "remitAddress1": "string",
        "remitAddress2": "string",
        "remitCity": "string",
        "remitState": "string",
        "remitZip": "string",
        "remitCountry": "string",
        "payeeName1": "string",
        "payeeName2": "string",
        "customerVendorAccount": "string",
        "internalReferenceId": 1,
        "customField1": "string",
        "customField2": "string",
        "additionalData": {
          "web": "string"
        }
      },
      "endDate": "2024-01-15T09:30:00Z",
      "frequency": "string",
      "terms": "string",
      "status": 1,
      "lotNumber": "string",
      "attachments": [
        {
          "ftype": "string",
          "filename": "string",
          "fileDescriptor": "string",
          "furl": "string",
          "fContent": "string"
        }
      ]
    }
  }
}
```

**SDK Code**

```typescript
import { PayabliClient } from "@payabli/sdk-node";

async function main() {
    const client = new PayabliClient({
        apiKey: "YOUR_API_KEY_HERE",
    });
    await client.ocr.ocrDocumentJson("typeResult", {});
}
main();

```

```python
from payabli import payabli

client = payabli(
    api_key="YOUR_API_KEY_HERE",
)

client.ocr.ocr_document_json(
    type_result="typeResult",
)

```

```java
package com.example.usage;

import io.github.payabli.api.PayabliPayabliApiOasClient;
import io.github.payabli.api.types.FileContentImageOnly;

public class Example {
    public static void main(String[] args) {
        PayabliPayabliApiOasClient client = PayabliPayabliApiOasClient
            .builder()
            .apiKey("YOUR_API_KEY_HERE")
            .build();

        client.ocr().ocrDocumentJson(
            "typeResult",
            FileContentImageOnly
                .builder()
                .build()
        );
    }
}
```

```ruby
require "payabli"

client = Payabli::Client.new(api_key: "YOUR_API_KEY_HERE")

client.ocr.ocr_document_json(type_result: "typeResult")

```

```csharp
using PayabliPayabliApiOas;
using System.Threading.Tasks;

namespace Usage;

public class Example
{
    public async Task Do() {
        var client = new PayabliPayabliApiOasClient(
            apiKey: "YOUR_API_KEY_HERE"
        );

        await client.Ocr.OcrDocumentJsonAsync(
            "typeResult",
            new FileContentImageOnly()
        );
    }

}

```

```go
package example

import (
    context "context"

    payabli "github.com/payabli/sdk-go"
    client "github.com/payabli/sdk-go/client"
    option "github.com/payabli/sdk-go/option"
)

func do() {
    client := client.NewClient(
        option.WithApiKey(
            "YOUR_API_KEY_HERE",
        ),
    )
    request := &payabli.FileContentImageOnly{}
    client.Ocr.OcrDocumentJson(
        context.TODO(),
        "typeResult",
        request,
    )
}

```

```php
<?php

namespace Example;

use Payabli\PayabliClient;
use Payabli\Types\FileContentImageOnly;

$client = new PayabliClient(
    apiKey: 'YOUR_API_KEY_HERE',
);
$client->ocr->ocrDocumentJson(
    'typeResult',
    new FileContentImageOnly([]),
);

```

```swift
import Foundation

let headers = [
  "requestToken": "<apiKey>",
  "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()
```