Run apps endpoint (Deprecated)

The Runs endpoint offers a simpler and more robust way to run apps and manage app runs. The Run apps endpoint is still supported, but the App runs endpoint is the preferred approach. This page remains temporarily available for reference but is not actively maintained.

In this document, API_ROOT defines where to route API requests for file operations, and its value is aihub.instabase.com/api/v2/zero-shot-idp/projects/app.

1import requests, base64
2
3API_ROOT = 'https://aihub.instabase.com/api/v2/zero-shot-idp/projects/app'
4APP_ID = '<EXAMPLE-APP-ID>' # Enter your app id
5API_KEY = '<API-KEY>' # Enter your API Key
Organization members must include an IB-Context header in all Run apps API requests for the call to complete in the organization context. This context is validated against any specified input directory or output workspace value. For example, if the IB-Context is a user’s community account but the API request lists a shared workspace in an organization as the output workspace, the call fails. The same applies if the IB-Context header is omitted, in which case the default community context is used.

Using file paths as app input

When running apps by name or by app ID, there are two methods to specify the app’s input:

  • Preferred: Use the batch_id parameter to process all files in the specified batch. See the Batches endpoint for more information.

  • Supported: Use the input_dir parameter to process all files in a specific input folder in the filesystem. This requires specifying the file path to a location in a connected drive.

The format of the file path varies if you have a community or organization account.

  • Community accounts: /<USER-ID>/my-repo/fs/<DRIVE-NAME>/<INPUT-FOLDER>/

  • Organization accounts: /<ORGANIZATION-ID>/<WORKSPACE>/fs/<DRIVE-NAME>/<INPUT-FOLDER>/

ValueDescription
<USER-ID> Enter your user ID. You can find this on the Settings > APIs page, under User ID.
<ORGANIZATION-ID> Enter your organization ID. You can find this on the Settings > APIs page, under Organization ID.
<WORKSPACE> This value reflects the workspace name (shared workspaces) or your user ID (personal workspaces). You can find this value by selecting the workspace in Workspaces, then looking at the workspace query string in the URL.

For example:
- https://aihub.instabase.com/workspaces/create?workspace=*New_Workspace*
- https://</span>aihub.instabase.com/workspaces/create?workspace=*john.doe_gmail.com*
<DRIVE-NAME>Use the drive’s display name. You can see a drive’s display name by opening the Data Sources panel in a workspace where the drive is connected. For example, the Instabase Drive’s display name is Instabase Drive.
<INPUT-FOLDER>Use the exact name of the folder, as displayed in the filesystem.

Running apps by app ID

Run an app by its app ID through sending a POST request to API_ROOT/<string:app_id>/run with the request body encoded as JSON.

You can find the app ID in the app’s AI Hub URL. For example, https://aihub.instabase.com/hub/apps/528c36e8-ac5b-490d-a41b-7eec9c404b87.

MethodSyntax
POSTAPI_ROOT/<string:app_id>/run

Request parameters

Parameters are required unless marked as optional.

ParameterTypeDescriptionValues
batch_idstringOptional, preferred. The batch ID of the batch you created. All files uploaded to the batch are used as input for the app run.A valid integer batch ID.
input_dirstringOptional, supported. The path of the input folder, in a connected drive or Instabase Drive.A complete path to the input folder. See using file paths as input.
output_workspacestringOptional. The workspace in which to run the app. The output is saved to the default drive of the specified workspace. If not defined, the default is:

- Community accounts: Runs in and saves to the personal workspace’s Instabase Drive (<userID>/my-repo/Instabase Drive).
- Organization accounts: Runs in and saves to the organization’s default drive (<organizationID>/<userID>/<default-drive>).
A valid name of a workspace in the specified community or organization context, such as shared-workspace-accounting.
output_dirstringOptional. Defines a specific location for the output to be saved in a connected drive or Instabase drive. If defined, overrides the output_workspace value.A complete path to the output folder.
settingsdictOptional. Advanced settings for your app run.
settings/webhook_configdictOptional. Configure the webhook URL that’s called on app run completion. See Webhook Parameters for more details
settings/webhook_config/urlstringOptional. Webhook URL to which a HTTP request is sent when the run is completed.
settings/webhook_config/headersdictOptional. Configure the headers that are sent alongside HTTP request. Format is { "<HTTP-HEADER>": "<VALUE>"}

