Dasyhub API documentation

Introduction

What is this API?

The Dasyhub API provides CRUD methods for interacting with the files of the existing projects within an account.


A Swagger Documentation is also available and can be accessed when the user is logged-in.

Authentication for a project

The API provides different authentication methods for accessing the files within a project. Currently, the following methods are available:

  • Basic-Authentication with a pair of username:password
  • Token-Authentication with a specific Token

The authentications can be created within a project by switching to the API tab. Only API accounts that are created there can be used to acess the API.

Moreover, this allows the administration of existing API accounts and provides the required Project-ID.

CRUD

Request endpoint status

Description

Get the status of the connection for the specific API account.

Parameters

GET https://api.dasyhub.com/api/v1/status/
Header
Authorization string

The username and password pair that must be provided when Basic-Authentication is used.

X-API-Key string

The Token that must be provided when Token-Authentication is used.

Path parameter
PROJECT-ID string required

The Project-ID which can be found on the API overview page.

Query parameter
-

Examples

  
#######################
# Basic-Authentication
#
# Replace: `PROJECT-ID`, `username` and `BASIC-PASSWORD`
#######################
curl -u username:BASIC-PASSWORD https://api.dasyhub.com/api/v1/status/PROJECT-ID

#######################
# Token-Authentication
#
# Replace: `PROJECT-ID` and `AUTHENTICATION-TOKEN`
#######################
curl -H "X-API-Key: AUTHENTICATION-TOKEN" https://api.dasyhub.com/api/v1/status/PROJECT-ID
  
  
#######################
# Basic-Authentication
#
# Replace: `PROJECT-ID`, `username` and `BASIC-PASSWORD`
#######################
http -a username:'BASIC-PASSWORD' https://api.dasyhub.com/api/v1/status/PROJECT-ID

#######################
# Token-Authentication
#
# Replace: `PROJECT-ID` and `AUTHENTICATION-TOKEN`
#######################
http https://api.dasyhub.com/api/v1/status/PROJECT-ID X-API-Key:AUTHENTICATION-TOKEN
  
  
/**
 * Basic-Authentication
 *
 * Replace: `PROJECT-ID`, `username` and `password`
 */
const token = btoa(`${username}:${password}`);

fetch("https://api.dasyhub.com/api/v1/status/PROJECT-ID", {
  method: 'GET',
  headers: {
    'Authorization': `Basic ${token}`
  }
})
  .then(response => {
    // Log the status code
    console.log('Status Code:', response.status);
  })
  .catch(error => {
    console.error('Error:', error);
  });

/**
 * Token-Authentication
 *
 * Replace: `PROJECT-ID` and `AUTHENTICATION-TOKEN`
 */
fetch("https://api.dasyhub.com/api/v1/status/PROJECT-ID", {
  method: 'GET',
  headers: {
    'X-API-Key': 'AUTHENTICATION-TOKEN'
  }
})
  .then(response => {
    // Log the status code
    console.log('Status Code:', response.status);
  })
  .catch(error => {
    console.error('Error:', error);
  });
  

Post a file into the project

Description

Post a file to a specific project.

Parameters

POST https://api.dasyhub.com/api/v1/file/PROJECT-ID
Header
Authorization string

The username and password pair that must be provided when Basic-Authentication is used.

X-API-Key string

The Token that must be provided when Token-Authentication is used.

Path parameter
PROJECT-ID string required

The Project-ID which can be found on the API overview page.

FILENAME string required

The name of the file with the file extension that is requested.

Query parameter
-

Examples

  
#######################
# Basic-Authentication
#
# Replace: `PROJECT-ID`, `FILENAME`, `username` and `BASIC-PASSWORD`
#######################
curl -u username:BASIC-PASSWORD -F file=@FILENAME https://api.dasyhub.com/api/v1/file/PROJECT-ID

#######################
# Token-Authentication
#
# Replace: `PROJECT-ID`, `FILENAME` and `AUTHENTICATION-TOKEN`
#######################
curl -F file=@FILENAME -H "X-API-Key: AUTHENTICATION-TOKEN" https://api.dasyhub.com/api/v1/file/PROJECT-ID
  
  
#######################
# Basic-Authentication
#
# Replace: `PROJECT-ID`, `FILENAME`, `username` and `BASIC-PASSWORD`
#######################
http -a username:'BASIC-PASSWORD' -f POST https://api.dasyhub.com/api/v1/file/PROJECT-ID file@FILENAME

