title: First API Call
description: Build a complete API request with proper error handling and response parsing.
First API Call
Walk through a complete request lifecycle: client setup, request, response, and error handling.
Set up the client
Initialize the SDK client with your API key.
// JavaScript
import Wontopos from "@wontopos/sdk";
const client = new Wontopos(process.env.WONTOPOS_API_KEY, {
baseUrl: "https://api.wontopos.com",
timeout: 30000,
}); # Python
import wontopos
import os
client = wontopos.Client(
api_key=os.environ["WONTOPOS_API_KEY"],
base_url="https://api.wontopos.com",
timeout=30.0,
) // Go
client := wontopos.NewClient(
os.Getenv("WONTOPOS_API_KEY"),
wontopos.WithBaseURL("https://api.wontopos.com"),
wontopos.WithTimeout(30 * time.Second),
) Make a request
List available APIs from the marketplace.
GET
/v1/marketplace/apisParameters
| Name | Type | Description |
|---|
// JavaScript
const apis = await client.marketplace.list({
limit: 10,
status: "active",
});
for (const api of apis.data) {
console.log(`${api.name} (${api.version})`);
} # Python
apis = client.marketplace.list(limit=10, status="active")
for api in apis.data:
print(f"{api.name} ({api.version})") // Go
apis, err := client.Marketplace.List(ctx, wontopos.MarketplaceListParams{
Limit: wontopos.Int(10),
Status: wontopos.String("active"),
})
if err != nil {
log.Fatal(err)
}
for _, api := range apis.Data {
fmt.Printf("%s (%s)\n", api.Name, api.Version)
} # cURL
curl https://api.wontopos.com/v1/marketplace/apis
-H "Authorization: Bearer $WONTOPOS_API_KEY"
-G -d limit=10 -d status=active Handle the response
All responses follow a consistent envelope format.
{
"data": [...],
"has_more": true,
"total_count": 42
} | Field | Type | Description |
|---|---|---|
data | array | The requested resources |
has_more | boolean | Whether more results exist |
total_count | integer | Total matching resources |
Error handling
Handle errors gracefully using SDK-specific patterns.
Always handle errors
Production code should catch and handle API errors to avoid silent failures.
// JavaScript
import { WontoposError, RateLimitError } from "@wontopos/sdk";
try {
const apis = await client.marketplace.list({ limit: 10 });
} catch (err) {
if (err instanceof RateLimitError) {
console.log(`Rate limited. Retry after ${err.retryAfter}s`);
} else if (err instanceof WontoposError) {
console.error(`API error: ${err.code} — ${err.message}`);
} else {
throw err;
}
} # Python
from wontopos.errors import WontoposError, RateLimitError
try:
apis = client.marketplace.list(limit=10)
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except WontoposError as e:
print(f"API error: {e.code} — {e.message}") // Go
apis, err := client.Marketplace.List(ctx, params)
if err != nil {
var apiErr *wontopos.Error
if errors.As(err, &apiErr) {
fmt.Printf("API error: %s — %s\n", apiErr.Code, apiErr.Message)
} else {
log.Fatal(err)
}
} Common error codes
| Status | Code | Description |
|---|---|---|
401 | unauthorized | Invalid or missing API key |
403 | forbidden | Insufficient permissions |
404 | not_found | Resource does not exist |
429 | rate_limited | Too many requests |
500 | internal_error | Server-side issue — retry with backoff |
Automatic retries
The SDK automatically retries on `429` and `5xx` errors with exponential backoff. Configure via `maxRetries`.
Next steps
- Environments — Switch between sandbox and production
- Authentication — OAuth 2.0 and scoped tokens
- API Reference — Full endpoint documentation