Response schema

KeyTypeDescriptionValue
job_idstringThe id of the job that was triggered

Examples

Request

Example (Python):

1run_app_payload = {
2 'batch_id': 'BATCH-ID',
3 # optional: 'output_dir': '<IB-OUTPUT-FILE-DIR>', if not specified, assumes it is your input_dir/out
4}
5
6API_HEADERS = {
7 'Authorization': f'Bearer {API_KEY}',
8 'IB-Context': '<USER-ID or ORGANIZATION-ID>'
9}
10
11url = f'{API_ROOT}/{APP_ID}/run'
12run_app_resp = requests.post(url, headers=API_HEADERS, data=run_app_payload)
13
14job_id = run_app_resp.json().get('job_id')
15print(f'Job Running: {job_id}')

Response

The response body is a JSON object.

If successful:

1HTTP STATUS CODE 200
2
3{
4 job_id: '53275652-abc8-479e-89f2-ccb12af401a0' # Example Job ID
5}

Running apps by name

Run an app by its name through sending a POST request to API_ROOT/run with the request body encoded as JSON.

MethodSyntax
POSTAPI_ROOT/run

Request parameters

Parameters are required unless marked as optional.

ParameterTypeDescriptionValues
batch_idstringOptional, preferred. The batch ID of the batch you created. All files uploaded to the batch are used as input for the app run.A valid integer batch ID.
input_dirstringOptional, supported. The path of the input folder, in a connected drive or Instabase Drive.A complete path to the input folder. See using file paths as input.
namestringThe name of the AI Hub app through which you want to process the files.A valid name of a prebuilt or custom AI Hub app.
output_workspacestringOptional. The workspace in which to run the app. The output is saved to the default drive of the specified workspace. If not defined, the default is:

- Community accounts: Runs in and saves to the personal workspace’s Instabase Drive (<userID>/my-repo/Instabase Drive).
- Organization accounts: Runs in and saves to the organization’s default drive (<organizationID>/<userID>/<default-drive>).
A valid name of a workspace in the specified community or organization context, such as shared-workspace-accounting.
output_dirstringOptional. Defines a specific location for the output to be saved in a connected drive or Instabase drive. If defined, overrides the output_workspace value.A complete path to the output folder.
ownerstringOptional. The account that generated the app. If not specified, defaults to your AI Hub username.For custom AI Hub apps belonging to you, don’t specify a value. For public AI Hub apps published by Instabase, specify instabase.
settingsdictOptional. Advanced settings for your app run.
settings/webhook_configdictOptional. Configure a webhook url that is called on app run completion. See Webhook parameters for more details
settings/webhook_config/urlstringOptional. Webhook URL to which a HTTP request is sent when the run is completed.
settings/webhook_config/headersdictOptional. Configure headers that is sent alongside HTTP request. Format is { "<HTTP-HEADER>": "<VALUE>"}

Response schema

KeyTypeDescriptionValue
job_idstringThe id of the job that was triggered

Examples

Request

Example (Python):

1run_app_payload = {
2 'batch_id': 'BATCH-ID',
3 'name': APP_NAME
4 # optional: 'owner': '<OWNER-USERNAME>', if not specified, assumes it is your username
5}
6
7API_HEADERS = {
8 'Authorization': f'Bearer {API_KEY}',
9 'IB-Context': '<USER-ID or ORGANIZATION-ID>'
10}
11
12url = f'{API_ROOT}/run'
13run_app_resp = requests.post(url, headers=API_HEADERS, data=run_app_payload)
14
15job_id = run_app_resp.json().get('job_id')
16print(f'Job Running: {job_id}')

