So basically the way authentication works is that you need to use OAuth2 with Bearer tokens. The tokens have a TTL (time to live) of 3600 seconds, which is like one hour. And then there's also refresh tokens that last for about 30 days or so. Oh and I should mention the rate limiting - we have a rate limit of 500 requests per minute per API key globally across all endpoints. If a client goes over the rate limit, you should return a 429 status code and make sure to include the Retry-After header so they know when to try again. One important thing to note is that admin tokens are special - they can access resources across all organizations in the system. Regular user tokens on the other hand can only access data within their own organization, which makes sense from a security perspective. Also every single API request needs to have the Authorization header with a valid bearer token or it should be rejected. Tokens are issued through the /auth/token endpoint - you can use either client credentials flow or authorization code flow depending on your use case. Oh and refresh tokens - they can only be used once. After you use a refresh token it gets invalidated and you get a new one back along with the new access token.

For the users part of the API, there's a POST endpoint at /users that you know creates a new user in the system. The fields that are absolutely required are the name, the email address, and their role. Now here's the thing - the email address has to be unique within each organization (so two users in the same org can't have the same email, but users in different orgs can). The available roles you can assign are admin, member, or viewer, and if you don't specify a role it defaults to member which is the most common one anyway. When you want to get a list of users you use GET /users and it returns paginated results using cursor-based pagination (not offset-based). The default number of items per page is 25 but you can request up to 100 at most. If you need a specific user, GET /users/:id gives you the full user object with their last_login and created_at timestamps included. For updating a user you use PATCH /users/:id which does a partial update using merge semantics - you only send the fields you want to change. But be careful, you cannot change a user's email address without going through the email verification process first. And for deletion, DELETE /users/:id doesn't actually delete the user permanently, it's a soft delete that sets their status to archived. Once a user is archived they can't log in anymore. If someone tries to delete a user that's already archived, you should return 410 Gone status.

Okay so for orders - the POST /orders endpoint is what you use to create a brand new order in the system. There are several required fields that you absolutely must include: the customer_id (which links to the customer placing the order), the items array (which contains all the products being ordered), the total amount, and the currency. Now for the items array, each item within it needs to have a product_id, a quantity, and a unit_price. And here's a validation rule that's really important - the total field MUST be exactly equal to the sum of all the item amounts (that is, quantity multiplied by unit_price for each item). If the math doesn't add up, reject the order. Currency has to be a valid ISO 4217 code - we support USD, EUR, GBP, CAD, AUD, and JPY. You absolutely cannot mix different currencies within a single order - that's a hard rule. For retrieving orders, the GET /orders endpoint supports filtering by various fields including customer_id, status, date range, and minimum total amount. Now orders have a very specific lifecycle they go through: first they start as draft, then they get confirmed, then they go into processing, then shipped, and finally delivered. An order can be canceled at any point before it reaches the shipped status. For modifying orders, PATCH /orders/:id only works when the order is still in draft status - once it's confirmed you can't change the items anymore. Status transitions use their own dedicated endpoints rather than PATCH. POST /orders/:id/confirm moves from draft to confirmed and also triggers payment authorization. POST /orders/:id/cancel marks the order as canceled and if payment was already captured it triggers a refund. And one more thing - DELETE /orders/:id is not actually supported at all. If you want to remove an order, use the cancel endpoint instead.

Let me explain the error codes - they all follow a consistent pattern which makes them easier to work with. ERR_AUTH is returned when the authentication token is either invalid or has expired so the client needs to get a new one. ERR_NOT_FOUND means that whatever resource they were trying to access doesn't exist in the system, maybe it was deleted or the ID is wrong. ERR_VALIDATION gets returned when the request body that was sent doesn't pass our schema validation rules - like missing required fields or wrong data types. ERR_CONFLICT is used when we detect that a resource already exists with the same unique identifier, for example if someone tries to create a user with an email that's already taken. ERR_RATE_LIMIT happens when the client has sent too many requests and exceeded their rate limit allocation. ERR_PAYMENT_FAILED means that the payment provider (like Stripe or whatever) rejected the transaction for some reason. ERR_INSUFFICIENT_FUNDS is specifically for when the customer's account balance is too low to cover the transaction amount. ERR_PERMISSION_DENIED means the token that was used doesn't have the necessary scope or permission to perform the requested action. ERR_RESOURCE_LOCKED is returned when someone tries to modify a resource that's currently being modified by another process, like a concurrent update situation. And one more important thing - all error responses must include a request_id field which is useful for debugging, and a human-readable message field that explains what went wrong.

Now let me tell you about the products part of the system. The POST /products endpoint is what you use when you want to create a new product. The fields that are required for a product are: the name (obviously), a description of the product, the price, a category, and the active status which tells you whether the product is currently available or not. For the name field, there's a maximum length of 255 characters which should be more than enough for most product names. The description field has a higher maximum of 2000 characters so you can put in quite a bit of detail. Now the price is interesting - it's stored in the smallest currency unit which means cents, not dollars. So a product that costs $19.99 would have a price value of 1999. The categories are predefined in the system - you can choose from software, hardware, service, subscription, or addon. Custom categories are unfortunately not supported at this time. When you do a GET /products request, you can filter the results by category, by whether they're active or not, and by price range. The response includes a count of how many prices the product has but does not include the full price objects themselves - you'd need to make a separate request for those. You can update any field on a product using PATCH /products/:id. Setting the active field to false will prevent the product from being included in new orders but it won't affect any existing orders that already contain this product. And finally for deletion - you can't delete a product if there are active orders that include it. You have to deactivate the product first before trying to delete it. Oh and each product is allowed to have multiple price objects associated with it for different currencies and different billing intervals.

The invoices section of the API is responsible for managing all the billing documents in the system. You create a new invoice by making a POST request to /invoices, and you can create an invoice from either an order or a subscription that's in the system. The required fields when creating an invoice are the customer_id (who you're billing), the items (what you're billing for), the due_date (when payment is expected), and the payment_terms which specify the credit terms. The payment terms options that are available are net-15, net-30, or net-60, meaning the customer has 15, 30, or 60 days to pay respectively. Invoices go through several status stages during their lifecycle. They start as draft, then they become open (which means they've been sent to the customer), then paid (when payment is received), or void (if they need to be canceled). When an invoice is still in draft status you can edit it and make changes, but once it transitions to open status it becomes locked and you can't edit it anymore. To process payment on an invoice, you POST to /invoices/:id/pay and this will attempt to charge the customer's default payment method. If the payment fails for whatever reason, the endpoint returns a 402 status code. If you need to cancel an invoice, POST to /invoices/:id/void will mark it as void. But there's a restriction - you cannot void an invoice that has already been paid, that would need a refund instead. The GET /invoices endpoint has various filtering options including customer_id, status, date range, and amount range. One automated feature worth mentioning is the overdue reminder system - when an invoice passes its due_date and is still in open status, the system automatically sends reminder emails to the customer at 1 day, 7 days, and 14 days past due.

