Example request
Keys & params
Here are the public and secret keys we will use:
| Public key | 84c92f2c5686d350d3d2d15c2073ec23 |
| Private (secret) key | 1jHj0HORiWhpmw9QqOXsLoZjweVm7BWoT5WPWC2AbFsuWl95 |
In this example, we are going to list our account publications. The following parameters will be used:
| apikey | 84c92f2c5686d350d3d2d15c2073ec23 |
| action | API.fetchAccountBooks |
| output | JSON |
Signature
To calculate the signature of this request, we concatenate the API secret key with the name-value alphabetically sorted parameters:
1jHj0HORiWhpmw9QqOXsLoZjweVm7BWoT5WPWC2AbFsuWl95actionAPI.fetchAccountBooksapikey84c92f2c5686d350d3d2d15c2073ec23outputJSON
We get the MD5 hash of this string:
C867521B01925CE79E16FD630F2BE646
The complete request looks like this:
https://api.calameo.com/1.0?apikey=84c92f2c5686d350d3d2d15c2073ec23&action=API.fetchAccountBooks&output=JSON&signature=C867521B01925CE79E16FD630F2BE646
Request examples by language
The following examples compute the signature and send the request.
danger
Never expose your secret key in client-side code (browser JavaScript, mobile apps…). Anyone could read it and send requests on behalf of your account. Always sign your requests on your server.
- Node.js
- PHP
- Python
import crypto from 'node:crypto';
const API_KEY = '84c92f2c5686d350d3d2d15c2073ec23';
const API_SECRET = '1jHj0HORiWhpmw9QqOXsLoZjweVm7BWoT5WPWC2AbFsuWl95';
function sign(params) {
const pairs = Object.keys(params)
.sort()
.map((key) => key + params[key])
.join('');
return crypto.createHash('md5').update(API_SECRET + pairs).digest('hex').toUpperCase();
}
async function getBooks() {
const params = {
apikey: API_KEY,
action: 'API.fetchAccountBooks',
output: 'JSON',
};
params.signature = sign(params);
const response = await fetch('https://api.calameo.com/1.0?' + new URLSearchParams(params));
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();
console.log(data);
}
getBooks().catch((error) => console.error('Error:', error));
<?php
$apiKey = '84c92f2c5686d350d3d2d15c2073ec23';
$apiSecret = '1jHj0HORiWhpmw9QqOXsLoZjweVm7BWoT5WPWC2AbFsuWl95';
$params = [
'apikey' => $apiKey,
'action' => 'API.fetchAccountBooks',
'output' => 'JSON',
];
ksort($params);
$pairs = '';
foreach ($params as $key => $value) {
$pairs .= $key . $value;
}
$params['signature'] = strtoupper(md5($apiSecret . $pairs));
$ch = curl_init('https://api.calameo.com/1.0?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
die('cURL error: ' . curl_error($ch));
}
curl_close($ch);
$data = json_decode($response, true);
var_dump($data);
import hashlib
import requests
API_KEY = '84c92f2c5686d350d3d2d15c2073ec23'
API_SECRET = '1jHj0HORiWhpmw9QqOXsLoZjweVm7BWoT5WPWC2AbFsuWl95'
params = {
'apikey': API_KEY,
'action': 'API.fetchAccountBooks',
'output': 'JSON',
}
pairs = ''.join(key + params[key] for key in sorted(params))
params['signature'] = hashlib.md5((API_SECRET + pairs).encode('utf-8')).hexdigest().upper()
response = requests.get('https://api.calameo.com/1.0', params=params)
response.raise_for_status()
print(response.json())