This TypeScript client library provides a comprehensive and easy-to-use interface to Karla's APIs and other services. Designed to help developers integrate and interact with Karla efficiently, this client supports all major service features including merchant, campaign, voucher, order and shipment management, data retrieval, and real-time updates.
- Authentication: Handle API authentication seamlessly.
- Data Retrieval: Fetch data using simple asynchronous methods.
- Webhooks: Set up and manage webhooks.
- Error Handling: Robust error handling tailored for clarity and quick debugging.
- Type Safety: Full TypeScript support ensures type safety across all interactions.
Install the package via npm:
npm install @gokarla-io/client
Or using Yarn:
yarn add @gokarla-io/client
Here's a quick example to get you started with the Karla TypeScript client.
This example demonstrates how to authenticate and fetch merchant data:
import { Karla } from "@gokarla-io/client";
import type { KarlaREST } from "@gokarla-io/client";
const { rest: apiClient } = Karla({
auth: {
username: process.env.KARLA_API_USERNAME,
apiKey: process.env.KARLA_API_TOKEN,
},
});
The REST interface is exposed under the rest
attribute. More interfaces will be available in the future.
const { data } = await apiClient.GET("/v1/merchants", {
params: { query: { page: 1, per_page: 100 } },
});
This client library offers various configuration options to tailor the API client to your needs:
- baseUrl: Override the default API endpoint for testing or development purposes.
- headers: Customize headers sent with each request.
Example of setting configuration options:
const karla = Karla({
baseUrl: process.env.KARLA_API_URL,
headers: {
"Custom-Header": "value",
},
});