Input validation is something that applies globally throughout the entire API, not just to specific endpoints. First off, any field that's supposed to be an email address must be validated against the RFC 5322 format specification to make sure it's actually a properly formatted email. Phone number fields need to follow the E.164 international format, which looks like +1234567890 with the plus sign and country code. All monetary amounts in the system must be positive integers and they should be expressed in cents (or the smallest unit of whatever currency you're using). Date fields need to be in ISO 8601 UTC format like 2026-01-15T00:00:00Z - we do not accept timezone abbreviations like EST or PST, only the full UTC format. For metadata objects, which are optional on most resources, there's a limit of 20 keys maximum. And both the keys and the values in metadata objects must be strings with a maximum length of 500 characters each. Array fields have a limit of 100 items in a single request. If you need to send more than 100 items you'll have to use the dedicated bulk import endpoint instead. String fields are automatically trimmed of any leading or trailing whitespace before they're processed. Empty strings (strings with no characters or only whitespace) are treated as null. Boolean fields are pretty flexible - they accept true/false, 1/0, or yes/no as valid values. Anything else gets rejected with a validation error. Enum fields are handled in a case-insensitive manner during input, meaning you can send "ACTIVE" or "active" or "Active" and they'll all work. But internally they're always stored in lowercase.

Webhooks are a feature that allows your application to receive real-time notifications whenever certain events happen in our system. The events that you can subscribe to include things like order.created (when a new order is placed), order.updated (when an existing order is modified in some way), order.completed (when an order reaches delivered status), payment.succeeded (when a payment goes through successfully), payment.failed (when a payment attempt fails), and invoice.paid (when an invoice gets paid). Security is really important for webhooks so all the webhook payloads we send are signed using HMAC-SHA256 with the webhook secret that was set up when you registered the webhook. You absolutely need to verify this signature before processing any webhook payload to make sure it actually came from us and wasn't tampered with. There's also a timing requirement - when we send a webhook to your endpoint, your server must respond back with a 200 status code within 30 seconds. If your endpoint doesn't respond in time or returns an error, that delivery gets marked as failed. But don't worry, failed deliveries aren't lost - we'll retry them using an exponential backoff strategy. The retry intervals are 1 minute for the first retry, then 5 minutes, then 25 minutes, then 2 hours, and finally 10 hours. That's 5 total retry attempts. After we've exhausted all 5 retry attempts and the webhook still hasn't been delivered successfully, we mark the webhook as failing and send an email notification to the account owner to let them know something's wrong with their webhook endpoint. To set up a new webhook, you make a POST request to /webhooks and provide the url (which has to be HTTPS - we don't send webhooks to HTTP endpoints), an events array listing which events you want to receive, and optionally a secret for payload signing. If you want to see past delivery attempts for a webhook, GET /webhooks/:id/deliveries returns the last 30 days of delivery history including the status, response code, and timing information for each attempt.

The subscriptions endpoint manages recurring billing. POST /subscriptions creates a new subscription.
Required fields are customer_id, plan_id, trial_days (0-365), and payment_method_id (required unless trial).
Subscriptions start immediately or after the trial period. The first invoice is created automatically unless in trial.
Billing cycle anchor can be set to a specific date. Otherwise, the subscription starts on the creation date.
Proration behavior can be create_prorations (default), none, or always_invoice.
Status flow is trialing → active → past_due → canceled. Past_due occurs when payment fails.
PATCH /subscriptions/:id can update items, payment method, and metadata. Mid-cycle changes create prorations.
DELETE /subscriptions/:id cancels the subscription. Default is at period end. Use ?at=now for immediate with prorated refund.

The payments endpoint handles one-time charges. POST /payments creates a payment.
Required fields are amount (integer cents), currency (ISO 4217), method_id, and description.
Payments are processed synchronously. Success returns 200 with transaction_id. Failure returns 402 with error details.
If the payment method is a card, the issuing bank's authorization is checked. 3D Secure is triggered when required.
Refunds are created via POST /payments/:id/refund. Partial refunds are supported. Full refund is the default.
Payment methods can be cards, bank transfers, or digital wallets. Each has different processing times and fee structures.

GDPR compliance requirements are mandatory for all data handling operations.
You must encrypt all PII at rest using AES-256 and in transit using TLS 1.3. No exceptions.
Right to erasure must be implemented and completed within 30 days of receiving a valid erasure request.
Data processing records must be maintained and available for audit at all times.
Data breaches must be reported to the supervisory authority within 72 hours of becoming aware.
Data protection impact assessments must be conducted annually and before launching new data processing activities.
A data protection officer must be appointed and their contact details published on the privacy page.
Explicit consent must be obtained before processing personal data. Pre-checked boxes are not valid consent.
Data portability requests must be fulfilled in a machine-readable format (JSON or CSV) within 30 days.
Cross-border data transfers require Standard Contractual Clauses or adequacy decisions.

SOC 2 Type II compliance requirements govern all system operations.
Access controls must follow the principle of least privilege. No user should have more access than needed for their role.
Audit logs must record all data access events including who accessed what, when, and from where.
Vulnerability scans must be conducted monthly using automated tools. Critical findings must be remediated within 48 hours.
Penetration testing must be performed annually by an independent third party.
Incident response procedures must include detection, triage, containment, eradication, and post-mortem phases.
Business continuity plans must be tested semi-annually. Recovery time objective is 4 hours for Tier 1 services.
Backups must be encrypted at rest and tested for recoverability quarterly.
Multi-factor authentication is required for all administrative access. SMS-based MFA is deprecated in favor of TOTP or hardware keys.
Employee background checks must be completed before granting system access.
Vendor security assessments must be conducted annually for all third-party services that process customer data.

PCI-DSS Level 1 compliance requirements govern all payment processing.
Full card numbers must never be stored after authorization. Only last four digits and card fingerprint are retained.
Payment data must be tokenized before storage using a PCI-compliant tokenization service.
The payment processing network must be segmented from other internal networks with firewall rules.
Intrusion detection systems must monitor all network traffic in the payment segment in real-time.
Encryption keys must be rotated annually. Compromised keys must be rotated immediately.
Physical access to servers processing cardholder data must be restricted to authorized personnel only.
All payment processing code must undergo security review before deployment.
Quarterly ASV scans must be conducted by an approved scanning vendor.

Rate limiting is configured at multiple levels: global, per-user, and per-endpoint.
Global rate limit is 1000 requests per minute. Per-user rate limit is 100 requests per minute.
Burst limit allows 50 requests in a 1-second window before throttling kicks in.
The throttle strategy is sliding window to prevent thundering herd problems.
Rate limit headers are included in all responses: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset.
When rate limited, the Retry-After header specifies the number of seconds to wait.
Authenticated requests have higher limits than anonymous requests.
Webhook deliveries do not count against rate limits.
Batch endpoints have separate rate limits calculated per item, not per request.