woolworths_search_products
Search Woolworths products by name, filter by special offers, sort by price or relevance, and browse results with pagination.
Instructions
Search for products on Woolworths. Requires session cookies to be obtained first.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| searchTerm | Yes | The product search term | |
| pageNumber | No | Page number for pagination (default: 1) | |
| pageSize | No | Number of results to return (default: 36) | |
| sortType | No | Sort order: TraderRelevance, PriceAsc, PriceDesc, Name (default: TraderRelevance) | TraderRelevance |
| isSpecial | No | Filter for special offers only (default: false) |
Implementation Reference
- src/index.ts:344-394 (handler)The main execution logic for the woolworths_search_products tool. Parses arguments, constructs a POST request to the Woolworths search API endpoint, and returns formatted search results or error.async function handleSearchProducts(args: any): Promise<any> { const searchTerm = args.searchTerm; const pageNumber = args.pageNumber ?? 1; const pageSize = args.pageSize ?? 36; const sortType = args.sortType ?? "TraderRelevance"; const isSpecial = args.isSpecial ?? false; // Woolworths search API endpoint (POST method) const url = `https://www.woolworths.com.au/apis/ui/Search/products`; const requestBody = { searchTerm, pageNumber, pageSize, sortType, location: `/shop/search/products?searchTerm=${encodeURIComponent(searchTerm)}`, formatObject: JSON.stringify({ name: searchTerm }), isSpecial, isBundle: false, isMobile: false, filters: [], groupEdmVariants: false, }; try { const data = await makeWoolworthsRequest(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(requestBody), }); return { success: true, searchTerm, totalResults: data.SearchResultsCount || 0, products: data.Products || [], pagination: data.Pagination || { TotalRecords: data.SearchResultsCount || 0, PageNumber: pageNumber, PageSize: pageSize, }, }; } catch (error: any) { return { success: false, error: error.message, }; } }
- src/index.ts:67-101 (schema)The input schema defining the parameters, types, descriptions, defaults, and requirements for the woolworths_search_products tool.name: "woolworths_search_products", description: "Search for products on Woolworths. Requires session cookies to be obtained first.", inputSchema: { type: "object", properties: { searchTerm: { type: "string", description: "The product search term", }, pageNumber: { type: "number", description: "Page number for pagination (default: 1)", default: 1, }, pageSize: { type: "number", description: "Number of results to return (default: 36)", default: 36, }, sortType: { type: "string", description: "Sort order: TraderRelevance, PriceAsc, PriceDesc, Name (default: TraderRelevance)", enum: ["TraderRelevance", "PriceAsc", "PriceDesc", "Name"], default: "TraderRelevance", }, isSpecial: { type: "boolean", description: "Filter for special offers only (default: false)", default: false, }, }, required: ["searchTerm"], }, },
- src/index.ts:639-641 (registration)The switch case in the main tool call handler that dispatches execution to the handleSearchProducts function.case "woolworths_search_products": result = await handleSearchProducts(args || {}); break;
- src/index.ts:210-248 (helper)Helper function used by the tool handler to perform authenticated HTTP requests to Woolworths APIs, including cookie management and error handling.async function makeWoolworthsRequest( url: string, options: any = {} ): Promise<any> { if (sessionCookies.length === 0) { throw new Error( "No session cookies available. Please use woolworths_get_cookies first." ); } const headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", Accept: "*/*", "Accept-Language": "en-US,en;q=0.9", Origin: "https://www.woolworths.com.au", Referer: "https://www.woolworths.com.au/", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-origin", Priority: "u=1, i", Cookie: getCookieHeader(), ...options.headers, }; const response = await fetch(url, { ...options, headers, }); if (!response.ok) { const errorText = await response.text(); throw new Error( `API request failed: ${response.status} ${response.statusText}. ${errorText}` ); } return response.json(); }