KWorkItem API¶
V1_KWorkItemAPI is the API group for work item automation. Its 23 actions create a work item, add documents, pages and files, read and upsert metadata, read OCR text, and report state and history. The second half of this page covers the V1_WorkflowAPI actions that work with it: list workflows, start a workflow, release a hold, and read and set global variables.
All actions follow the conventions in the Introduction: POST https://{tenant}/api/{Group}/{Action}, the TempIdentityToken header, a JSON body (or multipart/form-data where marked), and the { Success, MessageKey, Data } envelope. The spec your tenant serves is the final word on every shape.
At a glance
- Token feature Manage Work Items for every
V1_KWorkItemAPIaction; Manage Workflows forV1_WorkflowAPI - Ids A document's id is
Idin API results andDocumentIdin scripts - Values Every metadata value is a string
- Writes Each upsert locks, writes, commits and unlocks the work item for you
- Polling
GetWorkStateno more often than every 1.5 seconds per work item
Actions at a glance¶
| Purpose | Actions |
|---|---|
| Work items | NewWorkItem, GetWorkItem, UpsertWorkItemMetadata, DeleteWorkItem |
| Documents | AddDocument, UpsertDocumentMetadata, RemoveDocument |
| Pages | AddPage, UpsertPageMetadata, AddPagesFromBatchFiles |
| Files | StoreBatchFile, SetDocumentFile, GetDocumentFile, RemoveDocumentFile, GetPageFile |
| OCR | GetDocumentOcrData, GetPageOcrData, SetDocumentOcr, SetPageOcr |
| State and history | GetWorkState, QueryWorkState, GetWorkItemHistory, GetWorkflowHistory |
Workflow (V1_WorkflowAPI) |
GetAllWorkflows, SendToWorkflow, ReleaseHold, SetGlobalVariable, SetSecretGlobalVariable, GetGlobalVariable, GetGlobalVariableMetadata |
Shared shapes¶
MetadataValueDTO¶
One metadata value.
- Bucket and key
BucketandKeyare case-sensitive.Indexholds the indexed fields.Generalholds working values. - Value
Valueis always a string, also for numbers, dates and booleans. - System bucket The upsert actions and
NewWorkItemdrop values in theSystembucket. You cannot writeSystemmetadata through this API.
Work item projection¶
The Data of GetWorkItem:
{
"WorkItemId": "guid",
"Name": "20261007-142233512",
"Metadata": { "Index": { "Vendor": "Gateway Fleet Services LLC" }, "General": { } },
"Documents": [
{
"Id": "guid",
"Index": 0,
"Metadata": { "Index": { }, "General": { "DocTypeId": "guid" } },
"Files": [ { "Id": "guid", "FileName": "invoice.pdf", "Extension": ".pdf", "LocationHash": "...", "Type": "Input" } ],
"Pages": [ { "Id": "guid", "Index": 0, "OriginalFileName": "...", "PageFiles": [ ], "Metadata": { } } ]
}
]
}
- File type File
TypeisInput(what came in),Output(what the platform produced) orOCR. - Page file type Page file
TypeisRaw,CompressedRaw,CompressedScaled,ThumbnailorOCR. - Missing keys A key that a document does not have is absent from its dictionary. Read with a default.
Enum values
The spec documents enum values by name (Input, Completed). In requests, send the name. In responses, accept the name or its number: the numbers follow the order on this page, starting at 0 (Input = 0, Output = 1, OCR = 2; Completed = 0, Error = 1, Available = 2, BeingWorked = 3, Hold = 4, Stopped = 5, New = 6).
Work items¶
NewWorkItem¶
Creates an empty work item. It is not in a workflow yet: add documents, then call V1_WorkflowAPI/SendToWorkflow.
- Body
WorkItemName(string, optional),Metadata(array ofMetadataValueDTO, optional; a value with noBucketgoes toGeneral),WorkingFormat(optional; the same settings as the Configure Working Format step). - Returns
{ "WorkItemId": guid }. - Also sets
General.UploadUser,General.UploadUserToken,General.UploadSource=APIandGeneral.UploadDate. - Retries Not idempotent. A retry creates a second work item, so store the id before the next call.
{ "WorkItemName": "Invoice_20481", "Metadata": [ { "Bucket": "General", "Key": "Source", "Value": "api-import" } ] }
GetWorkItem¶
Reads the whole work item: metadata, documents, files and pages. Reads do not lock the work item.
- Body
WorkItemId(guid). - Returns The work item projection above.
UpsertWorkItemMetadata¶
Adds or overwrites metadata on the work item. Keys you do not send stay as they are. Running it twice gives the same result.
- Body
WorkItemId(guid),Metadata(array ofMetadataValueDTO). - Returns
{ "WorkItemId": guid }. - Routing Workflow routes read work item metadata. Write a routing value here, not only on documents.
{ "WorkItemId": "3f2b8c1e-...", "Metadata": [ { "Bucket": "Index", "Key": "NeedsReview", "Value": "Yes" } ] }
DeleteWorkItem¶
Removes the work item with all its files, state and holds. This cannot be undone.
- Body
WorkItemId(guid). - Returns
{ "WorkItemId": guid }.
Documents¶
AddDocument¶
Adds a document to a work item, with an optional file and optional metadata. multipart/form-data.
- Form fields See the table below.
- Returns
{ "WorkItemId": guid, "DocumentId": guid }. - File The file becomes the document's
Inputfile. The workflow makes the pages later. - Also sets
Index.UploadFileName,Index.UploadDate,General.OriginalFileExtension,General.UploadSource=APIand the upload user keys. - Fails with
File extension not allowed: .extfor a file extension the tenant does not allow.
| Form field | Meaning |
|---|---|
WorkItemId |
The work item id |
File |
The file (optional) |
FileName |
The file name with extension (optional; defaults to the uploaded file's name) |
mimeType |
The MIME type (optional; taken from the upload, or from the extension when the upload says application/octet-stream) |
MetadataParameter |
A JSON string of { "Metadata": [ MetadataValueDTO, ... ] } (optional) |
curl -X POST "https://{tenant}/api/V1_KWorkItemAPI/AddDocument" -H "TempIdentityToken: $KL_API_TOKEN" \
-F "WorkItemId=$WORK_ITEM_ID" -F "File=@Invoice_20481.pdf;type=application/pdf" \
-F 'MetadataParameter={"Metadata":[{"Bucket":"Index","Key":"InvoiceNumber","Value":"20481"}]}'
UpsertDocumentMetadata¶
Adds or overwrites metadata on one document.
- Body
WorkItemId(guid),DocumentId(guid),Metadata(array ofMetadataValueDTO). - Returns
{ "WorkItemId": guid, "DocumentId": guid }.
{ "WorkItemId": "3f2b8c1e-...", "DocumentId": "a91c...", "Metadata": [ { "Bucket": "Index", "Key": "ApprovalStatus", "Value": "Approved" } ] }
RemoveDocument¶
Removes a document from the work item.
- Body
WorkItemId(guid),DocumentId(guid). - Returns No
Data.
Pages¶
AddPage¶
Adds one page to a document, with an optional page file and metadata. multipart/form-data.
- Form fields
WorkItemId,DocumentId,File(a single-page TIFF),FileName,mimeType,MetadataParameter(JSON string, as inAddDocument). - Returns
{ "WorkItemId": guid, "DocumentId": guid, "PageId": guid }. - File Stored as the page's
Rawpage file.
UpsertPageMetadata¶
Adds or overwrites metadata on one page.
- Body
WorkItemId,DocumentId,PageId(guids),Metadata(array ofMetadataValueDTO). - Returns
{ "WorkItemId": guid, "DocumentId": guid, "PageId": guid }.
AddPagesFromBatchFiles¶
Adds pages to a document from files you stored first with StoreBatchFile.
- Body
WorkItemId(guid),DocumentId(guid),BlobPageFileInputs(array, at least one): each item hasInfo(theDatathatStoreBatchFilereturned),PageFileType(for exampleRaw) andPageMetadataToSet(optional array of{ Bucket, Key, Value }). - Returns
{ "WorkItemId": guid, "DocumentId": guid }. - Fails with
No pages were passed in, you must add at least one page with AddPagesFromBatchFiles.for an empty list.
Files¶
StoreBatchFile¶
Uploads a file to the work item's storage without attaching it to a document or page. Use the result in a later call such as AddPagesFromBatchFiles. multipart/form-data.
- Form fields
WorkItemId,File,FileName,mimeType. - Returns A stored file reference:
BlobId,FileNameHint,MimeType,Length,Hashand storage fields. Pass the whole object on.
SetDocumentFile¶
Replaces a document's file. This removes all the document's current files and all its pages, then stores the new file as the Input file. multipart/form-data.
- Form fields
WorkItemId,DocumentId,File(required),FileName,mimeType. - Returns
{ "WorkItemId": guid, "DocumentId": guid, "DocumentFileId": guid }.
GetDocumentFile¶
Downloads one document file.
- Body
WorkItemId,DocumentId,DocumentFileId(guids). The file id isDocuments[].Files[].IdinGetWorkItem. - Returns The file bytes, not an envelope.
Content-Dispositioncarries the file name. On failure you get the 412 envelope.
RemoveDocumentFile¶
Removes one file from a document.
- Body
WorkItemId,DocumentId,DocumentFileId(guids). - Returns No
Data.
GetPageFile¶
Downloads one page file, for example the page image.
- Body
WorkItemId,DocumentId,PageId,PageFileId(guids). The ids are inGetWorkItem(Documents[].Pages[].PageFiles[].Id). - Returns The file bytes, not an envelope.
OCR¶
GetDocumentOcrData¶
Reads the OCR text of every page of a document. OCR exists only after a workflow step has run OCR on the pages.
- Body
WorkItemId(guid),DocumentId(guid),ExceptionIfMissingPageOcr(boolean). Withtrue, the call fails if any page has no OCR. Withfalse, pages with no OCR are left out. - Returns An array of
{ "PageId": guid, "Text": string, "Confidence": number }.Confidenceis 0 to 1.
GetPageOcrData¶
Reads the OCR text of one page.
- Body
WorkItemId,DocumentId,PageId(guids),ExceptionIfMissingPageOcr(boolean). Withfalse, a page with no OCR returnsPageIdwith no text. - Returns
{ "PageId": guid, "Text": string, "Confidence": number }.
SetDocumentOcr¶
Stores OCR that you produced yourself for a whole document.
- Body
WorkItemId,DocumentId,Ocr.Ocris a container:OcrEngineName,Text,Confidence,Bounds(X,Y,Width,Height),ChildrensLevelandChildren. - Children Give one child per page, with
ChildrensLevelset toPage. If the document already has pages, the number of children must equal the number of pages. - Returns
{ "WorkItemId": guid, "DocumentId": guid, "DocumentFileId": guid }.
SetPageOcr¶
Stores OCR that you produced yourself for one page.
- Body
WorkItemId,DocumentId,PageId,Ocr(the same container). - Returns
{ "WorkItemId": guid, "DocumentId": guid, "PageId": guid, "PageFileId": guid }. - Fails with
Page {id} does not exist on doc {id} of WorkItem {id}for a page id that is not on the document.
State and history¶
GetWorkState¶
Reads where a work item is and its status. Use it to wait for a workflow to finish.
- Body
WorkItemId(guid). - Returns
WorkItemName,WorkStatus, andWorkItemwithWorkItemId,RootId,ParentIds,CreatedTime,CurrentWorkflow,CurrentWorkflowVersion,CurrentStep,LastSubmittedTime,LastWorkedTime. - WorkStatus One of
Completed,Error,Available,BeingWorked,Hold,Stopped,New. - Polling Call it no more often than every 1.5 seconds per work item. A faster caller can get a cached state.
QueryWorkState¶
Finds work items by name, status, workflow, last worked time or one Index value. Returns one page.
- Body See the table below.
- Returns An array of
{ WorkItem, WorkItemName, WorkStatus, WorkItemMetadata }. - Scope Results include only work items in workflows the token's user can run. A work item never sent to a workflow does not appear.
- Fails with
API User does not have access to WorkflowID {id}for a workflow the user cannot run.
| Field | Type | Meaning |
|---|---|---|
Skip, Take |
Integers | The page. Send Take greater than 0. |
WorkItemName |
String, optional | Exact name |
WorkStatusFilter |
Optional | A WorkStatus value |
CurrentWorkflowIdFilter |
Guid, optional | One workflow |
LastWorkedTimeFilter |
Date-time, optional | With LastWorkedTimeFilterDirection (GreaterThan or LessThan) |
MetadataKeyFilter, MetadataValueFilter |
Optional | An Index key and the exact value. FilterScope (WorkItem or Document) says where to look. |
MetadataToReturn |
Optional | An array of { Bucket, Key } work item values to return with each result |
GetWorkItemHistory¶
Reads the change events of a work item (documents added, metadata changed, and so on).
- Body
WorkItemId(guid). - Returns An array of
EventIndex,Occurred,EventType,EventParameters(a string),GroupingEventId,GroupEventType,Hash.
GetWorkflowHistory¶
Reads the workflow events of a work item: which steps ran, when, for how long, and the result.
- Body
WorkItemId(guid). - Returns An array of up to 1000 events, each with
EventId,OccurredTime,ProcessId,ProcessVersion,StepId,WorkType,IndexedEventType,IndexedEventStatus,DurationMs,UserIdand property dictionaries (StringProperties,LongProperties,DoubleProperties,BoolProperties). These are the same events a Secondary Event Provider receives; see the Events Dictionary.
Workflow actions (V1_WorkflowAPI)¶
Every action here needs the Manage Workflows token feature.
GetAllWorkflows¶
Lists the active workflows the token's user can view.
- Body none (
{}). - Returns An array of
{ WorkflowId, WorkflowName, Version, FirstStepId }.
SendToWorkflow¶
Starts a workflow on a work item. The workflow starts working the item at once, so add every document first.
- Body
WorkflowId(guid),WorkItemId(guid),WorkflowVersion(integer, optional; empty means the latest version),WorkflowStep(guid, optional; the step to start at; needsWorkflowVersion). - Returns The work item (
WorkItemId,CurrentWorkflow,CurrentStepand the otherWorkItemfields). - Fails with
Workflow is unavailable.(wrong id, or the workflow is not active),User does not run have permission to workflow.(the user needs Run permission),You must provide a workflow version if you specify a WorkflowStep property.
ReleaseHold¶
Releases the hold on a work item so it continues in its workflow, for example after your endpoint finishes work that a step waits for.
- Body
WorkItemId(guid). - Returns The work item.
- Fails with
No hold was found for workitem {id}(HTTP 412) when the work item is not on hold. Treat it as "already released" if your code can run twice.
SetGlobalVariable¶
Creates or updates a non-secret global variable.
- Body (
WorkerGlobalVariableParameter):Name(string),Value(string),Tags(array of strings, optional),Type(string, optional),SubType(string, optional). - Returns The variable you sent.
- Fails with
You cannot degrade or upgrade a global variable's secret property after creation!when a variable with that name is secret. UseSetSecretGlobalVariablefor it.
SetSecretGlobalVariable¶
Creates or updates a secret global variable, for example an API token that a workflow sends.
- Body The same as
SetGlobalVariable. - Token features Manage Workflows and Manage Secret Global Variables.
- Returns No
Data. - Fails with
You cannot degrade or upgrade a global variable's secret property after creation!when a variable with that name exists and is not secret. The secret flag cannot change in either direction after creation.
GetGlobalVariable¶
Reads a non-secret global variable with its value and metadata.
- Body
Name(string). - Returns The variable.
- Fails with
Cannot view global variable as it is marked as secret. To see the secret's global variable's tags and type, please use GetGlobalVariableMetadatafor a secret variable.
GetGlobalVariableMetadata¶
Reads a variable's metadata without its value. Works for secret variables when the token has Manage Secret Global Variables.
- Body
Name(string). - Returns
{ Name, Tags, Type, IsSecret }, orSuccess: truewithData: nullwhen no variable has that name.
Errors you will see¶
- HTTP 412 The action failed. Read
Messages[].MessageKey. Common causes: the work item id does not exist, a workflow step holds the work item at that moment (retry later), a document or page id is not on the work item, a file type is not allowed. - HTTP 401 The token does not have Manage Work Items (or Manage Workflows for
V1_WorkflowAPI). - HTTP 422 The body does not match the action (for example an id that is not a GUID).
See the Error message index.