Using the API

The Qarnot API is the primary mean to interact with Qarnot cloud computing services as all Qarnot interfaces (SDKs, CLI and GUIs) are developed around it. It allows users to launch, manage and monitor payloads running on distributed computing nodes. The following paragraphs are an overview of the basic API requests, you can refer to the API documentation for a more in depth look.

1. Requirements

In order to use the API provided by Qarnot, you must be able to issue web requests. To do so, make sure curl is installed on Linux or Invoke.RestMethod on Windows.

2. Retrieve your token

To set your connection information, you will need to get your secret token. It will be available on your Qarnot account page once you have created one.

3. Create a task

You can create a task by submitting a POST request to https://api.qarnot.com/tasks. The configuration of the task is described by a JSON. Here is an example of a JSON file and a request to create a basic Hello World task:

Bash

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: <<<YOUR_SECRET_TOKEN>>>" \
-d @helloworld.json \
https://api.qarnot.com/tasks

Powershell

$headers = @{
	'Content-Type'='application/json'
	'Authorization'='<<<YOUR_SECRET_TOKEN>>>'
 }

$body = Get-Content "./helloworld.json"

Invoke-RestMethod `
-Uri https://api.qarnot.com/tasks `
-Method 'Post' `
-Headers $headers `
-Body $body `

Helloworld.json

{
    "name": "HelloWorld",
    "profile": "ubuntu",
    "instanceCount": 1,
    "maxRetriesPerInstance": 5,
    "constants" : [
        {
           "key" : "DOCKER_CMD",
           "value" :  "echo hello world"
       }
    ]
}

If you successfully launch a task, you should get the uuid (Universally unique identifier) of the task returned.

4. Monitor your task

You can retrieve stdout by sending a GET request to https://api.qarnot.com/tasks/{uuid}/stdout, where {uuid} is the uuid of the task, returned when you create a task.

For stderr, replace stdout by stderr in the API endpoint: https://api.qarnot.com/tasks/{uuid}/stderr.

To get a task's information, you need to make a GET request to https://api.qarnot.com/tasks/{uuid}.

Bash

curl -X GET \
-H "Authorization: <<<YOUR_SECRET_TOKEN>>>" \
https://api.qarnot.com/tasks/{uuid}/stdout

Powershell

$headers = @{
     'Authorization'='<<<YOUR_SECRET_TOKEN>>>'
 }

Invoke-RestMethod `
-Method 'Get' `
-Uri https://api.qarnot.com/tasks/{uuid}/stdout `
-Headers $headers

5. Manage your data

Use a S3 SDK or a S3 compatible software to manage your data. More information is available in the Managing your data section.

Related Article

For more information on launching tasks please consult the following articles