Uploading files into your digital workplace via API
Overview
Whether you are migrating content from local files or from a web location, it is important to understand how your digital workplace accepts, handles and processes uploads. The steps provided below are general and can be followed using your preferred development language. However, if you are developing with JavaScript, check out our article that shows you how to upload a file using JavaScript. You can always find more information about our API on the API Reference page.
How to upload files into your digital workplace via API
1. Create a session. Before making any API calls to upload content to your digital workplace, you must create a session that returns a session key or token. This token is needed to authenticate yourself against your workplace and make additional API calls. Below is the API call for creating a session:
API V1: (Use this API if your workplace has SAML enabled)
Method: POST Path: /.api/api.svc/session/create Parameters: appID* (String), appPass* (String), apiversion* (Integer), community* ( URL of Community – String), username (String), password (String)
API V2: (Use this API if your workplace doesn't have SAML enabled)
Method: POST Path: /.api/api.svc/session/create Parameters (in body of request): AppID* (String), AppPassword* (String), ApiVersion* (Integer), UserName* (String), UserPassword* (String), Instance* : 0 (Integer)
2. Create a file upload instance. The next step is to create a file upload instance in your Igloo community.
Method: POST Path: /.api/api.svc/file_upload/create Parameters: title* (String), totalBytes* (Integer), parentId (String), documentId (String)
The response to this request contains the parameters id(fileId) and chunkSize which are necessary parameters for subsequent steps when we need to specify the fileId and how big the chunks need to be.
3. Upload file chunks to the file upload. The chunking logic is not provided by Igloo and has to be manufactured. Essentially, a function needs to be created to parse the file into x sized, n number of chunks so they can be uploaded sequentially.
Method: POST Path: /.file_upload_api/file_upload/{file_id}/add_chunk?chunkIndex={index} Parameters: file_id* (String), index* (Integer)
These chunks are passed into the POST request under data=file_chunk and is indexed based on chunkIndex.
4. Set the service flag. Once all the file chunks have been uploaded, you must set the service flag to completed "completed".
Method: POST
Path: /.api/api.svc/file_upload/{file_id}/update
Parameters: title (String), description (String), parentId (String)
5. Instantiate a finalization trigger. Once the completed status has been set, a finalize trigger must be instantiated to successfully create the file identified by the file_Id. This also deletes the file upload object (if the document was created successfully).
Method: POST Path: /api/api.svc/file_upload/{file_id}/create_document Parameters: file_id* (String)