/task/{id}

GET SYNC

Returns information about a previously created task from an asynchronous call.

GET /api/v1/task/{id}

Description

This endpoint retrieves information about a previously created task. Tasks are created by all asynchronous API calls, which return a TaskID (GUID). This GUID must be passed to this endpoint to check the task's status, progress, and to retrieve the results upon completion.

Note

This is a synchronous API call that returns the current state of an asynchronous task. You should poll this endpoint at regular intervals until the task is completed.

Parameters

Path Parameters

Parameter Type Required Description
id string Yes 32-hex character task GUID that was returned by the asynchronous API call.

Response

Returns a 200 OK response with a JSON object containing details about the task and its status.

Response Properties

id string
The task identifier (GUID).
status string
The current status of the task. Possible values are "running", "completed", or "error".
progress integer
The progress of the task as a percentage (0-100).
started integer
Unix timestamp when the task was created.
finished integer
Unix timestamp when the task was completed. Only present when status is "completed" or "error".
message string
Status message or error details.
data object
The result data for the completed task. Only present when status is "completed". The structure of this object depends on the type of task.

Example Response for an Echo Task

{
    "payload": {
        "id": "bdc8e99d-dd8a-40e9-8840-f9f8eef16c71",
        "status": "completed",
        "progress": 100,
        "started": 1678436330,
        "finished": 1678436332,
        "message": "Command Completed",
        "data": {
            "online": 25,
            "pownstring": "ppppppppppppppppppppppppp",
            "pownarray": [
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
            ],
            "latencies": [
                1104, 1104, 1417, 1407, 1397, 1416, 1405, 1412, 1397, 1407,
                1406, 1397, 1413, 1412, 1405, 1398, 1413, 1398, 1414, 1397,
                1410, 1404, 1403, 1415, 1113
            ]
        }
    },
    "status": "success"
}

Example Response for a Detect Task

{
    "payload": {
        "id": "4e1b284c-04f5-4d3f-8683-98d6fd2427f2",
        "status": "completed",
        "progress": 100,
        "started": 1678436959,
        "finished": 1678436960,
        "message": "Command Completed",
        "data": {
            "TotalCoins": 3000000020,
            "TotalCheckedCoins": 3000000020,
            "TotalAuthentic": 3000000020,
            "TotalAlreadyFracked": 0,
            "TotalAlreadyLimbo": 0,
            "TotalFracked": 0,
            "TotalCounterfeit": 0,
            "TotalLimbo": 0,
            "TotalErrors": 0,
            "Details": null,
            "Coins": [
                {
                    "sn": 16,
                    "pownstring": "ppppppppppppppppppppppppp",
                    "result": "Authentic"
                },
                {
                    "sn": 17,
                    "pownstring": "ppppppppppppppppppppppppp",
                    "result": "Authentic"
                },
                {
                    "sn": 23,
                    "pownstring": "ppppppppppppppppppppppppp",
                    "result": "Authentic"
                },
                {
                    "sn": 24,
                    "pownstring": "ppppppppppppppppppppppppp",
                    "result": "Authentic"
                },
                {
                    "sn": 25,
                    "pownstring": "ppppppppppppppppppppppppp",
                    "result": "Authentic"
                }
            ]
        }
    },
    "status": "success"
}

Examples

JavaScript Example

// Using Fetch API to check task status
const apiHost = 'http://localhost:8004';

// The task ID returned from an asynchronous call
const taskId = 'bdc8e99d-dd8a-40e9-8840-f9f8eef16c71';

// Function to check task status
function checkTaskStatus(taskId) {
    return fetch(`${apiHost}/api/v1/task/${taskId}`)
        .then(response => {
            if (!response.ok) {
                throw new Error(`HTTP error! Status: ${response.status}`);
            }
            return response.json();
        })
        .then(data => {
            console.log(`Task status: ${data.payload.status}`);
            console.log(`Progress: ${data.payload.progress}%`);
            
            // Check if the task is complete
            if (data.payload.status === 'completed') {
                console.log('Task completed!');
                console.log('Result data:', data.payload.data);
                return data.payload.data;
            } else if (data.payload.status === 'error') {
                console.error('Task error:', data.payload.message);
                throw new Error(data.payload.message);
            } else {
                // Task is still running, continue polling
                console.log('Task is still running. Checking again in 1 second...');
                return new Promise(resolve => {
                    setTimeout(() => {
                        resolve(checkTaskStatus(taskId));
                    }, 1000);
                });
            }
        });
}

// Start checking the task status
checkTaskStatus(taskId)
    .then(resultData => {
        console.log('Final result:', resultData);
        // Handle the completed task data here
    })
    .catch(error => {
        console.error('Error checking task status:', error);
    });

cURL Example

# Check the task status (replace with your actual task ID)
curl -X GET "http://localhost:8004/api/v1/task/bdc8e99d-dd8a-40e9-8840-f9f8eef16c71" \
  -H "accept: application/json"

# Example response:
# {
#   "payload": {
#     "id": "bdc8e99d-dd8a-40e9-8840-f9f8eef16c71",
#     "status": "completed",
#     "progress": 100,
#     "started": 1678436330,
#     "finished": 1678436332,
#     "message": "Command Completed",
#     "data": {
#       "online": 25,
#       "pownstring": "ppppppppppppppppppppppppp",
#       "pownarray": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
#       "latencies": [1104, 1104, 1417, 1407, 1397, 1416, 1405, 1412, 1397, 1407, 1406, 1397, 1413, 1412, 1405, 1398, 1413, 1398, 1414, 1397, 1410, 1404, 1403, 1415, 1113]
#     }
#   },
#   "status": "success"
# }