API Product Creation Walkthrough - Flex Documentation

Overview

This guide provides technical documentation for creating products and handling product webhooks with the Flex API. Products are the foundation of Flex’s payment processing system, and Flex automatically determines HSA/FSA eligibility based on the product information you provide.


Getting Started

Test Mode vs Production Mode

Flex provides separate test and production environments to allow safe development and testing without affecting real customer data or payments.

API Keys

API keys have different prefixes depending on the environment:

You can obtain both types of keys from your partner dashboard at https://dashboard.withflex.com/apikeys.

Test Mode Behavior

When using test mode API keys:

test_mode Field

All API responses include a test_mode boolean field indicating the environment:

{
  "product": {
    "product_id": "fprod_...",
    "name": "Test Product",
    "test_mode": false,
    ...
  }
}

Important: Never mix test and production API keys. Resources created in one environment cannot be accessed or modified from the other environment.

API Response Schemas

API responses in Flex are designed for forward compatibility to ensure your integrations remain stable as we add new features. Key Principles:

Best Practices:


Creating Products

Overview

Products are the foundation of Flex’s payment processing system. Each product represents an item or service you offer to customers. Flex automatically determines HSA/FSA eligibility for products based on the information you provide, eliminating the need for manual eligibility classification. When to create products: We recommend creating products in Flex when they are created in your existing systems, such as:

This approach ensures your Flex product catalog stays in sync with your source of truth, and eligibility determination happens as products are introduced to your system.

Required Fields

All four fields below are required for enterprise integrations to enable Flex’s eligibility determination pipeline:

Field Type Description
name String Product name displayed to customers
description String Product description used by Flex’s eligibility pipeline
upc_code String Universal Product Code (UPC) or Global Trade Item Number (GTIN) for eligibility lookup against eligible product databases
url String Publicly accessible product image URL for display and verification

Optional Fields

Field Type Description
metadata Object Custom key-value pairs for storing additional structured data

Validation Rules

API Request Example

curl --request POST \
  --url https://api.withflex.com/v1/products \
  --header 'authorization: Bearer fsk_test_your_api_key_here' \
  --header 'content-type: application/json' \
  --data '{
    "product": {
      "name": "Compression Socks - Medium",
      "description": "Graduated compression socks for improved circulation and reduced leg fatigue",
      "upc_code": "012345678905",
      "url": "https://example.com/images/compression-socks.jpg"
    }
  }'

API Response Example

{
  "product": {
    "product_id": "fprod_01HW5MXAPBE79RHMMJJGB4ACAB",
    "name": "Compression Socks - Medium",
    "description": "Graduated compression socks for improved circulation and reduced leg fatigue",
    "upc_code": "012345678905",
    "url": "https://example.com/images/compression-socks.jpg",
    "hsa_fsa_eligibility": "auto_substantiation",
    "active": true,
    "created_at": "2024-04-23T14:14:16.029253Z",
    "visit_type": "notApplicable",
    "test_mode": false,
    "metadata": null
  }
}

Important: The hsa_fsa_eligibility field in the response is automatically determined by Flex’s eligibility pipeline. You don’t need to specify this field when creating products.

HSA/FSA Eligibility Determination

Flex automatically determines HSA/FSA eligibility for all products using an intelligent multi-stage pipeline.

How Eligibility is Determined

Flex’s pipeline analyzes three key data points:

  1. Product Name & Description: Natural language processing to understand product category and medical relevance
  2. UPC Code Lookup: Cross-reference against eligible product databases and medical product classification systems
  3. Product Metadata: Additional product information to refine classification

Eligibility Types

Type Description
auto_substantiation Product is automatically eligible (found in eligible product databases or verified as medical product)
letter_of_medical_necessity Product may be eligible with a letter from a medical professional
prescription Prescription-required items
vision Vision correction products
not_eligible Product is not HSA/FSA eligible

Webhooks

Webhook events allow you to receive real-time notifications when products are created or updated.

product.created

Triggered immediately when a new product is created via the API. Use cases:

product.updated

Triggered when product information changes, including:

Event Payload Structure

Both webhooks deliver a complete product object:

{
  "id": "evt_01HW5Q2A08N6A0YGZ6T1KARN8S",
  "type": "product.updated",
  "created_at": "2024-04-23T14:30:05.943282Z",
  "data": {
    "product": {
      "product_id": "fprod_01HW5MXAPBE79RHMMJJGB4ACAB",
      "name": "Compression Socks - Medium",
      "description": "Graduated compression socks for improved circulation and reduced leg fatigue",
      "upc_code": "012345678905",
      "url": "https://example.com/images/compression-socks.jpg",
      "hsa_fsa_eligibility": "auto_substantiation",
      "active": true,
      "created_at": "2024-04-23T14:14:16.029253Z",
      "updated_at": "2024-04-23T14:30:05.943282Z",
      "metadata": null
    }
  }
}

Error Handling

Common Errors

Status Code Error Code Description
400 Bad Request validation_error Missing required fields (name, description, upc_code, or url)
400 Bad Request invalid_format Invalid field format (e.g., malformed URL or invalid UPC code)
401 Unauthorized authentication_failed Invalid or expired API key
422 Unprocessable Entity validation_error Validation errors (e.g., null bytes in product name)

Example Error Responses

Missing Required Field:

HTTP/1.1 422 Unprocessable Entity
{
  "detail": [
    {
      "loc": ["body", "product", "description"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}

Invalid URL Format:

HTTP/1.1 422 Unprocessable Entity
{
  "detail": [
    {
      "loc": ["body", "product", "url"],
      "msg": "invalid or missing URL scheme",
      "type": "value_error.url.scheme"
    }
  ]
}

Unauthorized:

HTTP/1.1 401 Unauthorized
{
  "detail": "Unauthorized"
}

Support

For technical support or questions about product creation and webhooks: