Skip to main content

SDK Examples

Code examples for calling the ToolBox API from different languages and environments.

Base URL​

All examples use:

https://www.toolbox-kit.com/api/v1/

JavaScript / TypeScript​

Browser (fetch)​

const API_KEY = 'tb_your_api_key_here';
const BASE_URL = 'https://www.toolbox-kit.com/api/v1';

async function toolboxPost(endpoint, body) {
const res = await fetch(`${BASE_URL}/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
body: JSON.stringify(body),
});

if (!res.ok) {
const err = await res.json();
throw new Error(err.error || `HTTP ${res.status}`);
}

return res.json();
}

// Format JSON
const result = await toolboxPost('json-format', {
json: '{"name":"test","age":25}',
indent: 2,
});
console.log(result.result);

Node.js (node-fetch or built-in fetch)​

Node.js 18+ has built-in fetch. For older versions, install node-fetch.

const API_KEY = process.env.TOOLBOX_API_KEY;
const BASE_URL = 'https://www.toolbox-kit.com/api/v1';

async function toolboxPost(endpoint: string, body: Record<string, unknown>) {
const res = await fetch(`${BASE_URL}/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
body: JSON.stringify(body),
});

if (!res.ok) {
const err = await res.json() as { error: string };
throw new Error(err.error || `HTTP ${res.status}`);
}

return res.json();
}

// Generate a hash
const hash = await toolboxPost('hash', {
input: 'hello world',
algorithm: 'sha256',
});
console.log(hash.result);

// Generate UUIDs
const uuids = await toolboxPost('uuid', { count: 5, version: 'v4' });
console.log(uuids.result);

Python​

Using requests​

import requests
import os

API_KEY = os.environ["TOOLBOX_API_KEY"]
BASE_URL = "https://www.toolbox-kit.com/api/v1"

def toolbox_post(endpoint, body):
res = requests.post(
f"{BASE_URL}/{endpoint}",
json=body,
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}",
},
)
res.raise_for_status()
return res.json()

# Format JSON
result = toolbox_post("json-format", {
"json": '{"name":"test"}',
"indent": 2,
})
print(result["result"])

# Generate a password
password = toolbox_post("password", {
"length": 24,
"uppercase": True,
"lowercase": True,
"numbers": True,
"symbols": True,
})
print(password["result"])

# Convert CSV to JSON
csv_data = toolbox_post("csv-json", {
"mode": "csv-to-json",
"csv": "name,age\nAlice,30\nBob,25",
})
print(csv_data["result"])

With error handling​

import requests
import time

def toolbox_post(endpoint, body, max_retries=3):
for attempt in range(max_retries):
res = requests.post(
f"{BASE_URL}/{endpoint}",
json=body,
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}",
},
)

if res.status_code == 429:
reset = int(res.headers.get("X-RateLimit-Reset", 0))
wait = max(reset - int(time.time()), 1)
print(f"Rate limited. Waiting {wait}s...")
time.sleep(wait)
continue

res.raise_for_status()
return res.json()

raise Exception("Max retries exceeded")

cURL​

POST request​

curl -X POST https://www.toolbox-kit.com/api/v1/json-format \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tb_your_api_key_here" \
-d '{"json": "{\"name\":\"test\"}", "indent": 2}'

Hash generation​

curl -X POST https://www.toolbox-kit.com/api/v1/hash \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tb_your_api_key_here" \
-d '{"input": "hello world", "algorithm": "sha256"}'

Base64 encode​

curl -X POST https://www.toolbox-kit.com/api/v1/base64 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tb_your_api_key_here" \
-d '{"input": "Hello, World!", "mode": "encode"}'

Tool chaining​

Chain multiple operations in a single request:

curl -X POST https://www.toolbox-kit.com/api/v1/tool-chain \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tb_your_api_key_here" \
-d '{
"input": "Hello World",
"steps": [
{"tool": "case-convert", "params": {"targetCase": "lower"}},
{"tool": "slugify"},
{"tool": "base64", "params": {"mode": "encode"}}
]
}'

Common patterns​

Error handling​

Every error response includes an error field:

try {
const result = await toolboxPost('json-validate', { input: 'not json' });
} catch (err) {
// err.message contains the error description
console.error('Validation failed:', err.message);
}

Rate limit retry with backoff​

async function toolboxWithRetry(endpoint, body, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
const res = await fetch(`${BASE_URL}/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
body: JSON.stringify(body),
});

if (res.status === 429) {
const resetAt = Number(res.headers.get('X-RateLimit-Reset'));
const waitMs = Math.max((resetAt * 1000) - Date.now(), 1000);
await new Promise(r => setTimeout(r, waitMs));
continue;
}

if (!res.ok) {
const err = await res.json();
throw new Error(err.error);
}

return res.json();
}

throw new Error('Max retries exceeded');
}

Batch operations​

Process multiple items by calling the API in sequence:

const items = ['item1', 'item2', 'item3'];
const results = [];

for (const item of items) {
const result = await toolboxPost('hash', {
input: item,
algorithm: 'sha256',
});
results.push(result);
}

For checking multiple URLs at once, use the check_links endpoint which accepts up to 20 URLs in a single request:

const result = await toolboxPost('check-links', {
urls: [
'https://example.com',
'https://example.com/about',
'https://example.com/contact',
],
});
console.log(result); // status codes and redirect info for each URL

Reading rate limit headers​

const res = await fetch(`${BASE_URL}/json-format`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
body: JSON.stringify({ json: '{}' }),
});

const limit = res.headers.get('X-RateLimit-Limit');
const remaining = res.headers.get('X-RateLimit-Remaining');
const reset = res.headers.get('X-RateLimit-Reset');

console.log(`${remaining}/${limit} requests remaining. Resets at ${new Date(Number(reset) * 1000)}`);