Before you begin, make sure you have:
- Node.js 18+ installed
- An Acme account (sign up here)
- Your API key from the dashboard
Install the Acme SDK using your preferred package manager:
Create a new file and initialize the Acme client:
import { Acme } from "@acme/sdk";
const client = new Acme({
apiKey: process.env.ACME_API_KEY
});
Never commit your API keys to version control. Use environment variables instead.
Let's make a simple API request to list users:
import { Acme } from "@acme/sdk";
const client = new Acme({
apiKey: process.env.ACME_API_KEY
});
async function main() {
// List all users
const users = await client.users.list();
console.log("Users:", users.data);
// Create a new user
const newUser = await client.users.create({
name: "John Doe",
email: "john@example.com"
});
console.log("Created user:", newUser);
}
main();
Execute your script:
You should see output similar to:
{
"data": [
{
"id": "usr_abc123",
"name": "John Doe",
"email": "john@example.com",
"createdAt": "2024-01-15T10:30:00Z"
}
],
"meta": {
"total": 1,
"page": 1,
"perPage": 10
}
}
Use npx tsx for quick TypeScript execution without compilation.
Always handle errors gracefully:
import { Acme, AcmeError } from "@acme/sdk";
const client = new Acme({ apiKey: process.env.ACME_API_KEY });
try {
const user = await client.users.get("usr_invalid");
} catch (error) {
if (error instanceof AcmeError) {
console.error(`Error ${error.code}: ${error.message}`);
} else {
throw error;
}
}