Website | Documentation | API Docs | Twitter
The Openfort Node library provides convenient access to the Openfort API from applications written in server-side JavaScript.
See the openfort-node
API docs for Node.js.
Node 14 or higher.
npm install @openfort/openfort-node
yarn add @openfort/openfort-node
The package needs to be configured with your account's secret key, which is available in the Openfort Dashboard. Require it with the key's value:
const openfort = require('@openfort/openfort-node')('sk_test_...');
openfort.players.create({
name: 'Joan McCoain',
description: 'API created player'
})
.then(player => console.log(player.id))
.catch(error => console.error(error));
Or using ES modules and async
/await
:
import Openfort from '@openfort/openfort-node';
const openfort = new Openfort('sk_test_...');
const player = await openfort.players.create({
name: 'customer@example.com',
description: 'API created player'
});
console.log(player.id);
Below code snippet shows exemplary usage of the configuration and the API.
import Openfort from "@openfort/openfort-node";
async function example() {
const openfort = new Openfort("sk_test_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
const players = await openfort.players.list();
for (const player of players.data) {
console.log(player.id);
}
const newPlayer = await openfort.players.create({name: "Test"});
console.log(newPlayer.id)
const transactionIntents = await openfort.transactionIntents.list();
for (const intent of transactionIntents.data) {
console.log(`Intent ${intent.id} by ${intent.player.name}`);
}
}
example().catch((e) => console.error(e));
New features and bug fixes are released on the latest major version of the openfort
package. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.