Gå till innehållet

Endast på engelska

Den här sidan finns inte på svenska ännu. Innehållet visas på engelska.

Getting started

In this tutorial we will go through some common steps with regards to this API.
We will:

  1. Authenticate against the Synkzone service
  2. List all available zones for the logged in user
  3. List root directory in one of the zones
  4. Retrieve file metadata for a file
  5. Download content of a file
  6. Upload a file

Prerequisites

There are some things we need before we get going.

  1. The credentials for a user that is a member of at least one zone - credentials are provided by the Synkzone service when the user account is created. The credentials used are organization specific and can for example be a password and possibly an additional MFA (Multi Factor Authentication) such as TOTP (Time-based one-time password).
  2. A tool like Bruno or curl in order to call the Synkzone REST API. The examples in this tutorial will use curl.
  3. An existing zone containing some files and folders.

API request anatomy

Your API request will consist of the following items:

  1. API URL. Your API is accessed at: https://<organisation-name>.synkzone.com/api. The path part will depend on the endpoint you are trying to call.
  2. Authorization header. This allows you to authenticate against the endpoint. Without authentication you will not be able to make any successful calls.
  3. Payload or request parameters (optional). When submitting a POST or PUT request, as for creating or updating a resource, you need to provide the new or updated info to the endpoint which is done as a payload written in JSON. For some GET requests the request can be refined by adding query parameters as a segment of the path.

Now let's try out our first request.

Note

Please make sure to change any user credentials provided to you and any IDs used in the following curl calls should come from your own responses when trying this out.

Authentication

curl --location --request POST http://<your-organization-name>.synkzone.com/api/access/logon \
--header 'Content-Type: application/json' \
--data-raw '{
  "password": [
    "p", "a", "s", "s", "w", "o", "r", "d"
  ],
  "username": "<username@synkzone.com>",
  "verificationCode": "<TOTP>"
  }'
{"expiresInMillis":3600000,"logonOK":true,"sessionID":"3881603599579212345"}

The first thing we will need to do before calling any API endpoints is to authenticate ourselves. This is done by calling the /api/access/logon endpoint as seen to the right. Please note that you need to change the password and the username to your credentials which you should have received from Synkzone. If your organization uses MFA, use the verificationCode field - otherwise remove it. All other parameters can stay as they are.

Note

Please note that if you have been provided a bearer token, a logon is not required and this token can be used instead of the sessionId provided by a successful logon.

If all goes well you will now receive some JSON back from the Synkzone service stating that your login attempt was successful. If not, please double check your input in the request. Please note that the request may also result in that more credentials (such as for example a TOTP) are needed to successfully logon. The successful JSON response will contain a sessionID property. This property is your token to use for authentication in any subsequent calls to the API.

Create authentication token

curl --location --request POST http://<your-organization-name>.synkzone.com/api/tokens \ 
--header 'Authorization: 3881603599579212345' \
--data-raw '{
  "tokenName": "An example token",
  "validity": 262980000,
  "password": [
    "p", "a", "s", "s", "w", "o", "r", "d"
  ]
}'
{
    "expiry": 986994936,
    "id": "185b3dd0-b725-4b2a-8292-f3cfe5251d19",
    "token": "P-7C4F101CF8725ED27D285E6C68FE47C608303455F2F4FEEBA4675B1401AED030-"
}

If you prefer you can use tokens as authentication method instead of using login and session id. To create a token you need to provide the password, since this is embedded in your token. Using the example request a token containing the same access levels as the user will be created, i.e. everything that user can view and create/modify can be done by that token. Validity is given in seconds.

The response of a successfully created token contains the token, the id of the token and its expiry (in milliseconds). This is the only time the token will be visible, do make sure to store it in a safe way. An expired token will not be automatically deleted and can be viewed in the list of all tokens. The generated token can now be used instead of a session id as authentication method. All tokens can be viewed by a GET request to the /api/tokens endpoint.

The rest of the examples in this "Getting started" guide will use session id as authorization.

List available zones

curl --location --request GET http://<your-organization-name>.synkzone.com/api/zones \
--header 'Authorization: 3881603599579212345'
[
  {
    "allowExternalSharing": false,
    "createdAt": "2022-04-07T12:20:38.673+02:00",
    "createdBy": "bob.tyler@organization.org",
    "currentSize": -1,
    "description": "A zone for testing",
    "id": "9391ee2e-b554-4bb5-8888-c3d7d6f0daa7",
    "name": "TestZone1",
    "numberOfUsers": 1,
    "rootId": "9E54F56ABE43411FAB6FE4852D5E64F9038A52FC0000018016E39605706B7F8F",
    "ssiAccessible": true,
    "type": "8ce19e4e-cecb-4c53-bd62-9113a2d0af8b",
    "typeName": "Private",
    "useECM": false,
    "webAccessible": true
  }
]

Now we want to check which zones we have access to. Take the sessionID value you received in the previous call (or a created bearer token) and add it as a Bearer token in an Authorization header to the following call.

A successful response will give you a JSON list of one or more zone objects. These zone objects will contain the id of the zone as well as the id of the root folder in the zone. using these two ids we can list the content of the root folder of a given zone.

List root directory of zone