#######################
# Token-Authentication
#
# Replace: `PROJECT-ID`, `FILENAME` and `AUTHENTICATION-TOKEN`
#######################
http -f POST https://api.dasyhub.com/api/v1/file/PROJECT-ID file@FILENAME X-API-Key:AUTHENTICATION-TOKEN
  
  
/**
 * Basic-Authentication
 *
 * Replace: `PROJECT-ID`, `FILE`, `username` and `password`
 */
const fs = require('fs');
const crypto = require('crypto');
const FormData = require('form-data');
const fetch = require('node-fetch'); // node-fetch 2.6.1 used

async function postFile(filePath, endpoint, includeHash = false) {
  // Create a new FormData instance and append the file.
  const form = new FormData();
  form.append('file', fs.createReadStream(filePath));

  // Get the default headers from the FormData instance (includes the multipart boundary).
  const headers = form.getHeaders();

  // Construct the Basic Auth header.
  const auth = btoa(`${username}:${password}`);
  headers['Authorization'] = `Basic ${auth}`;

  if (includeHash) {
    // Compute the SHA-256 hash of the file.
    // Note: For very large files, consider a streaming approach rather than reading synchronously.
    const fileBuffer = fs.readFileSync(filePath);
    const hash = crypto.createHash('sha256').update(fileBuffer).digest('hex');
    headers['X-Hash-Value'] = hash;
  }

  // Perform the HTTP POST request using node-fetch.
  const response = await fetch(endpoint, {
    method: 'POST',
    headers: headers,
    body: form
  });

  return response;
}

// Example usage:
(async () => {
  const filePath = 'path/to/your/local/FILE';
  const endpoint = 'https://api.dasyhub.com/api/v1/file/PROJECT-ID';
  const username = 'username'; // Replace with your username.
  const password = 'password'; // Replace with your password.

  try {
    const res = await postFile(filePath, endpoint, username, password, true); // Pass true to include the hash header
    if (res.ok) {
      console.log('File uploaded successfully');
    } else {
      console.error(`Upload failed with status: ${res.status}`);
    }
  } catch (err) {
    console.error('Error during file upload:', err);
  }
})();

/**
 * Token-Authentication
 *
 * Replace: `PROJECT-ID`, `FILE` and `AUTHENTICATION-TOKEN`
 */
const fs = require('fs');
const crypto = require('crypto');
const FormData = require('form-data');
const fetch = require('node-fetch'); // node-fetch 2.6.1 used

async function postFileWithTokenAuth(filePath, endpoint, token, includeHash = false) {
  // Create a new FormData instance and append the file with the form field "file".
  const form = new FormData();
  form.append('file', fs.createReadStream(filePath));

  // Get the default headers from the FormData instance (includes the multipart boundary).
  const headers = form.getHeaders();

  // Add the token authentication header.
  headers['X-API-Key'] = token;

  if (includeHash) {
    // Compute the SHA-256 hash of the file.
    // Note: For large files, consider a streaming approach rather than reading synchronously.
    const fileBuffer = fs.readFileSync(filePath);
    const hash = crypto.createHash('sha256').update(fileBuffer).digest('hex');
    headers['X-Hash-Value'] = hash;
  }

  // Perform the HTTP POST request using node-fetch.
  const response = await fetch(endpoint, {
    method: 'POST',
    headers: headers,
    body: form
  });

  return response;
}

// Example usage:
(async () => {
  const filePath = 'path/to/your/local/FILE';
  const endpoint = 'https://api.dasyhub.com/api/v1/file/PROJECT-ID';
  const token = 'AUTHENTICATION_TOKEN';

  try {
    const res = await postFileWithTokenAuth(filePath, endpoint, token, true); // Set true to include the hash header.
    if (res.ok) {
      console.log('File uploaded successfully with token authentication');
    } else {
      console.error(`Upload failed with status: ${res.status}`);
    }
  } catch (err) {
    console.error('Error during file upload:', err);
  }
})();
  

Get a file from a project

Description

Get a file from a specific project.

