Introduction
This section describes Synkzone API. It allows you to create applications interacting with the Synkzone service and perform actions like uploading and reading files belonging to your zones.
In this guide we will use the terms resource and endpoint to refer to a url for a specific resource.
From a birds-eye view the endpoints within the API are divided into sections:
- Access - deals with login/logout functionality.
- Files and multipart upload - deals with uploading, downloading, listing and deletion of folders and files.
- OAuth2 - deals with operations to support OAuth2.
- Organization - deals with settings of the organization.
- Platform notifications - deals with notifications from platform to user.
- Share - deals with sharing resources with others outside the organization or zone.
- Support - deals with creating support requests.
- Token management - deals with operations to support management of tokens.
- Users - deals with operations relating to users.
- Zones - deals with any operation regarding zones.
- Zone log - deals with events and messages (the zone log) within a zone.
We will here go though some concepts regarding this API, then a getting started section and at last go though the API itself. If you feel adventurous and want to jump straight into connecting to the API feel free to jump to the Getting Started section.
Authentication
Before any endpoints can be called the client needs to be authenticated. This is done by calling the either i) an issued bearer token or ii) using the logon endpoint with the credentials provided to you by Synkzone. Please note that the password needs to be sent as an array of chars rather than as a string due to security reasons.
Your credentials keys carry many privileges, so be sure to keep them secure! Do not share your credentials in publicly accessible areas such as GitHub, client-side code, and so forth.
If the logon message was used and the request was successful then the response from the endpoint will contain a session id which can be used as a bearer token and if requested a cookie will be set containing the very same bearer token. It will also contain an expiration time period in milliseconds. It is the responsibility of the calling application to keep track of token lifespan and create a new token if necessary.
Authentication against the other endpoints can then be done by either providing said cookie or by adding the given bearer token to a Authorization header. Please see example to the right. All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.
POST /api/access/logon HTTP/1.1
Content-Type: application/json
Accept: */*
Host: <host>
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 177
{
"password": [
"p", "a", "s", "s", "w", "o", "r", "d"
],
"setCookie": true,
"timeout": 3600000,
"username": "<username@synkzone.test>"
}
HTTP/1.1 200 OK
Set-Cookie: Synkzone=-135610627654801378;Version=1;Path=/;Max-Age=86400000;HttpOnly
Content-Length: 76
Content-Type: application/json
{"expiresInMillis":3599999,"logonOK":true,"sessionID":"-135610627609090378"}
POST /api/zones/<zoneid>/files/<folderid> HTTP/1.1
Authorization: Bearer -135610627609090378
Content-Type: application/octet-stream
Accept: */*
Host: <host>
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 1521
Note
You must replace -135610627609090378 with your generated session id / token.
Bearer tokens
As an alternative to creating a short lived sessionID through the logon method, it is possible to create bearer tokens that can be used towards the API. These are created by calling the API endpoint to create a token. The tokens created can have a name, a validity and possibly a tailored scope for the purpose.
The endpoint to create or manage tokens is /api/tokens.
Requests
In general all request are done as a HTTPS request and any data sent to the server will be as JSON, Content-Type must be set to application/json.
There as a few exceptions to this, for example file upload, which can either be done as application/octet-stream or as a multipart/form-data.
Responses
In general, all responses are as JSON and uses the application/json. Against there are exceptions to this for the endpoint that returns actual file content, this endpoint returns application/octet-stream.
All dates and times in any response are written as ISO 8601 and is using UTC.
Every response will contain a HTTP status code, showing if the request was processed successfully or not.
The following HTTP statues are available:
- 200 OK - Request was successful
- 201 Created - The resource was successfully created (after a POST call)
- 400 Bad request - The request contained an error
- 401 Unauthorized - The user is not logged in/no user credentials provided
- 403 Forbidden - User credentials are provided but user has not enough rights
- 404 Not found - The endpoint or resource does not exist
- 409 Conflict - Resource already exists
- 500 Internal Server Error - Unspecified server error
- 503 Service unavailable - The API is not reachable at the moment
In addition to the above HTTP status codes the responses will also contain the actual response body, which will hold the data request in JSON format, or, if the response is an error, an error structure describing the error.
{"message":"Error description"}
Pagination
Some calls are paginated. Pagination (sometimes called paging) is controlled by parameters page (default 1) and pageSize (default 100).
Whenever a call results in more items then pageSize, further requests using page is needed to retrieve all entries.
Scope
The scope concept is a powerful tool to limit or restrict a session (logon) or the capabilities of an issued bearer token. As a general rule bearer tokens are connected to a user in the system and thus cannot have any capabilities beyond what that user has. Scopes can further restrict these issued rights. More on scope TBA.