Response

The response body is a JSON object.

If successful:

1HTTP STATUS CODE 200
2
3{
4 job_id: '53275652-abc8-479e-89f2-ccb12af401a0' # Example Job ID
5}

Running apps in memory

Apps can also be run in memory by sending a POST request to API_ROOT/<string:app_id>/run/sync with the request body encoded as JSON.

When running apps in memory, neither the input file contents nor the app run’s results are saved. The app run’s results can only be retrieved through the API response.
MethodSyntax
POSTAPI_ROOT/<string:app_id>/run/sync

Request parameters

Parameters are required unless marked as optional.

ParameterTypeDescriptionValues
fileslistA list of files to process.Each file is represented by a file_name : file_content dictionary (see below).
file_namestringThe name of the file to be processed.File name must be a string.
file_contentBase64 encodingThe content of a file to process.Base64 representation of the content of a file.

Response schema

The response contains all extracted fields. Extracted fields are dependent on how the app is built. If a field isn’t found, an empty string '' is returned instead

Examples

Request

Example (Python):

1encoded_string = base64.b64encode(open('file_name.jpg', 'rb').read()).decode('utf-8')
2url = f'{API_ROOT}/{APP_ID}/run/sync'
3
4run_app_payload = {
5 'files': [{
6 'file_name': 'chips.jpg',
7 'file_content': encoded_string,
8 }]
9}
10
11API_HEADERS = {
12 'Authorization': f'Bearer {API_KEY}',
13 'IB-Context': '<USER-ID or ORGANIZATION-ID>'
14}
15
16run_app_resp = requests.post(url, data=run_app_payload, headers=API_HEADERS)
17print(f'Job Results: {run_app_resp.json()}')

Response

The response body is a JSON object.

If successful:

1HTTP STATUS CODE 200
2
3{
4 'response': {
5 'records': [
6 {
7 'output_file_path': 'IBMSG_FILE_PATH',
8 'results': [
9 {
10 'key': 'EXTRACTION_FIELD',
11 'value': 'EXTRACTION_VALUE',
12 'field_type': 'STRING',
13 'model_confidence': 0.9
14 }
15 ],
16 'record_index': 0,
17 'file_name': 'PATH_TO_chips.jpg',
18 'document_path': 'PATH_TO_chips.jpg',
19 'flow_index': 0,
20 'file_index': 0,
21 'is_manually_reviewed': false,
22 'current_step_index': 2,
23 'is_human_corrected': false,
24 'absolute_ibocr_path': 'OCR_PATH',
25 'was_classified': false,
26 'is_finalized': true
27 }
28 ],
29 'binary_path': 'IBFLOWBIN_PATH',
30 'job_id': '53275652-abc8-479e-89f2-ccb12af401a0',
31 'num_tasks': 1,
32 'has_more_tasks': false,
33 'next_offset': 1,
34 'can_resume': false,
35 'on_last_resumable_step': false
36 }
37}

Webhook parameters

You can use the webhook_config setting to ensure your application is notified when an app run completes. Instabase POSTs JSON-encoded data of the format below to the webhook endpoint:

$# body
>{
>"status": <string>,
>"msg": <string>,
>"job_id": <string>,
>"binary_path": <string>,
>"input_dir": <string>,
>"output": <string>
>}

The response body contains the following fields:

  • status: "OK" | "ERROR"

  • msg: (optional) Error message. Present only if status is ERROR.

  • job_id: A unique identifier for the job.

  • binary_path: The path reference to flow binary file used to execute the app.

  • input_dir: Input directory.

  • output: The full path to the root output folder.

To acknowledge receipt of the event, your endpoint must return a 2xx HTTP status code. All response codes outside this range, including 3xx codes, indicate to Instabase that you did not receive the event.

If Instabase does not receive a 2xx HTTP status code, the notification attempt is repeated up to 7 times.

Was this page helpful?