CREATE DBFiles/Files with Rest API

Using SAI360’s Rest API, DBFiles can be created and linked to a SAI360 parent record directly or via the "File Storage" Subform.

For the task of creating DBFile and linking it to a SAI360 Record

Step

Example

POST call to create a new DBFile, mention the file Name and Type in the URL

CALL Type: POST

URL (example):

http://<WebApp URL>/restapi/component/dbfile?name=NitricOxideSDS&filetype=pdf

The file data needs to be included in the POST payload as binary data.

On successfully creating the DBFile, the call will return the UniqueId of the DBFile record created, which can then be used in subsequent calls.

PATCH call to link the SAI360 parent record with the DBFile just created

To attach the DBFile you have created in the previous step to a parent record, you need the UniqueId of the parent record in the Patch call URL. In the payload you need to follow the below format to specify the relationship from the parent record to the DBFile (rel_safety_data_sheet) and provide the UniqueId of the DBfile created in the previous step.

CALL Type: PATCH

URL (example):

http://<WebApp URL>/restapi/component/chemical_register(<UniqueId of SAI360 record')

 

JSON Payload (example):

{

"rel_safety_data_sheet": {
"@id": "dbfile('UniqueId of DBFile from above step')"
}
}

 

For the Task of creating DBFile & File Storage Subform and linking it to a SAI360 record

Step

Example

POST call to create a new DBFile, mention the file Name, Type & createFileParent=true in the URL

Having the createFileParent flag in the URL will create the "File" record in the background and that File record can then be linked to the SAI360 parent record

 

CALL Type: POST

URL (example):

http://<WebApp URL>/restapi/component/dbfile?name=Incident1&filetype=jpeg&createFileParent=true

The file data needs to be included in the POST payload as binary data.

On successfully creating the DBFile, the call will return the UniqueId of the DBFile record created, which can then be used in subsequent calls.

GET call to get the UniqueId of the File record created (in the background) in the above POST call

To retrieve the UniqueId of the File record created (in the background), you need the UniqueId of the DBFile (created in the above step) in the GET URL.

The GET call will return the UniqueId of the File record in the relationship ‘rel_owningfilecomponent’.

CALL Type: GET

URL (example):

http://<WebApp URL>/restapi/component/dbfile('<UniqueId of DBFile from above step>')?$expand=rel_owningfilecomponent

 

PATCH call to link the SAI360 parent record with the File record

To attach the File record created in the previous steps to a parent record, you need the UniqueId of the parent record in the patch call URL. In the payload you need to follow the below format to specify the relationship from the parent record to the File record and provide the UniqueId of the File created in the previous step.

CALL Type: PATCH

URL (example):

http://<WebApp URL>/restapi/component/incident(<UniqueId of SAI360 record')

 

JSON Payload (example):

{

"rel_file_storage": [
{

"@id": "file('UniqueId of File record')"
}
]
}

 

See Also

Rest API

Rest API - Introduction

Add Components to Rest API

Generate an API Key for a User

GET (Read) Operations

PATCH (Write) Operations

POST (Create) Operations

CREATE or UPDATE Users with Rest API