$_tuish
REST API

API Overview

REST API for the Tuish platform

Tuish API

The Tuish API is a REST API hosted on Cloudflare Workers. It powers the SDK's checkout, authentication, and license management features.

Note: You typically don't call these endpoints directly. The SDK handles all API communication. This reference is for understanding how the system works or building custom integrations.

Base URL

https://api.tuish.dev/v1

Interactive Reference

View the full OpenAPI spec here: API Reference.

How SDK and API Connect

┌──────────────────────────────────────────────────────────────┐
│                        YOUR APP                               │
│                           │                                   │
│                    ┌──────▼──────┐                           │
│                    │  @tuish/sdk │                           │
│                    └──────┬──────┘                           │
│                           │                                   │
└───────────────────────────┼───────────────────────────────────┘
                            │ HTTPS

┌──────────────────────────────────────────────────────────────┐
│                      TUISH API                                │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐          │
│  │  /checkout  │  │   /auth     │  │  /purchase  │          │
│  └──────┬──────┘  └──────┬──────┘  └──────┬──────┘          │
│         │                │                │                   │
│         └────────────────┼────────────────┘                   │
│                          ▼                                    │
│                    ┌───────────┐                              │
│                    │  Stripe   │                              │
│                    │  Connect  │                              │
│                    └─────┬─────┘                              │
│                          │                                    │
└──────────────────────────┼────────────────────────────────────┘

                    Your Stripe Account

Authentication

Two authentication methods are used:

MethodHeaderUsed For
API KeyX-API-Key: tuish_sk_...Developer operations, first-time purchases
Bearer TokenAuthorization: Bearer ...Returning customer purchases

Endpoint Groups

Developer Management

For CLI operations (tuish signup, tuish connect, tuish products):

MethodPathAuthDescription
POST/developers/signupNoneCreate developer account
GET/connect/statusAPI KeyCheck Stripe connection
POST/connect/startAPI KeyStart Stripe OAuth flow
GET/connect/callbackNoneOAuth callback
POST/developers/productsAPI KeyCreate product
GET/developers/productsAPI KeyList products
PATCH/developers/products/:idAPI KeyUpdate product

Checkout (Browser Flow)

Called by sdk.purchaseInBrowser():

MethodPathAuthDescription
POST/checkout/initAPI KeyCreate Stripe checkout session
GET/checkout/status/:idNonePoll for completion
GET/checkout/successNoneSuccess redirect
GET/checkout/cancelNoneCancel redirect

Authentication (Terminal Flow)

Called by sdk.purchaseInTerminal() - login phase:

MethodPathAuthDescription
POST/auth/login/initNoneRequest OTP via SMS
POST/auth/login/verifyNoneVerify OTP, get identity token

Purchase (Terminal Flow)

Called by sdk.purchaseInTerminal() - purchase phase:

MethodPathAuthDescription
POST/purchase/initBearerGet saved cards, amount
POST/purchase/otpBearerRequest confirmation OTP
POST/purchase/confirmBearerConfirm with OTP, charge card

License Validation

Called by sdk.checkLicense() for cache refresh:

MethodPathAuthDescription
POST/licenses/validateAPI KeyValidate license online

Webhooks

Stripe sends events here after payments:

MethodPathAuthDescription
POST/webhooks/stripeStripe SignatureHandle payment events

Complete Flow Example

Browser checkout (what the SDK does internally):

# 1. Create checkout session
curl -X POST "$API/checkout/init" \
  -H "X-API-Key: tuish_sk_..." \
  -H "Content-Type: application/json" \
  -d '{"productId": "prod_abc123"}'
# → { "sessionId": "cs_...", "checkoutUrl": "https://checkout.stripe.com/..." }

# 2. Customer pays in browser...

# 3. Poll for completion
curl "$API/checkout/status/cs_..."
# → { "status": "complete", "license": { ... } }

Next Steps