The following examples all request the balances for the Silktide account. In practice, you will likely want to use other API endpoints.

See Quickstart for how to get your credentials.

Node

This example requires you install Axios as a HTTP client.

const axios = require('axios');

// Replace these with your Silktide API credentials
const apiHost = '<https://api.eu.silktide.com>';
const apiKey = "<YOUR_API_KEY>";

axios.get(`${apiHost}/v1/balances`, {
    headers: {
        'Authorization': `silktide token=${apiKey}`
    }
})
.then(response => {
    const balances = response.data;
    console.log(`You have ${balances.maxPages} pages remaining`);
})
.catch(error => {
    console.error('Error:', error);
});

PHP

This example requires you install Guzzle as a HTTP client.

<?php
require 'vendor/autoload.php';

use GuzzleHttp\\Client;

// Replace these with your Silktide API credentials
$apiHost = '<https://api.eu.silktide.com>';
$apiKey = "<YOUR_API_KEY>";

$client = new Client();

try {
	$response = $client->request('GET', $apiHost . '/v1/balances', [
	    'headers' => [
	      'Authorization' => 'silktide token=' . $apiKey
    ]
	]);
} catch (\\GuzzleHttp\\Exception\\GuzzleException $e) {
	// Handle the error appropriately
  echo $e->getMessage();
}

$balances = json_decode($response->getBody(), true);

echo "You have {$balances['maxPages']} pages remaining";

Python 3

This example requires you install Requests as a HTTP client.

import requests

url = '<https://api.eu.silktide.com/v1/balances>'
headers = {
    'Authorization': 'silktide token=<YOUR_API_KEY>'
}

try:
    response = requests.get(url, headers=headers)
    response.raise_for_status()

    # Convert the response to JSON
    data = response.json()

    # Print or process the data
    print(data)
except requests.exceptions.HTTPError as err:
    print(f"Http Error: {err}")