As of March 31, 2022 Octopart APIv3 will no longer be supported. As of June 30, 2022 this version will be completely disabled.
Octopart APIv3 and Nexar Legacy API REST provide a powerful search interface that's easy to use but will take some time to master. The following is a tutorial that will take you through the features of the search interface by using common part search examples. Although the examples are all focused on part search, the other API collections (e.g. brands, categories, and sellers) have the same search interface so the lessons can be applied to those search endpoints as well.
One thing to note is that although the "parts/search" endpoint can be used to search for parts by MPN or SKU, you can only execute one search per request. For BOM matching applications that are only interested in matching parts by part number, it is highly recommended that you use the "parts/match" endpoint which is optimized for that use-case. To learn more about BOM matching with Octopart APIv3 and Nexar Legacy API REST, a good starting point is the BOM Quickstart tutorial.
This tutorial follows a narrative style. To access the reference documentation, please visit the REST API Reference Documentation page.
Keyword Search
Octopart APIv3 and Nexar Legacy API REST search interface allows you to search across parts by keyword using the q url argument:
importjsonimporturlliburl="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"args=[('q','solid state relay'),('start',0),('limit',10)]url+='&'+urllib.urlencode(args)data=urllib.urlopen(url).read()search_response=json.loads(data)# print number of hitsprintsearch_response['hits']# print resultsforresultinsearch_response['results']:part=result['item']# print matched partprint"%s - %s"%(part['brand']['name'],part['mpn'])
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"solid state relay",:start=>0,:limit=>10}url+="&"+to_query(params)resp=Net::HTTP.get_response(URI.parse(url))search_response=JSON.parse(resp.body)# print number of hitsputssearch_response['hits']# print resultssearch_response['results'].eachdo|result|part=result['item']# print matched partputspart['brand']['name']+' - '+part['mpn']end
<script src="http://code.jquery.com/jquery-1.11.0.js"></script><script>varurl="http://octopart.com/api/v3/parts/search";url+="?callback=?";// NOTE: Use your API key here (https://octopart.com/api/register)url+="&apikey=REPLACE_ME";varargs={q:"solid state relay",start:0,limit:10};$.getJSON(url,args,function(search_response){// print original requestconsole.log(search_response['request']);// iterate through results$.each(search_response['results'],function(i,result){varpart=result['item'];// print matched part itemsconsole.log(part['brand']['name']+' - '+part['mpn']);});});</script>
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassKeywordSearch1{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="solid state relay";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/search";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("q",query).AddParameter("start","0").AddParameter("limit","10");// Perform the search and obtain resultsvarresp=client.Execute(req);varsearch_response=JsonConvert.DeserializeObject<dynamic>(resp.Content);// Print the number of hits and resultsConsole.WriteLine("Number of hits: "+search_response["hits"]);foreach(varresultinsearch_response["results"]){varpart=result["item"];Console.WriteLine(part["brand"]["name"]+" - "+part["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleKeywordSearch1PublicSubExecuteSearch()' -- your search query --DimqueryAsString="solid state relay"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="parts/search"DimapiKeyAsString=KeywordSearch1.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("q",query) _
.AddParameter("start","0") _
.AddParameter("limit","10")' Perform the search and obtain resultsDimresp=client.Execute(req)Dimsearch_response=JsonConvert.DeserializeObject(resp.Content)' Print the number of hits and resultsConsole.WriteLine("Number of hits: "&search_response("hits"))ForEachresultInsearch_response("results")Dimpart=result("item")Console.WriteLine(part("brand")("name")&" - "&part("mpn"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
By default, all keywords must be present in a part object in order for it to match. However, the words can appear in any field within the part. Keyword searches are executed across the following fields:
mpn
brand.name
offers.seller.name
offers.sku
descriptions.value
This feature of the search engine allows you to search intuitively across highly structured objects. For example, if you want to narrow your query by manufacturer you can add the manufacturer brand name to the q argument:
importjsonimporturlliburl="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"args=[('q','Omron solid state relay'),('start',0),('limit',10)]url+='&'+urllib.urlencode(args)data=urllib.urlopen(url).read()search_response=json.loads(data)# print number of hitsprintsearch_response['hits']# print resultsforresultinsearch_response['results']:part=result['item']# print matched partprint"%s - %s"%(part['brand']['name'],part['mpn'])
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"Omron solid state relay",:start=>0,:limit=>10}url+="&"+to_query(params)resp=Net::HTTP.get_response(URI.parse(url))search_response=JSON.parse(resp.body)# print number of hitsputssearch_response['hits']# print resultssearch_response['results'].eachdo|result|part=result['item']# print matched partputspart['brand']['name']+' - '+part['mpn']end
<script src="http://code.jquery.com/jquery-1.11.0.js"></script><script>varurl="http://octopart.com/api/v3/parts/search";url+="?callback=?";// NOTE: Use your API key here (https://octopart.com/api/register)url+="&apikey=REPLACE_ME";varargs={q:"Omron solid state relay",start:0,limit:10};$.getJSON(url,args,function(search_response){// print original requestconsole.log(search_response['request']);// iterate through results$.each(search_response['results'],function(i,result){varpart=result['item'];// print matched part itemsconsole.log(part['brand']['name']+' - '+part['mpn']);});});</script>
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassKeywordSearch2{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="Omron solid state relay";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/search";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("q",query).AddParameter("start","0").AddParameter("limit","10");// Perform the search and obtain resultsvarresp=client.Execute(req);varsearch_response=JsonConvert.DeserializeObject<dynamic>(resp.Content);// Print the number of hits and resultsConsole.WriteLine("Number of hits: "+search_response["hits"]);foreach(varresultinsearch_response["results"]){varpart=result["item"];Console.WriteLine(part["brand"]["name"]+" - "+part["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleKeywordSearch2PublicSubExecuteSearch()' -- your search query --DimqueryAsString="Omron solid state relay"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="parts/search"DimapiKeyAsString=KeywordSearch2.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("q",query) _
.AddParameter("start","0") _
.AddParameter("limit","10")' Perform the search and obtain resultsDimresp=client.Execute(req)Dimsearch_response=JsonConvert.DeserializeObject(resp.Content)' Print the number of hits and resultsConsole.WriteLine("Number of hits: "&search_response("hits"))ForEachresultInsearch_response("results")Dimpart=result("item")Console.WriteLine(part("brand")("name")&" - "&part("mpn"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
The q url argument also allows you to filter out keywords by using the "NOT" operator. For example, if you want your search to exclude parts made by a particular manufacturer, you can add a "NOT" to the manufacturer brand name in the q argument:
importjsonimporturlliburl="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"args=[('q','NOT Omron solid state relay'),('start',0),('limit',10)]url+='&'+urllib.urlencode(args)data=urllib.urlopen(url).read()search_response=json.loads(data)# print number of hitsprintsearch_response['hits']# print resultsforresultinsearch_response['results']:part=result['item']# print matched partprint"%s - %s"%(part['brand']['name'],part['mpn'])
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"NOT Omron solid state relay",:start=>0,:limit=>10}url+="&"+to_query(params)resp=Net::HTTP.get_response(URI.parse(url))search_response=JSON.parse(resp.body)# print number of hitsputssearch_response['hits']# print resultssearch_response['results'].eachdo|result|part=result['item']# print matched partputspart['brand']['name']+' - '+part['mpn']end
<script src="http://code.jquery.com/jquery-1.11.0.js"></script><script>varurl="http://octopart.com/api/v3/parts/search";url+="?callback=?";// NOTE: Use your API key here (https://octopart.com/api/register)url+="&apikey=REPLACE_ME";varargs={q:"NOT Omron solid state relay",start:0,limit:10};$.getJSON(url,args,function(search_response){// print original requestconsole.log(search_response['request']);// iterate through results$.each(search_response['results'],function(i,result){varpart=result['item'];// print matched part itemsconsole.log(part['brand']['name']+' - '+part['mpn']);});});</script>
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassBooleanOperators{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="NOT Omron solid state relay";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/search";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("q",query).AddParameter("start","0").AddParameter("limit","10");// Perform the search and obtain resultsvarresp=client.Execute(req);varsearch_response=JsonConvert.DeserializeObject<dynamic>(resp.Content);// Print the number of hits and resultsConsole.WriteLine("Number of hits: "+search_response["hits"]);foreach(varresultinsearch_response["results"]){varpart=result["item"];Console.WriteLine(part["brand"]["name"]+" - "+part["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleBooleanOperatorsPublicSubExecuteSearch()' -- your search query --DimqueryAsString="NOT Omron solid state relay"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="parts/search"DimapiKeyAsString=BooleanOperators.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("q",query) _
.AddParameter("start","0") _
.AddParameter("limit","10")' Perform the search and obtain resultsDimresp=client.Execute(req)Dimsearch_response=JsonConvert.DeserializeObject(resp.Content)' Print the number of hits and resultsConsole.WriteLine("Number of hits: "&search_response("hits"))ForEachresultInsearch_response("results")Dimpart=result("item")Console.WriteLine(part("brand")("name")&" - "&part("mpn"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
importjsonimporturlliburl="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"args=[('q','Omron "solid state relay"'),('start',0),('limit',10)]url+='&'+urllib.urlencode(args)data=urllib.urlopen(url).read()search_response=json.loads(data)# print number of hitsprintsearch_response['hits']# print resultsforresultinsearch_response['results']:part=result['item']# print matched partprint"%s - %s"%(part['brand']['name'],part['mpn'])
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"Omron \"solid state relay\"",:start=>0,:limit=>10}url+="&"+to_query(params)resp=Net::HTTP.get_response(URI.parse(url))search_response=JSON.parse(resp.body)# print number of hitsputssearch_response['hits']# print resultssearch_response['results'].eachdo|result|part=result['item']# print matched partputspart['brand']['name']+' - '+part['mpn']end
<script src="http://code.jquery.com/jquery-1.11.0.js"></script><script>varurl="http://octopart.com/api/v3/parts/search";url+="?callback=?";// NOTE: Use your API key here (https://octopart.com/api/register)url+="&apikey=REPLACE_ME";varargs={q:'Omron "solid state relay"',start:0,limit:10};$.getJSON(url,args,function(search_response){// print original requestconsole.log(search_response['request']);// iterate through results$.each(search_response['results'],function(i,result){varpart=result['item'];// print matched part itemsconsole.log(part['brand']['name']+' - '+part['mpn']);});});</script>
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassPhraseMatching{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="Omron \"solid state relay\"";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/search";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("q",query).AddParameter("start","0").AddParameter("limit","10");// Perform the search and obtain resultsvarresp=client.Execute(req);varsearch_response=JsonConvert.DeserializeObject<dynamic>(resp.Content);// Print the number of hits and resultsConsole.WriteLine("Number of hits: "+search_response["hits"]);foreach(varresultinsearch_response["results"]){varpart=result["item"];Console.WriteLine(part["brand"]["name"]+" - "+part["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModulePhraseMatchingPublicSubExecuteSearch()' -- your search query --DimqueryAsString="Omron ""solid state relay"""DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="parts/search"DimapiKeyAsString=PhraseMatching.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("q",query) _
.AddParameter("start","0") _
.AddParameter("limit","10")' Perform the search and obtain resultsDimresp=client.Execute(req)Dimsearch_response=JsonConvert.DeserializeObject(resp.Content)' Print the number of hits and resultsConsole.WriteLine("Number of hits: "&search_response("hits"))ForEachresultInsearch_response("results")Dimpart=result("item")Console.WriteLine(part("brand")("name")&" - "&part("mpn"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
The "parts/search" endpoint allows users to search for part numbers using wildcards. Wildcards can be used at the beginning, at the end, and anywhere within a part number. Multiple wildcards can be used but at least three alphanumeric characters must be present in the query term, otherwise it will be ignored. The asterisk wildcard ("*") can be used to match on zero or more characters and the question mark wildcard ("?") can be used to match on exactly one character:
importjsonimporturlliburl="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"args=[('q','SN74S7*'),('start',0),('limit',10)]url+='&'+urllib.urlencode(args)data=urllib.urlopen(url).read()search_response=json.loads(data)# print number of hitsprintsearch_response['hits']# print resultsforresultinsearch_response['results']:part=result['item']# print matched partprint"%s - %s"%(part['brand']['name'],part['mpn'])
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"SN74S7*",:start=>0,:limit=>10}url+="&"+to_query(params)resp=Net::HTTP.get_response(URI.parse(url))search_response=JSON.parse(resp.body)# print number of hitsputssearch_response['hits']# print resultssearch_response['results'].eachdo|result|part=result['item']# print matched partputspart['brand']['name']+' - '+part['mpn']end
<script src="http://code.jquery.com/jquery-1.11.0.js"></script><script>varurl="http://octopart.com/api/v3/parts/search";url+="?callback=?";// NOTE: Use your API key here (https://octopart.com/api/register)url+="&apikey=REPLACE_ME";varargs={q:"SN74S7*",start:0,limit:10};$.getJSON(url,args,function(search_response){// print original requestconsole.log(search_response['request']);// iterate through results$.each(search_response['results'],function(i,result){varpart=result['item'];// print matched part itemsconsole.log(part['brand']['name']+' - '+part['mpn']);});});</script>
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassPartNumberWildcards{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="SN74S7*";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/search";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("q",query).AddParameter("start","0").AddParameter("limit","10");// Perform the search and obtain resultsvarresp=client.Execute(req);varsearch_response=JsonConvert.DeserializeObject<dynamic>(resp.Content);// Print the number of hits and resultsConsole.WriteLine("Number of hits: "+search_response["hits"]);foreach(varresultinsearch_response["results"]){varpart=result["item"];Console.WriteLine(part["brand"]["name"]+" - "+part["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModulePartNumberWildcardsPublicSubExecuteSearch()' -- your search query --DimqueryAsString="SN74S7*"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="parts/search"DimapiKeyAsString=PartNumberWildcards.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("q",query) _
.AddParameter("start","0") _
.AddParameter("limit","10")' Perform the search and obtain resultsDimresp=client.Execute(req)Dimsearch_response=JsonConvert.DeserializeObject(resp.Content)' Print the number of hits and resultsConsole.WriteLine("Number of hits: "&search_response("hits"))ForEachresultInsearch_response("results")Dimpart=result("item")Console.WriteLine(part("brand")("name")&" - "&part("mpn"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
One important thing to note is that when a wildcard is present in a query term, that term will be treated as a part number and will not match on any other field.
Search Response Overview
Each API search endpoint returns a JSON object containing a list of search results along with some data about the search such as how long it took and the original request object. Here's an example of a parts search response:
For a more detailed explanation of the response object please see the SearchResponse object schema section of the REST API Reference Documentation.
Paging Through Results
By default, the parts/search endpoint returns up to 10 results per request. To change the number of results to return you can use the limit url argument:
importjsonimporturlliburl="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"args=[('q','solid state relay'),('start',0),('limit',20)]url+='&'+urllib.urlencode(args)data=urllib.urlopen(url).read()search_response=json.loads(data)# print number of hitsprintsearch_response['hits']# print resultsforresultinsearch_response['results']:part=result['item']# print matched partprint"%s - %s"%(part['brand']['name'],part['mpn'])
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"solid state relay",:start=>0,:limit=>20}url+="&"+to_query(params)resp=Net::HTTP.get_response(URI.parse(url))search_response=JSON.parse(resp.body)# print number of hitsputssearch_response['hits']# print resultssearch_response['results'].eachdo|result|part=result['item']# print matched partputspart['brand']['name']+' - '+part['mpn']end
<script src="http://code.jquery.com/jquery-1.11.0.js"></script><script>varurl="http://octopart.com/api/v3/parts/search";url+="?callback=?";// NOTE: Use your API key here (https://octopart.com/api/register)url+="&apikey=REPLACE_ME";varargs={q:"solid state relay",start:0,limit:20};$.getJSON(url,args,function(search_response){// print original requestconsole.log(search_response['request']);// iterate through results$.each(search_response['results'],function(i,result){varpart=result['item'];// print matched part itemsconsole.log(part['brand']['name']+' - '+part['mpn']);});});</script>
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassLimitArgument{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="solid state relay";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/search";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("q",query).AddParameter("start","0").AddParameter("limit","20");// Perform the search and obtain resultsvarresp=client.Execute(req);varsearch_response=JsonConvert.DeserializeObject<dynamic>(resp.Content);// Print the number of hits and resultsConsole.WriteLine("Number of hits: "+search_response["hits"]);foreach(varresultinsearch_response["results"]){varpart=result["item"];Console.WriteLine(part["brand"]["name"]+" - "+part["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleLimitArgumentPublicSubExecuteSearch()' -- your search query --DimqueryAsString="solid state relay"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="parts/search"DimapiKeyAsString=LimitArgument.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("q",query) _
.AddParameter("start","0") _
.AddParameter("limit","20")' Perform the search and obtain resultsDimresp=client.Execute(req)Dimsearch_response=JsonConvert.DeserializeObject(resp.Content)' Print the number of hits and resultsConsole.WriteLine("Number of hits: "&search_response("hits"))ForEachresultInsearch_response("results")Dimpart=result("item")Console.WriteLine(part("brand")("name")&" - "&part("mpn"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
importjsonimporturlliburl="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"args=[('q','solid state relay'),('start',20),('limit',20)]url+='&'+urllib.urlencode(args)data=urllib.urlopen(url).read()search_response=json.loads(data)# print number of hitsprintsearch_response['hits']# print resultsforresultinsearch_response['results']:part=result['item']# print matched partprint"%s - %s"%(part['brand']['name'],part['mpn'])
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"solid state relay",:start=>20,:limit=>20}url+="&"+to_query(params)resp=Net::HTTP.get_response(URI.parse(url))search_response=JSON.parse(resp.body)# print number of hitsputssearch_response['hits']# print resultssearch_response['results'].eachdo|result|part=result['item']# print matched partputspart['brand']['name']+' - '+part['mpn']end
<script src="http://code.jquery.com/jquery-1.11.0.js"></script><script>varurl="http://octopart.com/api/v3/parts/search";url+="?callback=?";// NOTE: Use your API key here (https://octopart.com/api/register)url+="&apikey=REPLACE_ME";varargs={q:"solid state relay",start:20,limit:20};$.getJSON(url,args,function(search_response){// print original requestconsole.log(search_response['request']);// iterate through results$.each(search_response['results'],function(i,result){varpart=result['item'];// print matched part itemsconsole.log(part['brand']['name']+' - '+part['mpn']);});});</script>
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassStartArgument{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="solid state relay";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/search";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("q",query).AddParameter("start","20").AddParameter("limit","20");// Perform the search and obtain resultsvarresp=client.Execute(req);varsearch_response=JsonConvert.DeserializeObject<dynamic>(resp.Content);// Print the number of hits and resultsConsole.WriteLine("Number of hits: "+search_response["hits"]);foreach(varresultinsearch_response["results"]){varpart=result["item"];Console.WriteLine(part["brand"]["name"]+" - "+part["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleStartArgumentPublicSubExecuteSearch()' -- your search query --DimqueryAsString="solid state relay"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="parts/search"DimapiKeyAsString=StartArgument.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("q",query) _
.AddParameter("start","20") _
.AddParameter("limit","20")' Perform the search and obtain resultsDimresp=client.Execute(req)Dimsearch_response=JsonConvert.DeserializeObject(resp.Content)' Print the number of hits and resultsConsole.WriteLine("Number of hits: "&search_response("hits"))ForEachresultInsearch_response("results")Dimpart=result("item")Console.WriteLine(part("brand")("name")&" - "&part("mpn"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
To change the sort order of the result set you can use the sortby url argument. The syntax for the sortby argument is "<fieldname> <sortorder>" where fieldname is the field to sort on (e.g. "brand.name", "specs.capacitance.value") and sortorder is either "asc" or "desc".
importjsonimporturlliburl="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"args=[('q','solid state relay'),('sortby','specs.current_rating.value desc')]url+='&'+urllib.urlencode(args)data=urllib.urlopen(url).read()search_response=json.loads(data)# print number of hitsprintsearch_response['hits']# print resultsforresultinsearch_response['results']:part=result['item']# print matched partprint"%s - %s"%(part['brand']['name'],part['mpn'])
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"solid state relay",:sortby=>"specs.current_rating.value desc"}url+="&"+to_query(params)resp=Net::HTTP.get_response(URI.parse(url))search_response=JSON.parse(resp.body)# print number of hitsputssearch_response['hits']# print resultssearch_response['results'].eachdo|result|part=result['item']# print matched partputspart['brand']['name']+' - '+part['mpn']end
<script src="http://code.jquery.com/jquery-1.11.0.js"></script><script>varurl="http://octopart.com/api/v3/parts/search";url+="?callback=?";// NOTE: Use your API key here (https://octopart.com/api/register)url+="&apikey=REPLACE_ME";varargs={q:"solid state relay",sortby:"specs.current_rating.value desc"};$.getJSON(url,args,function(search_response){// print original requestconsole.log(search_response['request']);// iterate through results$.each(search_response['results'],function(i,result){varpart=result['item'];// print matched part itemsconsole.log(part['brand']['name']+' - '+part['mpn']);});});</script>
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassSortByArgument1{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="solid state relay";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/search";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("q",query).AddParameter("sortby","specs.current_rating.value desc");// Perform the search and obtain resultsvarresp=client.Execute(req);varsearch_response=JsonConvert.DeserializeObject<dynamic>(resp.Content);// Print the number of hits and resultsConsole.WriteLine("Number of hits: "+search_response["hits"]);foreach(varresultinsearch_response["results"]){varpart=result["item"];Console.WriteLine(part["brand"]["name"]+" - "+part["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleSortByArgument1PublicSubExecuteSearch()' -- your search query --DimqueryAsString="solid state relay"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="parts/search"DimapiKeyAsString=SortByArgument1.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("q",query) _
.AddParameter("sortby","specs.current_rating.value desc")' Perform the search and obtain resultsDimresp=client.Execute(req)Dimsearch_response=JsonConvert.DeserializeObject(resp.Content)' Print the number of hits and resultsConsole.WriteLine("Number of hits: "&search_response("hits"))ForEachresultInsearch_response("results")Dimpart=result("item")Console.WriteLine(part("brand")("name")&" - "&part("mpn"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
By default, the value of sortby is "score desc" where "score" is a special field to indicate full-text matching score. To add a secondary sort value, you can comma separate sortby strings:
importjsonimporturlliburl="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"args=[('q','solid state relay'),('sortby','specs.current_rating.value desc, specs.isolation_voltage.value desc')]url+='&'+urllib.urlencode(args)data=urllib.urlopen(url).read()search_response=json.loads(data)# print number of hitsprintsearch_response['hits']# print resultsforresultinsearch_response['results']:part=result['item']# print matched partprint"%s - %s"%(part['brand']['name'],part['mpn'])
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/search"# NOTE: Use your API key here (https://octopart.com/api/register)url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"solid state relay",:sortby=>"specs.current_rating.value desc, specs.isolation_voltage.value desc"}url+="&"+to_query(params)resp=Net::HTTP.get_response(URI.parse(url))search_response=JSON.parse(resp.body)# print number of hitsputssearch_response['hits']# print resultssearch_response['results'].eachdo|result|part=result['item']# print matched partputspart['brand']['name']+' - '+part['mpn']end
<script src="http://code.jquery.com/jquery-1.11.0.js"></script><script>varurl="http://octopart.com/api/v3/parts/search";url+="?callback=?";// NOTE: Use your API key here (https://octopart.com/api/register)url+="&apikey=REPLACE_ME";varargs={q:"solid state relay",sortby:"specs.current_rating.value desc, specs.isolation_voltage.value desc"};$.getJSON(url,args,function(search_response){// print original requestconsole.log(search_response['request']);// iterate through results$.each(search_response['results'],function(i,result){varpart=result['item'];// print matched part itemsconsole.log(part['brand']['name']+' - '+part['mpn']);});});</script>
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassSortByArgument2{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="solid state relay";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/search";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("q",query).AddParameter("sortby","specs.current_rating.value desc, specs.isolation_voltage.value desc");// Perform the search and obtain resultsvarresp=client.Execute(req);varsearch_response=JsonConvert.DeserializeObject<dynamic>(resp.Content);// Print the number of hits and resultsConsole.WriteLine("Number of hits: "+search_response["hits"]);foreach(varresultinsearch_response["results"]){varpart=result["item"];Console.WriteLine(part["brand"]["name"]+" - "+part["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleSortByArgument2PublicSubExecuteSearch()' -- your search query --DimqueryAsString="solid state relay"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="parts/search"DimapiKeyAsString=SortByArgument2.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("q",query) _
.AddParameter("sortby","specs.current_rating.value desc, specs.isolation_voltage.value desc")' Perform the search and obtain resultsDimresp=client.Execute(req)Dimsearch_response=JsonConvert.DeserializeObject(resp.Content)' Print the number of hits and resultsConsole.WriteLine("Number of hits: "&search_response("hits"))ForEachresultInsearch_response("results")Dimpart=result("item")Console.WriteLine(part("brand")("name")&" - "&part("mpn"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
Several of the search endpoint url arguments use a variable referred to as <fieldname>. Fieldnames are dot-separated property names which can be used to reference nested property values. For example, to sort results alphabetically by manufacturer brand names you can use the brand.name fieldname in place of the specs.current_rating.value fieldname found above.
Note that not every field is searchable. Fields that are searchable can be used in filters, faceting, calculating stats and sorting. These are the searchable part fields:
Fieldname
Description
mpn
Manufacturer part number
brand.name
Manufacturer brand name
offers.sku
Distributor SKU
offers.seller.name
Distributor name
descriptions.value
Description text value
specs.*.value
Technical specs value property
specs.*.min_value
Technical specs min_value property
specs.*.max_value
Technical specs max_value property
category_uids
Category uid's
Filtering
Octopart APIv3 and Nexar Legacy API REST search interface allows you to filter results by the value of a given field using filter fields or to add more complex filters such as ranged filters and filters with wildcards using filter queries.
Filter Fields
The filter[fields][<fieldname>][] url argument allows you to add simple filters to a search result. To filter on a field just replace the <fieldname> value with the field you want to filter on and use the filter value as the url argument. Here's an example of how to display all Texas Instruments parts:
For more information about the filter[queries][] url argument please see the Search Documentation section of the REST API reference.
Faceting
Search facets allow you to implement guided search interfaces like those found on Amazon or eBay where users are presented with a list of filters and the number of items which apply to each filter. For example, search facets can be used to indicate to a user who has searched for "LEDs" how many Red, Green, or Yellow LEDs are in the result set.
Facet Fields
By adding url arguments of the form facet[fields][<fieldname>][include]=true the API will return the filters available for a given field. To facet on a particular field just replace the <fieldname> value with the field you want to facet on. Here's an example of how to see which manufacturers make solid state relays:
For more information about the facet[fields][<fieldname>] url argument please see the Search Documentation section of the REST API reference.
Facet Queries
The facet[queries][] url argument allows you to facet on more complex filter values using the "filter query" syntax (see Filter Queries Section above). Here's an example of how to calculate the number of solid state relays with a load current of 5A and 10A:
For more information about the facet[queries][] url argument please see the Search Documentation section of the REST API reference.
Calculating Statistics
By adding url arguments of the form stats[<fieldname>][include]=true the API will return statistics for the property values in the result set (e.g. min, max, mean, standard deviation). Here's an example of how to calculate statistics on current load values for solid state relays:
For more information about the stats[<fieldname>] url argument please see the Search Documentation section of the REST API reference.
Spec Drilldown
One problem with calculating facets and stats for part objects is that the technical specs which are relevant to each result set vary from query to query. For example, the technical specs that are relevant to a search for "capacitors" are different than those for "solid state relays". In many cases the ideal question to ask the search engine is, "for a given query X, what are the relevant technical specs I can filter on?"
To address this problem, Octopart APIv3 and Nexar Legacy API REST have a useful feature called "spec drilldown" which can be enabled by adding the url argument spec_drilldown[include]=true to the API request:
When you perform a spec drilldown the API will automatically facet on all technical spec string values and calculate stats for technical spec numeric values.
For more information about the spec_drilldown url argument please see the parts/search section of the REST API reference.