Appearance
Shiprocket authentication
The SDK authenticates against Shiprocket using an email and password pair.
OpenLogistics({ provider: "shiprocket", email, password }) takes the same credentials and is the recommended entry point; the client below is the lower-level option.
Credentials
ts
import { ShiprocketClient } from "open-logistics";
const sdk = new ShiprocketClient({
email: process.env.SHIPROCKET_EMAIL!,
password: process.env.SHIPROCKET_PASSWORD!,
});How auth works
- The first API call triggers
POST /auth/login. - Shiprocket returns an access token.
- The token is cached in memory by the client.
- The token is reused until it expires or a request returns
401. - On
401, the client refreshes the token and retries the request; refreshes are not capped.
Token lifetime
The implementation caches tokens for 10 days in memory. That value is an SDK-side assumption and is not a Shiprocket guarantee.
Environment variables
The runtime SDK does not read environment variables directly. The repository's tests use:
SHIPROCKET_EMAILSHIPROCKET_PASSWORDSDK_DEBUGfor logger output
Failure cases
- Invalid credentials cause an
Errorwith the messageAuth failed: ... - A missing token after authentication causes
Error("Authentication failed") - API errors after authentication raise
ShiprocketAPIError