coreplus API

The coreplus API provides access to appointment booking related end points, such as clients, practitioners, availability slots and appointments. It is a RESTful API, which utilises the HTTP verbs for creating viewing objects.

If you are a developer looking to create an external consumer server to server application for your coreplus clients, then by signing up for a sandbox account you will get access to your own trial coreplus account on our sandbox server with authorisation credentials.

Post Client Files (File Upload)

URL https://<server domain name>/api/core/<version>/File/
Description Allows a user to post a file for the given entity within a given parent folder.

This endpoint is a multipart/form-data post consisting of two key value fields (json and file), where the value’s are tuples.
The ‘json’ field value contains an empty name, the desired json string and the content-type
The ‘file’ field contains the desired file name, file contents as a binary plain text string and the content-type.
These two fields and their values must be encoded as a single data payload of multipart/form-data.

 

Required components for multipart/form data (json field) Type Description
Key Field:

Field name

String “json”
Key Values:
Name String Empty/None
Json values

Required parameters

String Json string with following parameters
name String Filename to upload
primaryDomainKey String The guid of the entity e.g.clientId
size string File size in bytes
entity String Type of entity to upload to e.g.client

(Only client entity is supported currently)

Optional Parameters
parentFolderId String The guid of the folder to which the file needs to be uploaded. If left blank it will be uploaded to root level
isFolder Bool Should be False for a File upload

 

Required components (File field part) Type Description
Key Field:

Field name

String “File”
Key Values:

 File Components

name String Name of the file being uploaded
File String The byte string stream as plain text for an file opened as binary
Content type String Text/plain (text/plain will work for all file types)

 

* Note that the header in the request will be a content type of “multipart/form-data” and will contain a calculated boundary value (other coreplus endpoint requests use application/json as the content-type)
It is best to use a multipart encoder library to generate the payload data into a single string.
e.g Python library Multipart Encoder http://toolbelt.readthedocs.io/en/latest/uploading-data.html
C# should be able to do this with the Microsoft.Net.Http package https://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data

 

Example Request https://api.coreplus.com.au/API/Core/v2.1/File/
Json Part json: (None, ‘{“parentFolderId”: null, “name”: “UploadFile.txt”, “size”: “38”, “isFolder”: false, “entity”: “Client”, “primaryDomainKey”: “88e372b5-e985-4084-8f69-c888f995fbcc”}’, ‘text/plain’)
File Part file: (‘UploadFile.txt’, <_io.BufferedReader name=’D:\\UploadFile.txt’>, ‘text/plain’)
where <_io.BufferedReader is the stream output from the file opened in binary mode
Example Response
{
   "id":"f9f4f4ac-10bb-48f6-a5e2-a47a55f2070f",
   "name":"UploadFile.txt",
   "size":38,
   "isFolder":false,
   "entity":"Client",
   "primaryDomainKey":"88e372b5-e985-4084-8f69-c888f995fbcc"
}

 

Sample Code for uploading a file using Python


import os
import datetime
import requests
from requests_toolbelt import MultipartEncoder
import jwt
import simplejson

end_point_url_sfx_str = '/API/Core/v2.1/File/'
app_creds = {'consumer_id': 'consumerId of the app',
             'secret': 'Secret of the app',
             'access_token': 'Access token of the app',
             'base_url': 'https://sandbox.coreplus.com.au'
             }
claim_payload = {'iss': 'http://mydomain.com.au',
                 'aud': 'https://coreplus.com.au',
                 'nbf': datetime.datetime.utcnow(),
                 'exp': datetime.datetime.utcnow() + datetime.timedelta(seconds=60),
                 'consumerId': app_creds.get('consumer_id'),
                 'accessToken': app_creds.get('access_token'),
                 'url': app_creds.get('base_url') + end_point_url_sfx_str,
                 'httpMethod': 'POST'
                 }

# create JwToken
encoded_jwt_byte = jwt.encode(claim_payload, app_creds.get('secret'), algorithm='HS256')
jwt_str = str(encoded_jwt_byte, 'utf-8')
uri = app_creds.get('base_url') + end_point_url_sfx_str

# Locate file
uploadfilepath = "D:\\Test files\\test upload.txt"
filesize = os.stat(uploadfilepath).st_size

# Prepare data payload for Folder Creation
datapayload = {
    'parentFolderId': '',
    'name': 'UploadFile.txt',
    'size': str(filesize),
    'isFolder': False,
    'entity': 'Client',
    'primaryDomainKey': '935BBFC6-2845-43F4-B513-8A3B12703851'
}

# create mutlipart/form-data
m = MultipartEncoder([
    ('json', (None, simplejson.dumps(datapayload), 'text/plain')),
    ('file', (os.path.basename(uploadfilepath), open(uploadfilepath, 'rb'), 'text/plain'))],
    None, encoding='utf-8')

headers = {'Authorization': 'JwToken' + ' ' + jwt_str, 'content-type': m.content_type}

# send request
response = requests.post(uri, headers=headers, data=m, timeout=45, verify=True)
print(response.json())

#### End ####

Develop with us

Use the form to sign-up and start developing with coreplus today.


Please leave this field empty.