Quick Start
Get up and running with the SDK in just a few minutes.
Step 1: Import the SDK
First, import the SDK into your project:
app.ts
import { SDK, Config } from "our-sdk";
Step 2: Initialize
Create a new instance of the SDK with your configuration:
app.ts
const sdk = new SDK({
apiKey: process.env.SDK_API_KEY,
environment: "production",
});
Step 3: Make Your First Call
Now you're ready to use the SDK:
example.ts
async function example() {
try {
const response = await sdk.getData({
id: "123",
options: {
include: ["details", "metadata"],
},
});
console.log("Success:", response);
} catch (error) {
console.error("Error:", error);
}
}
example();
Complete Example
Here's a complete working example:
main.ts
import { SDK } from "our-sdk";
// Initialize the SDK
const sdk = new SDK({
apiKey: process.env.SDK_API_KEY,
environment: "production",
options: {
timeout: 5000,
retries: 3,
},
});
// Define an async function
async function main() {
try {
// Fetch data
const data = await sdk.getData({ id: "123" });
console.log("Data:", data);
// Create a resource
const created = await sdk.create({
name: "My Resource",
description: "A sample resource",
});
console.log("Created:", created);
// Update a resource
const updated = await sdk.update(created.id, {
description: "Updated description",
});
console.log("Updated:", updated);
} catch (error) {
if (error instanceof SDK.Error) {
console.error("SDK Error:", error.message);
console.error("Error Code:", error.code);
} else {
console.error("Unexpected error:", error);
}
}
}
main();
Congratulations! You've made your first SDK call. 🎉
Error Handling
The SDK provides detailed error information:
error-handling.ts
try {
await sdk.getData({ id: "invalid" });
} catch (error) {
if (error instanceof SDK.NotFoundError) {
console.log("Resource not found");
} else if (error instanceof SDK.ValidationError) {
console.log("Invalid parameters:", error.details);
} else {
console.log("Unknown error:", error);
}
}
Next Steps
- Learn about Authentication
- Explore API Methods
- Check out Examples
Need help? Check out our API Reference for detailed documentation on all available methods.