Skip to main content

Example request

Keys & params​

Here are the public and secret keys we will use:

Public key84c92f2c5686d350d3d2d15c2073ec23
Private (secret) key1jHj0HORiWhpmw9QqOXsLoZjweVm7BWoT5WPWC2AbFsuWl95

In this example, we are going to list our account publications. The following parameters will be used:

apikey84c92f2c5686d350d3d2d15c2073ec23
actionAPI.fetchAccountBooks
outputJSON

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.

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));