Uploading a file involves several steps: creating a document, uploading the file, and then linking them.
Step 1: Obtain the Web Service ID for the folder #
To create a document, you need the Web Service ID of the target folder. Use an operation query :
Curl example:
curl "https://apps.kafinea.com/YourKafinea/webservice.php?operation=query&sessionName=YOUR_SESSION_ID&query=SELECT%20id%20FROM%20DocumentFolders%20WHERE%20foldername%20LIKE%20'Default'%20LIMIT%201%20;"
Request:
SELECT id FROM DocumentFolders WHERE foldername LIKE 'Default' LIMIT 1 ;
Step 2: Create a Document Entity #
Create an entity of type Documents through the operation create.
POST
https://apps.kafinea.com/{instance}/webservice.php
| Setting | Type | Required | Description |
|---|---|---|---|
operation |
string | yes | Must be create |
sessionName |
string | yes | Session ID |
element |
JSON | yes | Document JSON object (see fields below) |
elementType |
string | yes | Must be Documents |
Object fields element :
| Field | Type | Required | Description |
|---|---|---|---|
notes_title |
string | yes | Document entity name |
folderid |
string | yes | Folder Web Service ID (Step 1) |
filename |
string | yes | File name |
filetype |
string | yes | MIME type (e.g., application/pdf) |
filesize |
int | yes | File size in bytes |
filestatus |
int | yes | 1 for assets |
filelocationtype |
string | yes | I for internal storage |
assigned_user_id |
string | yes | Assigned user's Web service ID |
Curl example:
curl -X POST https://apps.kafinea.com/YourKafinea/webservice.php \
-d "operation=create" \
-d "sessionName=YOUR_SESSION_ID" \
-d 'element={"notes_title":"Mon document","folderid":"65x1","filename":"rapport.pdf","filetype":"application/pdf","filesize":12345,"filestatus":1,"filelocationtype":"I","assigned_user_id":"19x1"}' \
-d "elementType=Documents"
Step 3: Upload the file (FileUpload) #
This operation uploads the file and links it to the created document. It can also be used on its own to add images to products (replace attachmentType by Image and parentId (by the product's Webservice ID).
POST
https://apps.kafinea.com/{instance}/webservice.php
| Setting | Type | Required | Description |
|---|---|---|---|
operation |
string | yes | Must be FileUpload |
sessionName |
string | yes | Session ID |
parentId |
string | yes | Document Web Service ID (Step 2) |
attachmentType |
string | yes | Attachment for a file, Image for an image |
fileName |
string | yes | File name |
fileContents |
string | yes | Content of the Base64-encoded file |
Curl example:
curl -X POST https://apps.kafinea.com/YourKafinea/webservice.php \
-d "operation=FileUpload" \
-d "sessionName=YOUR_SESSION_ID" \
-d "parentId=15x7890" \
-d "attachmentType=Attachment" \
-d "fileName=rapport.pdf" \
-d "fileContents=$(base64 -w0 rapport.pdf)"
Retrieve a file (files_retrieve) #
Retrieves a file previously added to Kafinea. You need the file's WebserviceID (not to be confused with the Document entity's WebserviceID).
GET
https://apps.kafinea.com/{instance}/webservice.php
| Setting | Type | Required | Description |
|---|---|---|---|
operation |
string | yes | Must be files_retrieve |
sessionName |
string | yes | Session ID |
id |
string | yes | File Web Service ID |
Curl example:
curl "https://apps.kafinea.com/YourKafinea/webservice.php?operation=files_retrieve&sessionName=YOUR_SESSION_ID&id=28x5678"