UNPKG

@metalcamp/stockx-data

Version:

Unofficial StockX API to scrape product info utilizing requests/promises

47 lines (46 loc) 2.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = __importDefault(require("axios")); exports.default = async (product) => { const res = await axios_1.default.get(`https://stockx.com/api/products/${product}?includes=market`, { headers: { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36", accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept-language": "en-US,en;q=0.9", "sec-ch-ua": '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"', "sec-ch-ua-mobile": "?0", "sec-fetch-dest": "document", "sec-fetch-mode": "navigate", "sec-fetch-site": "none", "sec-fetch-user": "?1", "upgrade-insecure-requests": "1", }, }); const productDetails = res.data.Product; let sizeMap = {}; Object.keys(productDetails.children).map((id) => { sizeMap[productDetails.children[id].shoeSize] = id; }); return { name: productDetails.title, pid: productDetails.styleId, image: productDetails.media.imageUrl, uuid: productDetails.uuid, size: productDetails.shoeSize, searchKey: productDetails.shortDescription, details: { retail: productDetails.retailPrice, releaseDate: productDetails.releaseDate, colorway: productDetails.colorway, brand: productDetails.brand, type: productDetails.shoe, gender: productDetails.gender, description: productDetails.description, }, market: productDetails.market, sizeMap: sizeMap, }; };