This guide will walk you through the process using cURL to upload local files and attach them to Bika records with simple terminal commands.
Prerequisites
- A Bika account with API access
- An Access Token (generate via Bika’s developer settings)
- A local file to upload (e.g., example.png)
- Terminal or command-line tool
Step 1: Prepare Your Bika Environment
Create a space and database:
Ensure your database has a field for attachments (e.g., Images
).
Get Required IDs:
- SPACE_ID: Found in Bika’s space URL (e.g.,
https://bika.ai/space/{SPACE_ID}
). - NODE_ID: Identifier for your database. Check Bika’s URL.
- RECORD_ID: ID of the target record to update.
Step 2: Upload a File to Bika workspace
Run this cURL command to upload your file and save the data
in response for the next step:
curl 'https://bika.ai/api/openapi/bika/v1/spaces/{SPACE_ID}/attachments' \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
-F 'file=@./example.png'
Response Example:
{
"success": true,
"code": 200,
"message": "SUCCESS",
"data": [
{
"id": "attpcZFhfBmt6KFA4MbKKoO1",
"path": "openapi/teCC2LGpyEOUWZsXET9I6.png",
"size": 211047,
"bucket": "bika",
"mimeType": "image/png",
"name": "teCC2LGpyEOUWZsXET9I6.png"
}
]
}
Step 3: Attach the File to a Record
Use a PATCH request to update the record with the uploaded attachment:
curl -X PATCH "https://bika.ai/api/openapi/bika/v1/spaces/{SPACE_ID}/resources/databases/{NODE_ID}/records" \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"cells": {
"attachmentField": [
{
"id": "attpcZFhfBmt6KFA4MbKKoO1",
"path": "openapi/teCC2LGpyEOUWZsXET9I6.png",
"size": 211047,
"bucket": "bika",
"mimeType": "image/png",
"name": "teCC2LGpyEOUWZsXET9I6.png"
}
]
},
"id": "recif5tp0iMl4y6JHwIaCtvm"
}'
Key Notes
1. Replace Placeholders:
- {SPACE_ID}, {NODE_ID}, {RECORD_ID}, {YOUR_ACCESS_TOKEN}
- attachmentField : Match your Bika database’s attachment field name (e.g., Images).
2. Multiple Attachments:
Add more objects to the array:
"attachmentField": [
{ "id": "att1", "path": "...", ... },
{ "id": "att2", "path": "...", ... }
]
Troubleshooting
- 401 Unauthorized: Invalid or expired access token.
- Not Found: Verify SPACE_ID, NODE_ID, or RECORD_ID values.
- Field {key} not found: Ensure the attachment field exists in your Bika database.
yes, you are right, it’s PATCH