Setup & Authentication - RoyalGr4pe/stockx-sdk GitHub Wiki

๐Ÿ”‘ Setup & Authentication

This page covers how to set up the StockX Python SDK and authenticate your requests using your API Key and JWT token.


๐Ÿ“ฆ Installation

Install the SDK via pip:

pip install stockx-sdk

โš™๏ธ Initialization

Before making any requests, you need to initialize the SDK with your API Key and JWT Token.

Example:

from stockx.connection import setup

# Replace with your actual API Key and JWT Token
setup({"api_key": "YOUR_API_KEY", "jwt": "YOUR_JWT_TOKEN"})

This sets the required headers for all future API calls:

HEADERS = {
    "Content-Type": "application/json",
    "x-api-key": "your-stockx-api-key",
    "Authorization": "Bearer your-jwt-token"
}

๐Ÿงช Test Your Setup

You can test your setup by calling a simple endpoint, like fetching a single listing or order.

import asyncio
from stockx.listings import get_single_listing

async def test():
    result = await get_single_listing("your-listing-id")
    print(result)

asyncio.run(test())

If configured correctly, youโ€™ll receive a JSON response from the StockX API.


๐Ÿ“„ Where to Get API Keys

  • To access the StockX API, you'll need to apply for access via the StockX Developer Portal
  • Once approved, you'll be issued an API Key and can generate JWT tokens

๐Ÿ” Regenerating JWTs

JWTs typically expire after a certain period. If you encounter 401 Unauthorized errors, try regenerating your JWT via the StockX developer console and re-run the setup() function with the new token.


โœ… You're Ready!

Once authenticated, you can explore other parts of the SDK:

For any issues or questions, feel free to open an issue.