# Mouser Api > Mouser Electronics provides a public Search API for programmatic access to their electronic components catalog. The API supports keyword and part number searches, returning detailed product informatio --- # Mouser Electronics Search API ## Overview Mouser Electronics provides a public Search API for programmatic access to their electronic components catalog. The API supports keyword and part number searches, returning detailed product information including pricing, availability, and datasheets. ## Key Features - **Keyword Search**: Find parts by description, family name, or parameters - **Part Number Search**: Exact or partial part number lookup - **JSON/XML Responses**: Both formats supported, JSON recommended - **Real-time Data**: Live pricing, inventory, and lead times ## API Hub - **Main Portal**: https://www.mouser.com/api-hub/ - **Search API**: https://www.mouser.com/api-search/ - **Order API**: https://www.mouser.com/api-order/ - **Terms of Service**: https://www.mouser.com/apiterms/ ## Rate Limits | Limit | Value | |-------|-------| | Results per call | 50 max | | Calls per minute | 30 | | Calls per day | 1,000 | Higher limits may be negotiated directly with Mouser for commercial applications. ## Related APIs Mouser also provides: - **Cart API** - Automate cart creation and updates - **Order API** - Place and manage orders programmatically Each API requires separate registration and has its own documentation. ## Getting Started 1. Create a [My Mouser](https://www.mouser.com/) account 2. Complete the Search API Request Form 3. Receive your API key via email 4. Start making API calls ## Sources - [Mouser Search API](https://www.mouser.com/api-search/) - [Mouser API Hub](https://www.mouser.com/api-hub/) - [sparkmicro/mouser-api](https://github.com/sparkmicro/mouser-api) --- # Mouser API Authentication ## API Key Mouser uses a static API key for authentication. The key is passed in the request body, not as a header. ### Obtaining an API Key 1. **Create Account**: Log into or create a [My Mouser](https://www.mouser.com/) account 2. **Request Access**: Complete the Search API Request Form at https://www.mouser.com/api-search/ 3. **Receive Key**: Mouser sends your API key via email ### Using the API Key The key is included in the JSON request body: ```json { "apiKey": "YOUR_MOUSER_SEARCH_API_KEY", "SearchByKeywordRequest": { "keyword": "microcontroller" } } ``` ## Security Requirements - Keep your API key secret - Never expose keys in client-side code - Use environment variables or secure vaults - HTTPS is required for all API calls ## Terms of Service You must comply with Mouser's [Search API Terms of Service](https://www.mouser.com/apiterms/), including: - Acceptable use policies - Attribution requirements - Non-competitive use restrictions ## Environment Variable Example ```bash # .env or shell config export MOUSER_API_KEY="your-api-key-here" ``` ```python import os api_key = os.environ.get("MOUSER_API_KEY") ``` --- # Mouser API Endpoints ## Base URL ``` https://api.mouser.com/api/v1/search/ ``` ## Endpoints | Endpoint | Method | Description | |----------|--------|-------------| | `/searchbykeyword` | POST | Search by keyword/description | | `/searchbypartnumber` | POST | Search by part number | ## Search by Keyword **Endpoint**: `POST https://api.mouser.com/api/v1/search/searchbykeyword` ### Request Body ```json { "apiKey": "YOUR_MOUSER_SEARCH_API_KEY", "SearchByKeywordRequest": { "keyword": "STM32F103", "records": 25, "pageNumber": 1, "searchOptions": "" } } ``` ### Parameters | Parameter | Type | Description | |-----------|------|-------------| | `keyword` | string | Search term (required) | | `records` | int | Results per page (max 50) | | `pageNumber` | int | Page number for pagination | | `searchOptions` | string | Additional filters | ## Search by Part Number **Endpoint**: `POST https://api.mouser.com/api/v1/search/searchbypartnumber` ### Request Body ```json { "apiKey": "YOUR_MOUSER_SEARCH_API_KEY", "SearchByPartRequest": { "mouserPartNumber": "595-SN74HC595N" } } ``` ### Parameters | Parameter | Type | Description | |-----------|------|-------------| | `mouserPartNumber` | string | Mouser part number (recommended) | You can also search by manufacturer part number or partial numbers. ## HTTP Headers ``` Content-Type: application/json Accept: application/json ``` ## Error Responses | Status | Description | |--------|-------------| | 400 | Bad request / malformed payload | | 401/403 | Authentication or terms violation | | 429 | Rate limit exceeded | | 5xx | Server error | Error payloads include a description of the issue: ```json { "Errors": [ { "Code": "InvalidApiKey", "Message": "The API key provided is invalid" } ] } ``` --- # Mouser API Response Format ## Response Structure ### Keyword Search Response ```json { "SearchByKeywordResponse": { "NumberOfResult": 1234, "Parts": [ { "MouserPartNumber": "595-SN74HC595N", "ManufacturerPartNumber": "SN74HC595N", "Manufacturer": "Texas Instruments", "Availability": "3,456 In Stock", "DataSheetUrl": "https://...", "Description": "Shift Registers 8-Bit Shift Register", "ImagePath": "https://...", "Category": "Shift Registers", "ProductDetailUrl": "https://www.mouser.com/ProductDetail/595-SN74HC595N", "PriceBreaks": [ {"Quantity": 1, "Price": "0.45"}, {"Quantity": 10, "Price": "0.40"} ] } ] } } ``` ### Part Number Search Response ```json { "SearchByPartResponse": { "Parts": [ { "MouserPartNumber": "...", "ManufacturerPartNumber": "...", ... } ] } } ``` ## Available Fields Each part in the response includes: | Field | Description | |-------|-------------| | `MouserPartNumber` | Mouser's part number | | `ManufacturerPartNumber` | Manufacturer's part number | | `Manufacturer` | Manufacturer name | | `Availability` | Stock status (e.g., "3,456 In Stock") | | `DataSheetUrl` | Link to datasheet PDF | | `Description` | Product description | | `ImagePath` | Product image URL | | `Category` | Product category | | `Packaging` | Package type (Tube, Reel, etc.) | | `ProductCompliance` | Compliance info (REACH, RoHS) | | `LifecycleStatus` | Active, NRND, Obsolete, etc. | | `RoHSStatus` | RoHS compliance status | | `Reeling` | Cut tape/reeling availability | | `Min` | Minimum order quantity | | `Mult` | Order quantity multiple | | `LeadTime` | Lead time if not in stock | | `SuggestedReplacement` | Array of replacement parts | | `ProductDetailUrl` | Product page URL | | `PriceBreaks` | Array of quantity/price tiers | | `StandardPackQuantity` | Standard package quantity | ## Price Breaks Up to 4 price breaks are returned per part: ```json "PriceBreaks": [ {"Quantity": 1, "Price": "0.45"}, {"Quantity": 10, "Price": "0.40"}, {"Quantity": 100, "Price": "0.35"}, {"Quantity": 1000, "Price": "0.30"} ] ``` ## Pagination For large result sets: 1. Set `records` to desired page size (max 50) 2. Use `pageNumber` to iterate through pages 3. Check `NumberOfResult` for total count ```python total_results = response["SearchByKeywordResponse"]["NumberOfResult"] total_pages = (total_results + records - 1) // records ``` --- # Mouser API Code Examples ## Python ### Search by Part Number ```python import requests import os API_KEY = os.environ.get("MOUSER_API_KEY") BASE_URL = "https://api.mouser.com/api/v1/search/searchbypartnumber" def search_part(part_number: str) -> dict: payload = { "apiKey": API_KEY, "SearchByPartRequest": { "mouserPartNumber": part_number } } response = requests.post(BASE_URL, json=payload, timeout=15) response.raise_for_status() return response.json() # Usage data = search_part("595-SN74HC595N") parts = data.get("SearchByPartResponse", {}).get("Parts", []) for part in parts: print(f"Mouser P/N: {part.get('MouserPartNumber')}") print(f"Mfr P/N: {part.get('ManufacturerPartNumber')}") print(f"Availability: {part.get('Availability')}") print(f"Datasheet: {part.get('DataSheetUrl')}") price_breaks = part.get("PriceBreaks", []) if price_breaks: print(f"Unit Price: ${price_breaks[0].get('Price')}") ``` ### Search by Keyword ```python import requests import os API_KEY = os.environ.get("MOUSER_API_KEY") BASE_URL = "https://api.mouser.com/api/v1/search/searchbykeyword" def search_keyword(keyword: str, records: int = 25, page: int = 1) -> dict: payload = { "apiKey": API_KEY, "SearchByKeywordRequest": { "keyword": keyword, "records": records, "pageNumber": page } } response = requests.post(BASE_URL, json=payload, timeout=15) response.raise_for_status() return response.json() # Usage data = search_keyword("STM32F103", records=20) resp = data.get("SearchByKeywordResponse", {}) print(f"Total results: {resp.get('NumberOfResult')}") for part in resp.get("Parts", []): print(f"{part.get('MouserPartNumber')} - {part.get('Description')}") print(f" Stock: {part.get('Availability')}") ``` ### Pagination Example ```python def search_all(keyword: str, max_results: int = 200) -> list: """Fetch multiple pages of results.""" all_parts = [] page = 1 records_per_page = 50 # API max while len(all_parts) < max_results: data = search_keyword(keyword, records=records_per_page, page=page) resp = data.get("SearchByKeywordResponse", {}) parts = resp.get("Parts", []) if not parts: break all_parts.extend(parts) total = resp.get("NumberOfResult", 0) if len(all_parts) >= total: break page += 1 return all_parts[:max_results] ``` ## JavaScript / Node.js ### Search by Part Number ```javascript const API_KEY = process.env.MOUSER_API_KEY; const BASE_URL = "https://api.mouser.com/api/v1/search/searchbypartnumber"; async function searchPart(partNumber) { const body = { apiKey: API_KEY, SearchByPartRequest: { mouserPartNumber: partNumber } }; const response = await fetch(BASE_URL, { method: "POST", headers: { "Content-Type": "application/json", "Accept": "application/json" }, body: JSON.stringify(body) }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${await response.text()}`); } return response.json(); } // Usage const data = await searchPart("595-SN74HC595N"); const parts = data.SearchByPartResponse?.Parts || []; parts.forEach(part => { console.log(`${part.MouserPartNumber} - ${part.Description}`); console.log(` Stock: ${part.Availability}`); console.log(` Datasheet: ${part.DataSheetUrl}`); }); ``` ## cURL ### Keyword Search ```bash curl -X POST "https://api.mouser.com/api/v1/search/searchbykeyword" \ -H "Content-Type: application/json" \ -d '{ "apiKey": "YOUR_API_KEY", "SearchByKeywordRequest": { "keyword": "ATmega328", "records": 10, "pageNumber": 1 } }' ``` ### Part Number Search ```bash curl -X POST "https://api.mouser.com/api/v1/search/searchbypartnumber" \ -H "Content-Type: application/json" \ -d '{ "apiKey": "YOUR_API_KEY", "SearchByPartRequest": { "mouserPartNumber": "556-ATMEGA328P-PU" } }' ``` ## Third-Party Libraries ### Python: sparkmicro/mouser-api ```bash pip install mouser-api ``` ```python from mouser.api import MouserPartSearchRequest request = MouserPartSearchRequest('YOUR_API_KEY') result = request.part_search('595-SN74HC595N') ``` GitHub: https://github.com/sparkmicro/mouser-api