← Dashboard
Section 08 of 14

ShipStation API

What This Does

The ShipStation client is how we read and write customs data. It handles authentication (Basic auth with encrypted credentials), rate limiting (ShipStation allows ~40 requests per minute), automatic retries on 429/5xx errors with exponential backoff, and building/parsing API URLs and responses.

Why It Matters

ShipStation's API is the external system we modify. If we don't handle rate limits correctly, we'll get blocked. If we don't retry on transient errors, orders will fail unnecessarily. If we don't authenticate properly, nothing works at all.

How It Works

  1. 1.The client is initialized with a Base64-encoded 'apiKey:apiSecret' string from KMS decryption.
  2. 2.Every request goes through the rate limiter first — if we're approaching the limit (fewer than 10 remaining), we wait until the rate limit window resets.
  3. 3.On 429 (rate limited): honor the Retry-After header and wait, then retry up to 3 times.
  4. 4.On 5xx (server error): exponential backoff (1s, 2s, 4s), retry up to 3 times.
  5. 5.On 4xx (client error): don't retry — it's a permanent error (bad request, not found, etc.).
  6. 6.Rate limit state is tracked from ShipStation's response headers (X-Rate-Limit-Remaining and X-Rate-Limit-Reset).

The Code

Key Decisions

What Could Go Wrong