Prerequisites
- Node.js 18+ or Bun 1.0+
- An S4Kit account with an API key
- Access to an SAP S/4HANA system (configured in the platform)
Step 1: Install the SDK
Step 2: Initialize the Client
Create an S4Kit client with your API key and connection name:
import { S4Kit } from 's4kit';
const client = new S4Kit({
apiKey: process.env.S4KIT_API_KEY, // Your API key
connection: 'production' // Your SAP instance alias
});
Never commit your API key to source control. Use environment variables instead.
Step 3: Make Your First Request
Query SAP entities using the intuitive SDK interface:
// List business partners
const partners = await client.A_BusinessPartner.list({
top: 10,
select: ['BusinessPartner', 'BusinessPartnerName', 'BusinessPartnerCategory']
});
console.log(partners);
// [
// { BusinessPartner: '10100001', BusinessPartnerName: 'Acme Corp', ... },
// { BusinessPartner: '10100002', BusinessPartnerName: 'Global Inc', ... },
// ...
// ]
Step 4: Try CRUD Operations
Read
Create
Update
Delete
// Get a single entity by ID
const partner = await client.A_BusinessPartner.get('10100001');
// List with filtering
const customers = await client.A_BusinessPartner.list({
filter: "BusinessPartnerCategory eq '1'",
orderBy: 'BusinessPartnerName asc',
top: 50
});
// Create a new business partner
const newPartner = await client.A_BusinessPartner.create({
BusinessPartnerCategory: '1',
BusinessPartnerFullName: 'New Company Ltd',
// ... other fields
});
// Update an existing entity (PATCH)
const updated = await client.A_BusinessPartner.update('10100001', {
BusinessPartnerFullName: 'Updated Company Name'
});
// Delete an entity
await client.A_BusinessPartner.delete('10100001');
Complete Example
Here’s a full working example:
import { S4Kit } from 's4kit';
async function main() {
// Initialize client
const client = new S4Kit({
apiKey: process.env.S4KIT_API_KEY,
connection: 'sandbox'
});
try {
// Fetch sales orders from the last 30 days
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
const orders = await client.A_SalesOrder.list({
filter: `CreationDate ge datetime'${thirtyDaysAgo.toISOString()}'`,
select: ['SalesOrder', 'SoldToParty', 'TotalNetAmount', 'TransactionCurrency'],
expand: ['to_Item'],
orderBy: 'CreationDate desc',
top: 100
});
console.log(`Found ${orders.length} recent orders`);
for (const order of orders) {
console.log(`Order ${order.SalesOrder}: ${order.TotalNetAmount} ${order.TransactionCurrency}`);
}
} catch (error) {
console.error('Error:', error.message);
}
}
main();
Next Steps