Templates
Template กำหนดวิธีที่ AI ดึงข้อมูลจากเอกสาร — ฟิลด์ใน Schema, คำสั่ง และรูปแบบ Output Endpoint ของ Template ให้คุณจัดการ Template แบบ Programmatic รวมถึงการอัปโหลดไฟล์ข้อมูลอ้างอิงที่ช่วยแนะนำ AI ระหว่างการดึงข้อมูล
รายการ Templates
GET /v1/openapi/templatesคืน Template ทั้งหมดที่ Token เข้าถึงได้ Organization Token จะคืน Template จากทุก Project ใน Organization ส่วน Project Token จะคืนเฉพาะ Template ของ Project นั้น
Headers:
| Header | Value | Required |
|---|---|---|
X-API-Key | ocr_your_api_key | Yes |
Example Request:
curl "https://api.ocriva.com/v1/openapi/templates" \
-H "X-API-Key: ocr_your_api_key"Example Response (200 OK):
[
{
"templateId": "68db4bb3a67e9c04fb0c6f85",
"name": "Invoice Template",
"description": "Extract structured data from invoices including line items, totals, and vendor details",
"templateSchema": {
"invoiceNumber": { "type": "string", "description": "Invoice number" },
"totalAmount": { "type": "number", "description": "Total invoice amount" },
"vendor": { "type": "string", "description": "Vendor name" }
},
"projectId": "68db4aa2967d9c03fa9b5e74",
"isActive": true,
"resultFormat": "json",
"extractionMode": "structured",
"createdAt": "2026-01-15T08:00:00.000Z",
"updatedAt": "2026-03-20T14:30:00.000Z"
}
]สร้าง Template
POST /v1/openapi/templatesสร้าง Extraction Template ใหม่สำหรับ Project
Headers:
| Header | Value | Required |
|---|---|---|
X-API-Key | ocr_your_api_key | Yes |
Content-Type | application/json | Yes |
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | ชื่อ Template (เช่น Receipt) |
description | string | Yes | คำอธิบายว่า Template นี้ดึงข้อมูลอะไร |
templateSchema | object | Yes | JSON Schema ที่กำหนดฟิลด์ที่ต้องการดึงข้อมูล |
projectId | string | Yes | ID ของ Project เป้าหมาย |
instructions | string | No | คำสั่งเพิ่มเติมสำหรับ AI |
Example Request:
curl -X POST "https://api.ocriva.com/v1/openapi/templates" \
-H "X-API-Key: ocr_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Receipt",
"description": "Extract structured data from receipts including merchant information, items purchased, amounts, and payment details",
"projectId": "68db4aa2967d9c03fa9b5e74",
"templateSchema": {
"merchantName": {
"type": "string",
"description": "Name of the merchant or store"
},
"totalAmount": {
"type": "number",
"description": "Total amount paid including tax"
},
"date": {
"type": "string",
"description": "Date of the transaction (YYYY-MM-DD)"
},
"items": {
"type": "array",
"description": "List of purchased items"
}
},
"instructions": "You are an expert in document analysis. Extract all fields accurately."
}'Example Response (201 Created):
{
"templateId": "68db4bb3a67e9c04fb0c6f85",
"name": "Receipt",
"description": "Extract structured data from receipts including merchant information, items purchased, amounts, and payment details",
"templateSchema": {
"merchantName": { "type": "string", "description": "Name of the merchant or store" },
"totalAmount": { "type": "number", "description": "Total amount paid including tax" },
"date": { "type": "string", "description": "Date of the transaction (YYYY-MM-DD)" },
"items": { "type": "array", "description": "List of purchased items" }
},
"projectId": "68db4aa2967d9c03fa9b5e74",
"isActive": true,
"createdAt": "2026-03-31T10:00:00.000Z",
"updatedAt": "2026-03-31T10:00:00.000Z"
}อัปเดต Template
PUT /v1/openapi/templates/:idอัปเดต Template ที่มีอยู่ โดยเปลี่ยนเฉพาะ Field ที่ส่งมาเท่านั้น
Path Parameters:
| Parameter | Description |
|---|---|
id | ID ของ Template ที่ต้องการอัปเดต |
Headers:
| Header | Value | Required |
|---|---|---|
X-API-Key | ocr_your_api_key | Yes |
Content-Type | application/json | Yes |
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
projectId | string | Yes | ID ของ Project ที่ Template นี้สังกัด |
name | string | No | ชื่อ Template ที่อัปเดต |
description | string | No | คำอธิบายที่อัปเดต |
templateSchema | object | No | Schema ที่อัปเดต |
instructions | string | No | คำสั่ง AI ที่อัปเดต |
Example Request:
curl -X PUT "https://api.ocriva.com/v1/openapi/templates/68db4bb3a67e9c04fb0c6f85" \
-H "X-API-Key: ocr_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"projectId": "68db4aa2967d9c03fa9b5e74",
"name": "Receipt Updated",
"description": "Updated description for receipt processing"
}'Example Response (200 OK):
{
"templateId": "68db4bb3a67e9c04fb0c6f85",
"name": "Receipt Updated",
"description": "Updated description for receipt processing",
"templateSchema": {
"merchantName": { "type": "string", "description": "Name of the merchant or store" },
"totalAmount": { "type": "number", "description": "Total amount paid including tax" }
},
"projectId": "68db4aa2967d9c03fa9b5e74",
"isActive": true,
"createdAt": "2026-03-31T10:00:00.000Z",
"updatedAt": "2026-03-31T11:15:00.000Z"
}Common Errors:
| Status | Cause |
|---|---|
401 | Template ไม่ได้อยู่ใน Project หรือ Organization ของ Token |
404 | ไม่พบ Template |
ลบ Template
DELETE /v1/openapi/templates/:idลบ Template แบบ Soft Delete โดย Template จะถูกตั้งสถานะ Inactive และไม่ปรากฏใน Response ของการดึงรายการอีกต่อไป แต่ Processing Record ที่อ้างอิง Template นี้ยังคงเก็บไว้ครบถ้วน
Path Parameters:
| Parameter | Description |
|---|---|
id | ID ของ Template ที่ต้องการลบ |
Headers:
| Header | Value | Required |
|---|---|---|
X-API-Key | ocr_your_api_key | Yes |
Example Request:
curl -X DELETE "https://api.ocriva.com/v1/openapi/templates/68db4bb3a67e9c04fb0c6f85" \
-H "X-API-Key: ocr_your_api_key"Example Response (200 OK):
{
"message": "Template deleted successfully"
}Common Errors:
| Status | Cause |
|---|---|
401 | Template ไม่ได้อยู่ใน Project หรือ Organization ของ Token |
404 | ไม่พบ Template |
อัปโหลดไฟล์ข้อมูลไปยัง Template
POST /v1/openapi/templates/:id/filesแนบไฟล์ข้อมูลอ้างอิง (JSON, Markdown หรือ Plain Text) กับ Template AI จะใช้ไฟล์เหล่านี้เป็น Context เพิ่มเติมระหว่างการดึงข้อมูล เช่น Catalog สินค้าหรือรายการรหัสผู้ขาย
Path Parameters:
| Parameter | Description |
|---|---|
id | ID ของ Template ที่ต้องการแนบไฟล์ |
Headers:
| Header | Value | Required |
|---|---|---|
X-API-Key | ocr_your_api_key | Yes |
Content-Type | multipart/form-data | Yes |
Request Body (multipart/form-data):
| Field | Type | Required | Description |
|---|---|---|---|
file | File | Yes | ไฟล์ข้อมูลที่ต้องการแนบ รองรับ: .json, .md, .txt |
Example Request:
curl -X POST "https://api.ocriva.com/v1/openapi/templates/68db4bb3a67e9c04fb0c6f85/files" \
-H "X-API-Key: ocr_your_api_key" \
-F "file=@/path/to/product-catalog.json"Example Response (201 Created):
{
"templateId": "68db4bb3a67e9c04fb0c6f85",
"name": "Receipt",
"description": "Extract structured data from receipts",
"templateSchema": { ... },
"projectId": "68db4aa2967d9c03fa9b5e74",
"isActive": true,
"createdAt": "2026-03-31T10:00:00.000Z",
"updatedAt": "2026-03-31T12:00:00.000Z"
}Common Errors:
| Status | Cause |
|---|---|
400 | ไม่มีไฟล์แนบ หรือประเภทไฟล์ไม่รองรับ |
401 | Template ไม่ได้อยู่ใน Scope ของ Token |
404 | ไม่พบ Template |
ลบไฟล์ข้อมูลออกจาก Template
DELETE /v1/openapi/templates/:id/files/:fileIdลบไฟล์ข้อมูลที่แนบอยู่กับ Template ออก
Path Parameters:
| Parameter | Description |
|---|---|
id | ID ของ Template |
fileId | ID ของไฟล์ข้อมูลที่ต้องการลบ |
Headers:
| Header | Value | Required |
|---|---|---|
X-API-Key | ocr_your_api_key | Yes |
Example Request:
curl -X DELETE "https://api.ocriva.com/v1/openapi/templates/68db4bb3a67e9c04fb0c6f85/files/68dc2dd5c89f1e26fd3b8g02" \
-H "X-API-Key: ocr_your_api_key"Example Response (200 OK):
{
"templateId": "68db4bb3a67e9c04fb0c6f85",
"name": "Receipt",
"description": "Extract structured data from receipts",
"templateSchema": { ... },
"projectId": "68db4aa2967d9c03fa9b5e74",
"isActive": true,
"createdAt": "2026-03-31T10:00:00.000Z",
"updatedAt": "2026-03-31T12:30:00.000Z"
}Common Errors:
| Status | Cause |
|---|---|
401 | Template ไม่ได้อยู่ใน Scope ของ Token |
404 | ไม่พบ Template หรือไฟล์ |