curl --location --request GET http://<your-organization-name>.synkzone.com/api/zones/9391ee2e-b554-4bb5-8888-c3d7d6f0daa7/folder/9E54F56ABE43411FAB6FE4852D5E64F9038A52FC0000018016E39605706B7F8F \
--header 'Authorization: 3881603599579212345' 
[
{
    "attributes": {
      "executable": false,
      "hidden": false,
      "readProtected": false,
      "synchronize": true,
      "writeProtected": false
    },
    "deleted": false,
    "displayName": "test (2).txt",
    "folder": false,
    "id": "B2E00D1E20E645A083FE6238932AC5FC7B9E7B410000018116F834621B3EB854",
    "lastModified": "2022-06-13T16:27:39.019+02:00",
    "lastModifiedBy": "josef.smith@organization.org",
    "name": "test (2).txt",
    "parentId": "FE612674501748208CCB6AB2974E6DEDFD9463BF0000017F16E33B116FE72F10",
    "properName": "test (2)",
    "size": 4,
    "synchronizationStatus": "NotSynchronizing",
    "type": "TXT",
    "zoneId": "98762633-0b3d-40c8-8089-31d39c27a0fe"
  }
]

Let's list the root folder of a zone. Take the zone id and the root folder id of a zone listed in previous response and replace the dummy values in the example call below. If possible please pick a zone that you know contains at least a single file, ideally more, and see what it contains. We will use the same sessionID as we did in the previous call.

In the response we can see a JSON list of entries again. This time each entry in the list represents a file or a folder. You can see what each item is by looking at the folder property, if true then the object is a folder, if false then it is a file.

Note

Please note, you can use this call to list the content of any folder that you have the zone id and the folder id for.

Retrieve file metadata for a file

curl --location --request GET http://<your-organization-name>.synkzone.com/api/zones/9391ee2e-b554-4bb5-8888-c3d7d6f0daa7/files/B2E00D1E20E645A083FE6238932AC5FC7B9E7B410000018116F834621B3EB854 \
--header 'Authorization: 3881603599579212345' 

```json { "attributes": { "executable": false, "hidden": false, "readProtected": false, "synchronize": true, "writeProtected": false }, "deleted": false, "displayName": "test (2).txt", "folder": false, "id": "B2E00D1E20E645A083FE6238932AC5FC7B9E7B410000018116F834621B3EB854", "lastModified": "2022-06-13T16:27:39.019+02:00", "lastModifiedBy": "josef.smith@organization.org", "name": "test (2).txt", "parentId": "FE612674501748208CCB6AB2974E6DEDFD9463BF0000017F16E33B116FE72F10", "properName": "test (2)", "size": 4, "synchronizationStatus": "NotSynchronizing", "type": "TXT", "zoneId": "98762633-0b3d-40c8-8089-31d39c27a0fe" }

```

Take an entry from the above response that has the folder property set to false, this means the item represents a file. Lets see what meta data we can find for it. Meta data is data that describes the file/folder, but not the actual content of the file or folder. Info like file name, file size, create data, modify date and owner are examples of meta data.

The call will come back with a JSON structure listing various properties of the file itself, like size, last modified, owner, etc. The only thing missing is the actual file content itself. We will get that in the next call.

Download content of a file

curl --location --request GET http://<your-organization-name>.synkzone.com/api/zones/9391ee2e-b554-4bb5-8888-c3d7d6f0daa7/files/dad3a6697ed64324ae57a1cf6bf12920acbb4b490000017d16123123cd9019/content \
--header 'Authorization: 3881603599579212345'  \
-o file.txt
<OCTET STREAM>

Do the same call as before but add content to the end of the url. this will result in the content of the file itself being returned as an octet stream. We are here assuming the file you are downloading is a .txt file. If it is not please adjust accordingly.

You should now be able to open the file.txt file and view the downloaded content.

Upload a file

curl --location --request POST http://<your-organization-name>.synkzone.com/api/zones/9391ee2e-b554-4bb5-8888-c3d7d6f0daa7/files/9B6F3394137E43498464CCF7A18079E5DFE876750000017F16E17650E268A2E4 \
--header 'Authorization: 3881603599579212345' \
--form file=@testfile.txt \
--form fileName="testfile.txt"
{
  "attributes": {
      "executable": false,
      "hidden": false,
      "readProtected": false,
      "synchronize": true,
      "writeProtected": false
  },
  "deleted": false,
  "displayName": "testfile.txt",
  "folder": false,
  "id": "52CF0A9FCFBB41A2917D9CB51B05A33BEF301FB4000001831716953C65ACF705",
  "lastModified": "2022-09-20T15:39:58.975+02:00",
  "lastModifiedBy": "josef.smith@organization.org",
  "name": "testfile.txt",
  "parentId": "9B6F3394137E43498464CCF7A18079E5DFE876750000017F16E17650E268A2E4",
  "properName": "testfile",
  "size": 137,
  "synchronizationStatus": "NotSynchronizing",
  "type": "TXT",
  "zoneId": "9391ee2e-b554-4bb5-8888-c3d7d6f0daa7"
}

After downloading a file we might want to try to upload another. This call uploads a file as multipart/form-data. When using this request don't forget to update the path to your file specified in the --form parameter. You will need to provide a name for the uploaded file by setting the string parameter fileName.

If the file upload was successful you should see the metadata of the file as a response.