Parameters

GET https://api.dasyhub.com/api/v1/file/PROJECT-ID/FILENAME
Header
Authorization string

The username and password pair that must be provided when Basic-Authentication is used.

X-Hash-Value string

The SHA265 Hash value of the file that can be provided to check the correct transfer of the file. (Optional)

X-API-Key string

The Token that must be provided when Token-Authentication is used.

Path parameter
PROJECT-ID string required

The Project-ID which can be found on the API overview page.

FILENAME string required

The name of the file with the file extension that is requested.

Query parameter
-

Examples

  
#######################
# Basic-Authentication
#
# Replace: `PROJECT-ID`, `FILENAME`, `username` and `BASIC-PASSWORD`
#######################
curl -u username:BASIC-PASSWORD https://api.dasyhub.com/api/v1/file/PROJECT-ID/FILENAME

#######################
# Token-Authentication
#
# Replace: `PROJECT-ID`, `FILENAME` and `AUTHENTICATION-TOKEN`
#######################
curl -H "X-API-Key: AUTHENTICATION-TOKEN" https://api.dasyhub.com/api/v1/file/PROJECT-ID/FILENAME
  
  
#######################
# Basic-Authentication
#
# Replace: `PROJECT-ID`, `FILENAME`, `username` and `BASIC-PASSWORD`
#######################
http -a username:'BASIC-PASSWORD' https://api.dasyhub.com/api/v1/file/PROJECT-ID/FILENAME

#######################
# Token-Authentication
#
# Replace: `PROJECT-ID`, `FILENAME` and `AUTHENTICATION-TOKEN`
#######################
http https://api.dasyhub.com/api/v1/file/PROJECT-ID/FILENAME X-API-Key:AUTHENTICATION-TOKEN
  
  
/**
 * Basic-Authentication
 *
 * Replace: `PROJECT-ID`, `FILENAME`, `username` and `password`
 */
const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch'); // Import node-fetch

// Predefined local file path (adjust as needed)
const localFilePath = path.join(process.cwd(), 'FILENAME');

async function downloadFile() {
  try {
    const response = await fetch(`https://api.dasyhub.com/api/v1/file/PROJECT-ID/FILENAME`, {
      method: 'GET',
      headers: {
        'Authorization': 'Basic ' + btoa(`${username}:${password}`)
      }
    });

    if (!response.ok) {
      throw new Error(`Error fetching file: ${response.status}`);
    }

    // Create a writable stream to the predefined local file.
    const fileStream = fs.createWriteStream(localFilePath);

    // node-fetch returns a Node.js stream, which has a .pipe() method
    response.body.pipe(fileStream);

    response.body.on('error', (err) => {
      console.error('Stream error:', err);
    });

    fileStream.on('finish', () => {
      console.log('File downloaded successfully to', localFilePath);
    });
  } catch (error) {
    console.error('Download failed:', error);
  }
}

downloadFile();

/**
 * Token-Authentication
 *
 * Replace: `PROJECT-ID`, `FILENAME` and `AUTHENTICATION-TOKEN`
 */
const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch'); // Import node-fetch

// Predefined local file path (adjust as needed)
const localFilePath = path.join(process.cwd(), 'FILENAME');

async function downloadFile() {
  try {
    const response = await fetch(`https://api.dasyhub.com/api/v1/file/PROJECT-ID/FILENAME`, {
      method: 'GET',
      headers: {
        'X-API-Key': 'AUTHENTICATION-TOKEN'
      }
    });

    if (!response.ok) {
      throw new Error(`Error fetching file: ${response.status}`);
    }

    // Create a writable stream to the predefined local file.
    const fileStream = fs.createWriteStream(localFilePath);

    // node-fetch returns a Node.js stream, which has a .pipe() method
    response.body.pipe(fileStream);

    response.body.on('error', (err) => {
      console.error('Stream error:', err);
    });

    fileStream.on('finish', () => {
      console.log('File downloaded successfully to', localFilePath);
    });
  } catch (error) {
    console.error('Download failed:', error);
  }
}

downloadFile();
  

Miscellaneous

Access limits per minute

The API has an access limit per minute which depends on the active plan for the main account.

The number of accesses per minute can be seen on the pricing page.