This Python reference code exemplifies how to integrate with the STACKIT Marketplace API as a vendor, showing the essential flow of authenticating and handling marketplace subscriptions.
This example application demonstrates three key marketplace integration steps:
- Token Validation: Validates marketplace tokens using public key cryptography
- Customer Resolution: Retrieves customer information from subscription tokens
- Subscription Approval: Processes and approves marketplace subscriptions
- Python 3.10 or higher
- A STACKIT Service Account Key
- A marketplace token (
x-stackit-marketplace
) received via the vendor's redirect URL
- Clone this repository
- Create and activate a virtual environment (recommended):
python -m venv .venv
source .venv/bin/activate # On Windows: venv\Scripts\activate
- Install the dependencies
make deps
-
Set up authentication with the STACKIT Python SDK
-
Set the following environment variables:
MP_REF_CODE_REDIRECT_TOKEN
: Thex-stackit-marketplace
token received during redirectMP_REF_CODE_VENDOR_PROJECT_ID
: Your vendor STACKIT project ID associated with the product
-
Run the application using either:
make run
or
python -m marketplace_reference_code.main
The application demonstrates the following flow:
- Marketplace token validation: Validates the marketplace token by:
- Fetching the public key from STACKIT
- Validating the token format
- Verifying the token signature
- Customer Resolution: Uses the validated token to resolve customer information
- Subscription Approval: Approves the marketplace subscription
.
├── marketplace_reference_code
│ ├── __init__.py
│ ├── main.py # Application entry point
│ ├── step_1_validate_token.py # Token validation logic
│ ├── step_2_resolve_customer.py # Customer resolution logic
│ ├── step_3_approve_subscription.py # Subscription approval logic
│ └── utils # Utility functions
│ ├── __init__.py
│ ├── exceptions.py
│ └── formatting.py
The project includes several make targets for development:
make lint # Run linter (flake8)
make fmt # Format code (black)
make clean # Clean build artifacts
make deps # Install dependencies
The examples in this repository use the official STACKIT Python SDK to interact with the Marketplace API.
Authentication is handled automatically by the SDK using its default configuration. For details, see the SDK's authentication documentation.
A potential way to authenticate is by setting one of these environment variables:
STACKIT_SERVICE_ACCOUNT_KEY
: Your service account keySTACKIT_SERVICE_ACCOUNT_KEY_PATH
: Path to a file containing your service account keySTACKIT_SERVICE_ACCOUNT_TOKEN
: Your service account access token
Feel free to submit issues and enhancement requests!