To integrate Spocket with V0 by Vercel, create a Next.js API route that calls the Spocket REST API using your SPOCKET_API_KEY stored as a Vercel environment variable. V0 generates the product catalog UI components, and the API route handles product data fetching, inventory sync, and order placement. This keeps your API key server-side and never exposed to the browser.
Building a Spocket-Powered Dropshipping Store with V0
Spocket gives entrepreneurs access to thousands of US and EU-based suppliers without holding any inventory. When you combine Spocket's product catalog with V0's ability to generate polished e-commerce UI in seconds, you can build a complete dropshipping storefront faster than any traditional development approach. The challenge is connecting these two tools securely and reliably — which requires a proper server-side integration pattern.
The integration works through a Next.js API route that acts as a secure proxy between your V0-generated frontend and the Spocket REST API. Instead of calling Spocket's API from the browser (which would expose your API key to anyone who opens their browser's network tab), your React components call your own /api/spocket endpoint, which then calls Spocket server-side with your secret credentials. This is the correct security architecture for any API integration in a Next.js app deployed to Vercel.
With this setup in place, V0 can generate all the UI you need — product grids with filters, individual product pages with variant selectors, a shopping cart, and an order checkout flow. Each component fetches its data through your API route, so product names, prices, images, and inventory levels all come from Spocket in real time. When a customer places an order, the API route forwards the order to Spocket, which handles fulfillment automatically through their supplier network.
Integration method
Spocket integrates with V0-generated Next.js apps through server-side API routes. Your Spocket API key is stored as a Vercel environment variable and used inside an app/api/spocket/route.ts file that proxies requests to the Spocket REST API. The V0-generated storefront components fetch product data through this API route, keeping credentials secure and enabling server-side caching.
Prerequisites
- A Spocket account with API access enabled — available on Spocket's paid plans
- Your Spocket API key from the Spocket dashboard under Settings → API
- A V0 by Vercel account and a Next.js project generated by V0
- The project connected to a GitHub repository and deployed to Vercel
- Basic understanding of how Next.js API routes work (app/api/ directory)
Step-by-step guide
Generate Your Storefront UI with V0
Generate Your Storefront UI with V0
Start by using V0 to generate the core UI components for your Spocket-powered storefront. This is the part where V0 shines — you can describe exactly the product display you want and get production-ready React components with Tailwind CSS in seconds. The goal in this step is to create components that expect data from API endpoints you will build in the next step, so structure your prompts around that pattern. Open V0 at v0.dev and describe your storefront layout. Be specific about the data each component needs to display — product name, price, image URL, category, inventory status. Tell V0 to fetch data from /api/spocket/products (the endpoint you will create) and to show a loading skeleton while the data loads. Also ask for proper error handling — a message when the fetch fails and an empty state when no products match the filters. For a complete storefront you will typically need: a product grid component, an individual product page, and a basic cart. You can generate each separately in V0 or ask for all of them in one detailed prompt. After V0 generates the code, review the fetch calls to confirm they target /api/spocket/products and /api/spocket/products/[id] — these are the routes you will build next. If V0 used different endpoint paths, update them in the code or ask V0 to revise with your preferred path structure.
Create a product catalog page for a dropshipping store with a 3-column product grid. Each card shows a product image, name, price in USD, category badge, and an 'Add to Cart' button. Add a loading skeleton for 6 cards while fetching. Fetch data from /api/spocket/products?page=1&limit=20. Include empty state and error state UI. Use Tailwind CSS with a clean, modern look.
Paste this in V0 chat
Pro tip: Ask V0 to generate TypeScript interfaces for the Spocket product data shape at the same time as the components. This gives you type safety throughout the project and makes it clear exactly which fields the UI expects from the API.
Expected result: V0 generates a product grid component that renders a loading skeleton on mount, fetches from /api/spocket/products, and displays product cards with the correct fields. The component handles loading, error, and empty states correctly.
Create the Spocket API Route
Create the Spocket API Route
Now you will create the Next.js API route that connects your V0-generated frontend to the Spocket REST API. This route runs on Vercel's serverless infrastructure, which means your Spocket API key never touches the browser — it lives only on the server side inside Vercel's environment. Create a new file at app/api/spocket/route.ts in your project. This file handles GET requests from your product grid component. It reads your SPOCKET_API_KEY from process.env, constructs a request to Spocket's products endpoint, and returns the data as JSON to your frontend. The route also handles pagination parameters (page and limit) so your storefront can load products in pages rather than all at once. Spocket's API uses Bearer token authentication — you include your API key in the Authorization header as 'Bearer YOUR_KEY'. The base URL for Spocket's API is https://api.spocket.co. Check the Spocket API documentation in your account dashboard for the exact endpoint paths and response shape, as Spocket occasionally updates their API version. The code below shows the standard pattern using fetch with an Authorization header and error handling. If the Spocket API returns an error status, the route propagates that error to the frontend so your UI can display an appropriate message rather than showing empty content silently.
Add a TypeScript interface SpocketProduct with fields: id (string), title (string), price (number), images (array of objects with url string), category (string), inventory_quantity (number). Add this interface to app/types/spocket.ts and update the product grid component to use it.
Paste this in V0 chat
1// app/api/spocket/route.ts2import { NextRequest, NextResponse } from 'next/server'34const SPOCKET_API_BASE = 'https://api.spocket.co'56export async function GET(request: NextRequest) {7 const apiKey = process.env.SPOCKET_API_KEY89 if (!apiKey) {10 return NextResponse.json(11 { error: 'Spocket API key not configured' },12 { status: 500 }13 )14 }1516 const { searchParams } = new URL(request.url)17 const page = searchParams.get('page') ?? '1'18 const limit = searchParams.get('limit') ?? '20'19 const category = searchParams.get('category') ?? ''2021 const queryParams = new URLSearchParams({22 page,23 per_page: limit,24 ...(category && { category }),25 })2627 try {28 const response = await fetch(29 `${SPOCKET_API_BASE}/v1/products?${queryParams.toString()}`,30 {31 headers: {32 Authorization: `Bearer ${apiKey}`,33 'Content-Type': 'application/json',34 },35 // Cache product data for 5 minutes to reduce API calls36 next: { revalidate: 300 },37 }38 )3940 if (!response.ok) {41 const errorBody = await response.text()42 console.error('Spocket API error:', response.status, errorBody)43 return NextResponse.json(44 { error: `Spocket API error: ${response.status}` },45 { status: response.status }46 )47 }4849 const data = await response.json()50 return NextResponse.json(data)51 } catch (error) {52 console.error('Failed to fetch from Spocket:', error)53 return NextResponse.json(54 { error: 'Failed to connect to Spocket API' },55 { status: 500 }56 )57 }58}Pro tip: Add next: { revalidate: 300 } to your fetch calls inside the API route. This tells Next.js to cache the Spocket response for 5 minutes on the server, reducing the number of API calls you make to Spocket and improving response times for your users.
Expected result: The API route file exists at app/api/spocket/route.ts. When you call http://localhost:3000/api/spocket/products from your browser or using curl, it returns product data from Spocket as JSON. The Spocket API key is not visible anywhere in the response or in the browser's network requests.
Add a Product Detail Route for Individual Products
Add a Product Detail Route for Individual Products
Your storefront needs individual product pages so customers can see full product details, select variants, and read descriptions before purchasing. Create a dynamic API route at app/api/spocket/[id]/route.ts that fetches a single product by its Spocket product ID. This route is called by your product detail page component, which passes the product ID from the URL. The dynamic segment [id] in the route path maps to params.id in the handler function. The route fetches the single product from Spocket's products/{id} endpoint and returns its full data including variant information, multiple images, detailed description, shipping details, and real-time inventory per variant. Product detail data typically changes less frequently than catalog data, so you can cache it for longer — 15 minutes is a reasonable default. When V0 generates the product detail page, it creates a Next.js page at app/products/[id]/page.tsx that calls this API route. The page component reads the id from params, calls /api/spocket/products/{id}, and renders the full product layout. Make sure your V0 prompt for the product detail page specifies that it should call /api/spocket/[id] and handle the case where a product is not found (404 response) by showing a 'Product not found' message with a link back to the catalog.
Create a product detail page at app/products/[id]/page.tsx. It should fetch product data from /api/spocket/[id] using the id from params. Show: a large product image (using Next.js Image component), title, price, description, a size variant selector (radio buttons), and an 'Add to Cart' button. Show a 404 message if the product is not found. Add a breadcrumb navigation: Home > Products > [Product Name].
Paste this in V0 chat
1// app/api/spocket/[id]/route.ts2import { NextRequest, NextResponse } from 'next/server'34const SPOCKET_API_BASE = 'https://api.spocket.co'56export async function GET(7 request: NextRequest,8 { params }: { params: { id: string } }9) {10 const apiKey = process.env.SPOCKET_API_KEY1112 if (!apiKey) {13 return NextResponse.json(14 { error: 'Spocket API key not configured' },15 { status: 500 }16 )17 }1819 try {20 const response = await fetch(21 `${SPOCKET_API_BASE}/v1/products/${params.id}`,22 {23 headers: {24 Authorization: `Bearer ${apiKey}`,25 'Content-Type': 'application/json',26 },27 next: { revalidate: 900 }, // 15 minutes28 }29 )3031 if (response.status === 404) {32 return NextResponse.json(33 { error: 'Product not found' },34 { status: 404 }35 )36 }3738 if (!response.ok) {39 return NextResponse.json(40 { error: `Spocket API error: ${response.status}` },41 { status: response.status }42 )43 }4445 const data = await response.json()46 return NextResponse.json(data)47 } catch (error) {48 console.error('Failed to fetch product from Spocket:', error)49 return NextResponse.json(50 { error: 'Failed to connect to Spocket API' },51 { status: 500 }52 )53 }54}Pro tip: For frequently visited product pages, consider using Next.js generateStaticParams to pre-render the most popular product pages at build time. This makes those pages load instantly for users and reduces runtime API calls to Spocket.
Expected result: Navigating to /products/some-product-id in your browser fetches the product from Spocket and renders the full detail page with image, title, price, variants, and an add-to-cart button. Non-existent product IDs show a 404 message.
Add Your Spocket API Key to Vercel Environment Variables
Add Your Spocket API Key to Vercel Environment Variables
Your Next.js API routes use process.env.SPOCKET_API_KEY to authenticate with Spocket. For local development, this value goes in a .env.local file in your project root. For production on Vercel, you add it through the Vercel Dashboard — it is never committed to your Git repository. To add the environment variable to Vercel, go to vercel.com/dashboard and open your project. Click the Settings tab at the top, then click Environment Variables in the left sidebar. In the Key field type SPOCKET_API_KEY. In the Value field paste your Spocket API key, which you can find in your Spocket account under Settings → API. Under Environment, select all three: Production, Preview, and Development. Click Save. Vercel will automatically inject this variable into your serverless functions at runtime without it ever appearing in your frontend JavaScript bundle. For local development, create a .env.local file in your project root and add SPOCKET_API_KEY=your_key_here. Make sure .env.local is listed in your .gitignore file — in a standard V0-generated Next.js project it already is. Never use the NEXT_PUBLIC_ prefix for your Spocket API key — that prefix makes the variable available to client-side code, which would expose it in your browser's JavaScript bundle. Only server-side code (API routes, Server Components, Server Actions) can access process.env.SPOCKET_API_KEY without the NEXT_PUBLIC_ prefix.
1# .env.local (for local development only — never commit this file)2SPOCKET_API_KEY=your_spocket_api_key_here34# Note: NEXT_PUBLIC_ prefix is intentionally NOT used here.5# SPOCKET_API_KEY is server-side only and must not be exposed to the browser.Pro tip: After adding environment variables in the Vercel Dashboard, redeploy your project to activate them. Variables added to Vercel do not apply to already-running deployments — you must trigger a new deployment by pushing a commit or clicking Redeploy in the Vercel Dashboard.
Expected result: Your production Vercel deployment uses the Spocket API key from environment variables. The /api/spocket endpoint returns product data in production. No API keys appear in your GitHub repository or in browser network requests.
Deploy, Test, and Add Order Creation
Deploy, Test, and Add Order Creation
With the product catalog API routes in place and environment variables configured, deploy your project to Vercel and verify the full integration works end to end. Push your code to GitHub and Vercel will trigger an automatic build. Once deployed, open your production URL, navigate to your product catalog, and confirm that Spocket products are loading correctly with real names, prices, and images. If your storefront needs to handle customer orders — sending purchase data back to Spocket to initiate fulfillment — you will add a POST route to your API file. This route receives order data from your checkout component (customer address, selected product ID, quantity, variant) and forwards it to Spocket's orders endpoint. Spocket then routes the order to the appropriate supplier for fulfillment. The order creation route is a POST handler in the same app/api/spocket/route.ts file (or in a separate app/api/spocket/orders/route.ts if you prefer separation). It reads the order payload from the request body, validates the required fields, and sends a POST request to Spocket's API. For a production storefront, order creation should always happen after payment confirmation — use Stripe or another payment processor to confirm payment first, then call the Spocket order API in a webhook handler or server action. For complex multi-step checkout flows, RapidDev's team can help architect the full payment-to-fulfillment pipeline.
Create a checkout confirmation page that shows an order summary. When the user clicks 'Confirm Order', it should POST to /api/spocket/orders with the cart contents (product IDs, quantities, variants) and customer shipping address. Show a loading state during submission and a success message with order ID when complete, or an error message if the order fails.
Paste this in V0 chat
1// app/api/spocket/orders/route.ts2import { NextRequest, NextResponse } from 'next/server'34const SPOCKET_API_BASE = 'https://api.spocket.co'56export async function POST(request: NextRequest) {7 const apiKey = process.env.SPOCKET_API_KEY89 if (!apiKey) {10 return NextResponse.json(11 { error: 'Spocket API key not configured' },12 { status: 500 }13 )14 }1516 try {17 const body = await request.json()1819 // Validate required fields20 if (!body.products || !body.shipping_address) {21 return NextResponse.json(22 { error: 'Missing required fields: products and shipping_address' },23 { status: 400 }24 )25 }2627 const response = await fetch(`${SPOCKET_API_BASE}/v1/orders`, {28 method: 'POST',29 headers: {30 Authorization: `Bearer ${apiKey}`,31 'Content-Type': 'application/json',32 },33 body: JSON.stringify({34 order: {35 line_items: body.products.map((item: {36 product_id: string37 variant_id: string38 quantity: number39 }) => ({40 product_id: item.product_id,41 variant_id: item.variant_id,42 quantity: item.quantity,43 })),44 shipping_address: body.shipping_address,45 },46 }),47 })4849 if (!response.ok) {50 const errorBody = await response.json().catch(() => ({}))51 return NextResponse.json(52 { error: errorBody.message || `Order failed: ${response.status}` },53 { status: response.status }54 )55 }5657 const order = await response.json()58 return NextResponse.json({ success: true, order_id: order.id })59 } catch (error) {60 console.error('Failed to create Spocket order:', error)61 return NextResponse.json(62 { error: 'Failed to create order' },63 { status: 500 }64 )65 }66}Pro tip: Always place order creation after payment confirmation in your checkout flow. Call the Spocket order API only after Stripe (or your payment provider) confirms the payment succeeded — this prevents fulfilling orders for failed payments.
Expected result: The full dropshipping flow works end to end: products load from Spocket on the catalog page, product detail pages show variants and inventory, and submitting a checkout order sends the order to Spocket for fulfillment. The Vercel deployment logs show no authentication errors.
Common use cases
Niche Dropshipping Storefront
An entrepreneur wants to launch a focused dropshipping store in a specific niche — for example, sustainable home goods or fitness accessories. They use V0 to generate the storefront UI with a product grid, filters, and checkout flow, and connect it to Spocket's catalog filtered to relevant categories using the API route.
Create a product catalog page for a dropshipping store. Show products in a 3-column grid on desktop, 2-column on tablet, 1-column on mobile. Each product card shows an image, product name, price, and an 'Add to Cart' button. Include filter buttons at the top for category filtering. Fetch products from /api/spocket/products and display a loading skeleton while fetching.
Copy this prompt to try it in V0
Product Detail Page with Variants
A Spocket store needs individual product pages showing multiple product variants such as sizes and colors, with real-time inventory status so customers know immediately if a variant is out of stock before adding to cart.
Build a product detail page that fetches data from /api/spocket/products/[id]. Show the product image gallery, title, price, description, and a variant selector for size and color options. Display an inventory badge showing 'In Stock' or 'Out of Stock' per variant. Include an 'Add to Cart' button that is disabled when the selected variant is out of stock.
Copy this prompt to try it in V0
Order Management Dashboard
A store owner wants an admin panel to view incoming orders and their fulfillment status from Spocket. The dashboard shows order details, customer information, shipping status, and allows the owner to see which orders are pending, in transit, or delivered.
Create an admin order management table that fetches orders from /api/spocket/orders. Show columns for Order ID, Customer Name, Order Date, Total Amount, Status (with color-coded badges: Pending=yellow, Shipped=blue, Delivered=green), and a View Details button. Include a search input to filter by customer name or order ID.
Copy this prompt to try it in V0
Troubleshooting
API route returns 401 Unauthorized when calling Spocket
Cause: The SPOCKET_API_KEY environment variable is missing, incorrectly named, or the API key has been revoked in the Spocket dashboard.
Solution: Go to Vercel Dashboard → Settings → Environment Variables and confirm SPOCKET_API_KEY is present and spelled exactly right (no extra spaces or quotes). Verify the key is still active in your Spocket account under Settings → API. After fixing the environment variable, redeploy your Vercel project for the change to take effect.
Products load in local development but show an error in Vercel production
Cause: The SPOCKET_API_KEY environment variable was added to .env.local for local dev but was not added to Vercel Dashboard environment variables for production.
Solution: Open Vercel Dashboard → your project → Settings → Environment Variables and add SPOCKET_API_KEY with the Production environment selected. Then trigger a redeployment — environment variables added to Vercel do not apply to already-running deployments.
Product images from Spocket are not loading — showing broken image icons
Cause: Spocket product image URLs use external domains that are not listed in the Next.js Image component's allowed domains configuration in next.config.ts.
Solution: Open next.config.ts and add Spocket's image CDN domain to the remotePatterns list. Check the actual image URLs from the Spocket API response to find the exact domain (typically images.spocket.co or a CDN domain).
1// next.config.ts2const nextConfig = {3 images: {4 remotePatterns: [5 {6 protocol: 'https',7 hostname: 'images.spocket.co',8 },9 {10 protocol: 'https',11 hostname: '*.spocket.co',12 },13 ],14 },15}16export default nextConfigThe product catalog shows stale prices or out-of-stock items that are actually available
Cause: The Next.js fetch cache is serving stale Spocket data beyond the inventory's actual update frequency.
Solution: Reduce the revalidate time on your fetch call in the API route. For inventory data that changes frequently, use revalidate: 60 (1 minute) or revalidate: 0 to always fetch fresh data. Balance freshness against Spocket API rate limits.
1// For frequently-changing inventory data:2next: { revalidate: 60 } // refresh every 60 seconds34// For always-fresh data (use sparingly — increases API calls):5next: { revalidate: 0 }Best practices
- Never use the NEXT_PUBLIC_ prefix for SPOCKET_API_KEY — this would expose your key in the browser JavaScript bundle and allow anyone to make API calls on your account
- Add server-side caching with next: { revalidate: 300 } on product catalog fetches to reduce Spocket API calls and improve page load speed for your users
- Validate required fields in your order creation route before calling the Spocket API — sending incomplete orders wastes API quota and makes debugging harder
- Always confirm payment with Stripe or another payment processor before calling the Spocket order API — never create a Spocket order for an unconfirmed payment
- Add the Spocket image CDN domain to next.config.ts remotePatterns when using the Next.js Image component — failing to do this breaks all product images in production
- Use TypeScript interfaces for Spocket API response shapes to catch data structure mismatches before they cause runtime errors in your components
- Handle the case where Spocket returns empty inventory data gracefully in your UI — show an 'Out of Stock' badge rather than crashing or showing a negative inventory number
Alternatives
Square is better suited for businesses with both online and physical retail, offering a unified inventory and point-of-sale system rather than a dropshipping catalog.
Stripe handles payment processing rather than product sourcing — use Stripe alongside Spocket to handle the payment step in your checkout flow.
Teachable is an alternative if you want to sell digital products or courses instead of physical dropshipped goods, requiring a completely different V0 storefront architecture.
Frequently asked questions
Does Spocket have an official V0 or Next.js integration?
Spocket does not have an official V0 integration or a dedicated Next.js SDK. The integration works through Spocket's standard REST API, which you call from a Next.js API route using fetch. This is the same pattern used for any REST API integration in a V0-generated project.
Is Spocket API access available on the free plan?
Spocket's API access is available on paid plans. Check your account's Settings → API section to see if API credentials are available for your subscription tier. If you do not see an API section, you may need to upgrade to a plan that includes API access.
How do I handle Spocket's rate limits in my Next.js API route?
Add server-side caching to your fetch calls using next: { revalidate: 300 } for product catalog data. This reduces the number of requests sent to Spocket by serving cached data for 5 minutes. For individual product pages with higher traffic, consider generating static pages with generateStaticParams to pre-render them at build time, eliminating runtime API calls entirely.
Can I use Spocket with a Vercel serverless function cold start?
Yes, but be aware that Vercel serverless functions (API routes) have cold start times of a few hundred milliseconds after periods of inactivity. For product catalog pages that need fast load times, use Next.js server-side caching (next: { revalidate }) so the cached response is served instantly without a Spocket API call on every request.
How do I sync Spocket product updates to my Next.js storefront automatically?
Use Spocket webhooks if available on your plan to trigger a revalidation of your Next.js cache when products change. Send a POST request to Next.js's revalidatePath or revalidateTag function from your webhook handler, which clears the cached product data and forces a fresh fetch from Spocket on the next page load.
Can I filter Spocket products by category, price range, or supplier location in the API route?
Yes — the Spocket API accepts query parameters for filtering, which you can pass through from your frontend. Read the filter values from the request URL's searchParams in your API route handler and forward them to the Spocket API request. This lets your V0-generated filter UI control which products are shown without any additional backend logic.
What happens if the Spocket API is down when a customer tries to place an order?
Your API route will catch the network error and return a 500 response to the frontend. Your V0-generated checkout component should handle this by displaying a user-friendly error message: 'Unable to process your order right now — please try again in a moment.' Add retry logic in the checkout component that allows the customer to retry the order without re-entering their information.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation