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 are a REST API's that are easy to query in any programming environment. The following is the full documentation for the REST API including schemas for the response and query objects as well as documentation for the REST endpoints. If you have any questions please chat with us at our Developer Forum or send us an email (support@nexar.com).
Object Schemas
The following are the schemas for the data objects returned by the API (e.g. brands, manufacturers, parts, offers, sellers):
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassBrandsGet{publicstaticvoidExecuteSearch(){// -- your search query --stringid="2239e3330e2df5fe";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="brands/{id}";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddUrlSegment("id",id);// Perform the search and obtain resultsvardata=client.Execute(req).Content;varbrand=JsonConvert.DeserializeObject<dynamic>(data);// Print the brand display nameConsole.WriteLine(brand["name"]);}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleBrandsGetPublicSubExecuteSearch()' -- your search query --DimidAsString="2239e3330e2df5fe"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="brands/{id}"DimapiKeyAsString=BrandsGet.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddUrlSegment("id",id)' Perform the search and obtain resultsDimdata=client.Execute(req).ContentDimbrand=JsonConvert.DeserializeObject(data)' Print the brand display nameConsole.WriteLine(brand("name"))EndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
These are some common HTTP responses and their likely causes:
200 OK: Brand was fetched successfuly
404 Not Found: The brand does not exist
This method allows searching across brands by keyword. This is the ideal method to use to go from a brand alias or keyword to a Octopart brand instance
Argument
Datatype
Default
q
string
""
start
integer
0
limit
integer
10
sortby
string
"score desc"
filter[fields][<fieldname>][]
string
""
filter[queries][]
string
""
facet[fields][<fieldname>][include]
boolean
false
facet[fields][<fieldname>][exclude_filter]
boolean
false
facet[fields][<fieldname>][start]
integer
0
facet[fields][<fieldname>][limit]
integer
10
facet[queries][]
string
""
stats[<fieldname>][include]
boolean
false
stats[<fieldname>][exclude_filter]
boolean
false
q
Full-text query string
start
Ordinal position of first result. First position is 0. Maximum is 1000.
limit
Maximum number of results to return. Default is 10. Maximum is 100.
sortby
Comma separated list of (fieldname, fieldorder) pairs
filter[fields][<fieldname>][]
Attribute (fieldname/fieldvalue) pair to filter results on
filter[queries][]
Arbitrary filter query string
facet[fields][<fieldname>][include]
If specified, perform faceting on given <fieldname>
facet[fields][<fieldname>][exclude_filter]
If specified, remove <fieldname> from filters when calculating facets for <fieldname>
facet[fields][<fieldname>][start]
Ordinal position of first facet to return. First position is 0. Maximum is 1000.
facet[fields][<fieldname>][limit]
Number of facets to return. Default is 10. Maximum is 100.
facet[queries][]
Arbitrary filter query string to facet on
stats[<fieldname>][include]
If specified, calculate statistics for <fieldname
stats[<fieldname>][exclude_filter]
If specified, remove <fieldname> from filters when calculating statistics for <fieldname>
importjsonimporturlliburl="http://octopart.com/api/v3/brands/search"url+="?apikey=REPLACE_ME"args=[('q','texas'),('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']:# print matched brandprintresult['item']['name']
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/brands/search"url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"texas",: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|# print matched brandputsresult['item']['name']end
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassBrandsSearch{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="texas";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="brands/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 resultsvardata=client.Execute(req).Content;varsearch_response=JsonConvert.DeserializeObject<dynamic>(data);// Print the number of hitsConsole.WriteLine(search_response["hits"]);// Print resultsforeach(varresultinsearch_response["results"]){// Print matched brandConsole.WriteLine(result["item"]["name"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleBrandsSearchPublicSubExecuteSearch()' -- your search query --DimqueryAsString="texas"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="brands/search"DimapiKeyAsString=BrandsSearch.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 resultsDimdata=client.Execute(req).ContentDimsearch_response=JsonConvert.DeserializeObject(data)' Print the number of hitsConsole.WriteLine(search_response("hits"))' Print resultsForEachresultInsearch_response("results")' Print matched brandConsole.WriteLine(result("item")("name"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassBrandsGetMulti{publicstaticvoidExecuteSearch(){// -- your search query --stringid1="2239e3330e2df5fe";stringid2="c4f105fbe7591336";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEntpoint="brands/get_multi";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEntpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("uid[]",id1).AddParameter("uid[]",id2);// Perform the search and obtain resultsvardata=client.Execute(req).Content;varserver_response=JsonConvert.DeserializeObject<dynamic>(data);// Print the brand display namesforeach(varuidinserver_response){Console.WriteLine(uid.Value["name"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleBrandsGetMultiPublicSubExecuteSearch()' -- your search query --Dimid1AsString="2239e3330e2df5fe"Dimid2AsString="c4f105fbe7591336"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEntpointAsString="brands/get_multi"DimapiKeyAsString=BrandsGetMulti.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEntpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("uid[]",id1) _
.AddParameter("uid[]",id2)' Perform the search and obtain resultsDimdata=client.Execute(req).ContentDimserver_response=JsonConvert.DeserializeObject(data)' Print the brand display namesForEachuidInserver_responseConsole.WriteLine(uid.Value.GetValue("name"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassCategoriesGet{publicstaticvoidExecuteSearch(){// -- your search query --stringid="87a44aaeb6be5c63";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="categories/{id}";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddUrlSegment("id",id);// Perform the search and obtain resultsvardata=client.Execute(req).Content;varcategory=JsonConvert.DeserializeObject<dynamic>(data);// Print nameConsole.WriteLine(category["name"]);}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleCategoriesGetPublicSubExecuteSearch()' -- your search query --DimidAsString="87a44aaeb6be5c63"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="categories/{id}"DimapiKeyAsString=CategoriesGet.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddUrlSegment("id",id)' Perform the search and obtain resultsDimdata=client.Execute(req).ContentDimcategory=JsonConvert.DeserializeObject(data)' Print nameConsole.WriteLine(category("name"))EndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
importjsonimporturlliburl="http://octopart.com/api/v3/categories/search"url+="?apikey=REPLACE_ME"args=[('q','semiconductors'),('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']:# print matched categoryprintresult['item']['name']
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/categories/search"url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"semiconductors",: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|# print matched categoryputsresult['item']['name']end
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassCategoriesSearch{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="semiconductors";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="categories/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 resultsvardata=client.Execute(req).Content;varsearch_response=JsonConvert.DeserializeObject<dynamic>(data);// Print the number of hitsConsole.WriteLine(search_response["hits"]);// Print resultsforeach(varresultinsearch_response["results"]){// Print matched categoryConsole.WriteLine(result["item"]["name"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleCategoriesSearchPublicSubExecuteSearch()' -- your search query --DimqueryAsString="semiconductors"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="categories/search"DimapiKeyAsString=CategoriesSearch.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 resultsDimdata=client.Execute(req).ContentDimsearch_response=JsonConvert.DeserializeObject(data)' Print the number of hitsConsole.WriteLine(search_response("hits"))' Print resultsForEachresultInsearch_response("results")' Print matched categoryConsole.WriteLine(result("item")("name"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
These are some common HTTP responses and their likely causes:
200 OK: The request was completed successfuly
400 Bad Request: The request failed validation
This endpoint returns multiple categories simultaneously by primary key. The fetch key for each part is its 'uid'. Missing categories will also be missing from the response list.
Argument
Datatype
Default
uid[]
string
None
uid[]
The uid for an individual part. Append multiple url arguments to fetch multiple categories (up to 20).
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassCategoriesGetMulti{publicstaticvoidExecuteSearch(){// -- your search query --stringid1="3b27f62d0a3ae0e0";stringid2="9e07530daf1645c0";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="categories/get_multi";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("uid[]",id1).AddParameter("uid[]",id2);// Perform the search and obtain resultsvardata=client.Execute(req).Content;varserver_response=JsonConvert.DeserializeObject<dynamic>(data);// Print the category display namesforeach(varuidinserver_response){Console.WriteLine(uid.Value["name"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleCategoriesGetMultiPublicSubExecuteSearch()' -- your search query --Dimid1AsString="3b27f62d0a3ae0e0"Dimid2AsString="9e07530daf1645c0"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="categories/get_multi"DimapiKeyAsString=CategoriesGetMulti.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("uid[]",id1) _
.AddParameter("uid[]",id2)' Perform the search and obtain resultsDimdata=client.Execute(req).ContentDimserver_response=JsonConvert.DeserializeObject(data)' Print the category display namesForEachuidInserver_responseConsole.WriteLine(uid.Value.GetValue("name"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassPartsGet{publicstaticvoidExecuteSearch(){// -- your search query --stringid="103cdb613d20cffb";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/{id}";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddUrlSegment("id",id);// Perform the search and obtain resultsvardata=client.Execute(req).Content;varresponse=JsonConvert.DeserializeObject<dynamic>(data);// Print brand, mpnConsole.WriteLine(response["brand"]["name"]);Console.WriteLine(response["mpn"]);// Print offersforeach(varofferinresponse["offers"]){Console.WriteLine(offer["seller"]["name"]);Console.WriteLine(offer["sku"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
These are some common HTTP responses and their likely causes:
200 OK: Part was fetched successfuly
404 Not Found: The part does not exist
This method returns parts matched by MPN/SKU filter. It also accepts brand and seller filters as well. This is the ideal method to match a list of parts (e.g. a BOM) to the Octopart parts database.
Argument
Datatype
Default
queries
string
"[]"
exact_only
boolean
false
queries
JSON encoded list of PartsMatchQuery objects. Maximum value of 'limit' argument is 20, and maximum 'start' + 'limit' is 100.
exact_only
If specified, match non-alphanumeric characters in MPNs and SKUs
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/match"url+="?apikey=REPLACE_ME"queries=[{:mpn=>"SN74S74N",:reference=>"line1"},{:sku=>"67K1122",:reference=>"line2"},{:mpn_or_sku=>"SN74S74N",:reference=>"line3"},{:brand=>"Texas Instruments",:mpn=>"SN74S74N",:reference=>"line4"}]url+="&queries="+URI.encode(JSON.generate(queries))resp=Net::HTTP.get_response(URI.parse(url))server_response=JSON.parse(resp.body)# print request time (in milliseconds)putsserver_response['msec']# print mpn'sserver_response['results'].eachdo|result|puts"Reference: "+result['reference']result['items'].eachdo|part|putspart['mpn']endend
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;usingSystem.Collections.Generic;usingSystem.Web.Script.Serialization;publicstaticclassPartsMatch{publicstaticvoidExecuteSearch(){// -- your search query --varquery=newList<dynamic>(){newDictionary<string,string>(){{"mpn","SN74S74N"},{"reference","line1"}},newDictionary<string,string>(){{"sku","67K1122"},{"reference","line2"}},newDictionary<string,string>(){{"mpn_or_sku","SN74S74N"},{"reference","line3"}},newDictionary<string,string>(){{"brand","Texas Instruments"},{"mpn","SN74S74N"},{"reference","line4"}}};stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/match";stringapiKey=APIKEY;// Create the search requeststringqueryString=(newJavaScriptSerializer()).Serialize(query);varclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("queries",queryString);// Perform the search and obtain resultsvardata=client.Execute(req).Content;varresponse=JsonConvert.DeserializeObject<dynamic>(data);// Print request time (in milliseconds)Console.WriteLine(response["msec"]);// Print mpn'sforeach(varresultinresponse["results"]){Console.WriteLine("Reference: "+result["reference"]);foreach(variteminresult["items"]){Console.WriteLine(item["mpn"]);}}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
These are some common HTTP responses and their likely causes:
200 OK: Request was completed successfuly
400 Bad Request: JSON parsing error
This method allows searching across parts by keyword. or technical specs. This is the ideal method to use to filter parts by manufacturer or to perform a parametric search.
Argument
Datatype
Default
q
string
""
start
integer
0
limit
integer
10
sortby
string
"score desc"
filter[fields][<fieldname>][]
string
""
filter[queries][]
string
""
facet[fields][<fieldname>][include]
boolean
false
facet[fields][<fieldname>][exclude_filter]
boolean
false
facet[fields][<fieldname>][start]
integer
0
facet[fields][<fieldname>][limit]
integer
10
facet[queries][]
string
""
stats[<fieldname>][include]
boolean
false
stats[<fieldname>][exclude_filter]
boolean
false
spec_drilldown[include]
boolean
false
spec_drilldown[exclude_filter]
boolean
false
spec_drilldown[limit]
integer
10
q
Full-text query string
start
Ordinal position of first result. First position is 0. Maximum is 1000.
limit
Maximum number of results to return. Default is 10. Maximum is 100.
sortby
Comma separated list of (fieldname, fieldorder) pairs
filter[fields][<fieldname>][]
Attribute (fieldname/fieldvalue) pair to filter results on
filter[queries][]
Arbitrary filter query string
facet[fields][<fieldname>][include]
If specified, perform faceting on given <fieldname>
facet[fields][<fieldname>][exclude_filter]
If specified, remove <fieldname> from filters when calculating facets for <fieldname>
facet[fields][<fieldname>][start]
Ordinal position of first facet to return. First position is 0. Maximum is 1000.
facet[fields][<fieldname>][limit]
Number of facets to return. Default is 10. Maximum is 100.
facet[queries][]
Arbitrary filter query string to facet on
stats[<fieldname>][include]
If specified, calculate statistics for <fieldname
stats[<fieldname>][exclude_filter]
If specified, remove <fieldname> from filters when calculating statistics for <fieldname>
spec_drilldown[include]
If specified, perform drilldown
spec_drilldown[exclude_filter]
If specified, remove <fieldname> from filters when calculating statistics for <fieldname>
spec_drilldown[limit]
Number of facets to return for each field. Default is 10. Maximum is 100.
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;publicstaticclassPartsSearch{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 resultsvardata=client.Execute(req).Content;varsearch_response=JsonConvert.DeserializeObject<dynamic>(data);// Print number of hitsConsole.WriteLine(search_response["hits"]);// Print resultsforeach(varresultinsearch_response["results"]){varpart=result["item"];// Print matched partConsole.WriteLine(part["brand"]["name"]+" - "+part["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModulePartsSearchPublicSubExecuteSearch()' -- your search query --DimqueryAsString="solid state relay"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="parts/search"DimapiKeyAsString=PartsSearch.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 resultsDimdata=client.Execute(req).ContentDimsearch_response=JsonConvert.DeserializeObject(data)' Print number of hitsConsole.WriteLine(search_response("hits"))' Print resultsForEachresultInsearch_response("results")Dimpart=result("item")' Print matched partConsole.WriteLine(part("brand")("name")&" - "&part("mpn"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
These are some common HTTP responses and their likely causes:
200 OK: The request was completed successfuly
400 Bad Request: The request failed validation
This endpoint returns multiple parts simultaneously by primary key. The fetch key for each part is its 'uid'. Missing parts will also be missing from the response list.
Argument
Datatype
Default
uid[]
string
None
uid[]
The uid for an individual part. Append multiple url arguments to fetch multiple parts (up to 20).
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/parts/get_multi"url+="?apikey=REPLACE_ME"uids=["103cdb613d20cffb","2a68e3620f0cf5af"]urlargs=[]uids.eachdo|uid|urlargs.push("uid[]="+uid)endurl+="&"+urlargs.join("&")resp=Net::HTTP.get_response(URI.parse(url))server_response=JSON.parse(resp.body)# print brands and mpn'sserver_response.keys.eachdo|key|putsserver_response[key]['brand']['name']putsserver_response[key]['mpn']end
<script src="http://code.jquery.com/jquery-1.11.0.js"></script><script>varurl="http://octopart.com/api/v3/parts/get_multi";url+="?apikey=REPLACE_ME";url+="&callback=?";varargs={uid:["103cdb613d20cffb","2a68e3620f0cf5af"]};$.getJSON(url,args,function(parts){// iterate through parts$.each(parts,function(i,part){console.log(part['brand']['name']);console.log(part['mpn']);});});</script>
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassPartsGetMulti{publicstaticvoidExecuteSearch(){// -- your search query --stringid1="103cdb613d20cffb";stringid2="2a68e3620f0cf5af";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="parts/get_multi";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("uid[]",id1).AddParameter("uid[]",id2);// Perform the search and obtain resultsvardata=client.Execute(req).Content;varserver_response=JsonConvert.DeserializeObject<dynamic>(data);// Print brands, mpn'sforeach(varpartinserver_response){Console.WriteLine(part.Value["brand"]["name"]);Console.WriteLine(part.Value["mpn"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassSellersGet{publicstaticvoidExecuteSearch(){// -- your search query --stringid="d294179ef2900153";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="sellers/{id}";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddUrlSegment("id",id);// Perform the search and obtain resultsvardata=client.Execute(req).Content;varseller=JsonConvert.DeserializeObject<dynamic>(data);// Print nameConsole.WriteLine(seller["name"]);}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleSellersGetPublicSubExecuteSearch()' -- your search query --DimidAsString="d294179ef2900153"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="sellers/{id}"DimapiKeyAsString=SellersGet.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddUrlSegment("id",id)' Perform the search and obtain resultsDimdata=client.Execute(req).ContentDimseller=JsonConvert.DeserializeObject(data)' Print nameConsole.WriteLine(seller("name"))EndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
These are some common HTTP responses and their likely causes:
200 OK: Seller was fetched successfuly
404 Not Found: The seller does not exist
This method allows searching across sellers by keyword. This is the ideal method to use to go from a seller alias or keyword to a Octopart seller instance
Argument
Datatype
Default
q
string
""
start
integer
0
limit
integer
10
sortby
string
"score desc"
filter[fields][<fieldname>][]
string
""
filter[queries][]
string
""
facet[fields][<fieldname>][include]
boolean
false
facet[fields][<fieldname>][exclude_filter]
boolean
false
facet[fields][<fieldname>][start]
integer
0
facet[fields][<fieldname>][limit]
integer
10
facet[queries][]
string
""
stats[<fieldname>][include]
boolean
false
stats[<fieldname>][exclude_filter]
boolean
false
q
Full-text query string
start
Ordinal position of first result. First position is 0. Maximum is 1000.
limit
Maximum number of results to return. Default is 10. Maximum is 100.
sortby
Comma separated list of (fieldname, fieldorder) pairs
filter[fields][<fieldname>][]
Attribute (fieldname/fieldvalue) pair to filter results on
filter[queries][]
Arbitrary filter query string
facet[fields][<fieldname>][include]
If specified, perform faceting on given <fieldname>
facet[fields][<fieldname>][exclude_filter]
If specified, remove <fieldname> from filters when calculating facets for <fieldname>
facet[fields][<fieldname>][start]
Ordinal position of first facet to return. First position is 0. Maximum is 1000.
facet[fields][<fieldname>][limit]
Number of facets to return. Default is 10. Maximum is 100.
facet[queries][]
Arbitrary filter query string to facet on
stats[<fieldname>][include]
If specified, calculate statistics for <fieldname
stats[<fieldname>][exclude_filter]
If specified, remove <fieldname> from filters when calculating statistics for <fieldname>
importjsonimporturlliburl='http://octopart.com/api/v3/sellers/search'url+='?apikey=REPLACE_ME'args=[('q','newark'),('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']:# print matched sellerprintresult['item']['name']
require'rubygems'require'json'require'net/http'url="http://octopart.com/api/v3/sellers/search"url+="?apikey=REPLACE_ME"defto_query(hsh)hsh.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join("&")endparams={:q=>"newark",: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|# print matched sellerputsresult['item']['name']end
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassSellersSearch{publicstaticvoidExecuteSearch(){// -- your search query --stringquery="newark";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="sellers/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 resultsvardata=client.Execute(req).Content;varsearch_response=JsonConvert.DeserializeObject<dynamic>(data);// Print the number of hitsConsole.WriteLine(search_response["hits"]);// Print resultsforeach(varresultinsearch_response["results"]){// Print matched sellerConsole.WriteLine(result["item"]["name"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleSellersSearchPublicSubExecuteSearch()' -- your search query --DimqueryAsString="newark"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="sellers/search"DimapiKeyAsString=SellersSearch.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 resultsDimdata=client.Execute(req).ContentDimsearch_response=JsonConvert.DeserializeObject(data)' Print the number of hitsConsole.WriteLine(search_response("hits"))' Print resultsForEachresultInsearch_response("results")' Print matched sellerConsole.WriteLine(result("item")("name"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
namespaceOctopartApi{usingNewtonsoft.Json;usingRestSharp;usingSystem;publicstaticclassSellersGetMulti{publicstaticvoidExecuteSearch(){// -- your search query --stringid1="d294179ef2900153";stringid2="2c3be9310496fffc";stringoctopartUrlBase="http://octopart.com/api/v3";stringoctopartUrlEndpoint="sellers/get_multi";stringapiKey=APIKEY;// Create the search requestvarclient=newRestClient(octopartUrlBase);varreq=newRestRequest(octopartUrlEndpoint,Method.GET).AddParameter("apikey",apiKey).AddParameter("uid[]",id1).AddParameter("uid[]",id2);// Perform the search and obtain resultsvardata=client.Execute(req).Content;varserver_response=JsonConvert.DeserializeObject<dynamic>(data);// Print the seller display namesforeach(varuidinserver_response){Console.WriteLine(uid.Value["name"]);}}// -- your API key -- (https://octopart.com/api/register)privateconststringAPIKEY="REPLACE_ME";}}
ImportsNewtonsoft.JsonImportsRestSharpImportsSystemPublicModuleSellersGetMultiPublicSubExecuteSearch()' -- your search query --Dimid1AsString="d294179ef2900153"Dimid2AsString="2c3be9310496fffc"DimoctopartUrlBaseAsString="http://octopart.com/api/v3"DimoctopartUrlEndpointAsString="sellers/get_multi"DimapiKeyAsString=SellersGetMulti.APIKEY' Create the search requestDimclient=NewRestClient(octopartUrlBase)Dimreq=NewRestRequest(octopartUrlEndpoint,Method.GET) _
.AddParameter("apikey",apiKey) _
.AddParameter("uid[]",id1) _
.AddParameter("uid[]",id2)' Perform the search and obtain resultsDimdata=client.Execute(req).ContentDimserver_response=JsonConvert.DeserializeObject(data)' Print the seller display namesForEachuidInserver_responseConsole.WriteLine(uid.Value.GetValue("name"))NextEndSub' -- your API key -- (https:'octopart.com/api/register)PrivateConstAPIKEYAsString="REPLACE_ME"EndModule
These are some common HTTP responses and their likely causes:
200 OK: The request was completed successfuly
Include Directives
For performance reasons, some types of data are not included in API response objects by default (e.g. datasheets). To add missing data you can use the include url argument:
More generally, here are the rules for using the include directive:
The general strategy is to use url arguments of the form:
&include[]=<fieldname>
To include multiple fields you can chain together include directives:
&include[]=<fieldname1>&include[]=<fieldname2>
The following include directives can be used with the parts collection:
URL Argument
Description
include[]=short_description
Add short description to part objects
include[]=datasheets
Add datasheets to part objects
include[]=compliance_documents
Add compliance documents to part objects
include[]=descriptions
Add descriptions to part objects
include[]=imagesets
Add images to part objects
include[]=specs
Add technical specs to part objects
include[]=category_uids
Add category uids to part objects
include[]=external_links
Add external links to part objects
include[]=reference_designs
Add reference designs to part objects
include[]=cad_models
Add 3D models to part objects
Show/Hide Directives
Show/hide directives are url arguments that you can use to control the
size of API response objects by only requesting the fields you need. For
example, to only show MPNs and manufacturer brand names for each part
matched in a parts/match request:
For more fine-grained control over API response sizes you can use the slice url argument to perform slice operations on JSON arrays. For example, to only show the first five offers for each part matched in a parts/match request:
Octopart APIv3 and Nexart Legacy API REST search endpoint exposes advanced search functionality that can be used to implement useful search features such as parametric search. The following is reference documentation for the search endpoints. For a more narrative approach please read our Search Tutorial.
URL Arguments
The following are the URL arguments available to each search endpoint:
Argument
Datatype
Default
q
string
""
start
integer
0
limit
integer
10
sortby
string
"score desc"
filter[fields][<fieldname>][]
string
""
filter[queries][]
string
""
facet[fields][<fieldname>][include]
boolean
false
facet[fields][<fieldname>][exclude_filter]
boolean
false
facet[fields][<fieldname>][start]
integer
0
facet[fields][<fieldname>][limit]
integer
10
facet[queries][]
string
""
stats[<fieldname>][include]
boolean
false
stats[<fieldname>][exclude_filter]
boolean
false
q
Full-text query string
start
Ordinal position of first result. First position is 0. Maximum is 1000.
limit
Maximum number of results to return. Default is 10. Maximum is 100.
sortby
Comma separated list of (fieldname, fieldorder) pairs
filter[fields][<fieldname>][]
Attribute (fieldname/fieldvalue) pair to filter results on
filter[queries][]
Arbitrary filter query string
facet[fields][<fieldname>][include]
If specified, perform faceting on given <fieldname>
facet[fields][<fieldname>][exclude_filter]
If specified, remove <fieldname> from filters when calculating facets for <fieldname>
facet[fields][<fieldname>][start]
Ordinal position of first facet to return. First position is 0. Maximum is 1000.
facet[fields][<fieldname>][limit]
Number of facets to return. Default is 10. Maximum is 100.
facet[queries][]
Arbitrary filter query string to facet on
stats[<fieldname>][include]
If specified, calculate statistics for <fieldname
stats[<fieldname>][exclude_filter]
If specified, remove <fieldname> from filters when calculating statistics for <fieldname>
Fieldnames
Several of the 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 filter on parts sold by Newark you can use the offer.seller.name fieldname:
&filter[fields][offers.seller.name][]=Newark
Other examples of commonly fieldnames used in the parts/search endpoint are manufacturer brand names (brand.name) and technical specs (e.g. specs.capacitance.value).
For a more narrative overview of fieldnames please visit the Fieldnames Section of the Search Tutorial.
Search Filters
The simplest way to filter search results is to add (fieldname, fieldvalue) pairs using the filter[fields] url argument:
&filter[fields][<fieldname1>][]=<fieldvalue1>
Multple arguments for the same fieldname will be OR'd together:
For a narrative introduction to search filters please visit the Filtering Section of the Search Tutorial.
Full-text query syntax
The full-text query field (q) accepts the following operators:
Description
Full-text query syntax
Phrase Match
"keyword1 keyword2"
Negative Boolean Operator
-keyword1 keyword2
Multiple-letter wildcards
part*ber *art*umb* partnum*
Single-letter wildcards
part?umber ?artnum?er partnumb??
Please note that multiple-letter wildcards and single-letter wildcards are only applied against part number fields (see Notes: Part Number Filters).
For a narrative introduction to keyword search using full-text queries please visit the Keyword Search section of the Search Tutorial.
Filter query syntax
Filter queries can be made up of the following elements:
Description
Filter query syntax
Single Terms
fieldname:val
Multiple Terms
fieldname:(val1 val2)
Phrase Match
fieldname:"val1 val2"
Multiple-letter Wildcards
fieldname:val*
Single-letter Wildcards
fieldname:va?
Ranged Search (inclusive)
fieldname:[min_val TO max_val]
Ranged Search (exclusive)
fieldname:{min_val to max_val}
Ranged Search (unbounded)
fieldname:[min_val TO *]
Boolean Operators
query1 OR query2
Nested Queries
(query1 AND query2) OR (query3 AND query4)
For a narrative introduction to filter queries please visit the Filter Queries section of the Search Tutorial.
Reserved characters
To use any of the characters which function as operators without treating them as operators, you should escape them with a leading backslash.
For example, to search for an MPN that contains parentheses, like 123(456), write your query as mpn:123\(456\).
The reserved characters for filter queries are ( ) " * ? [ ] { } : \ plus whitespace.
Faceting
Facets give developers an easy way to implement guided search interfaces by allowing users to "preview" the filters that are available within a given result set. For example, you can narrow your part search to LEDs and then facet on "color" to see how many "Red", "Green", and "Yellow" LEDs match in the set.
Facet Fields
The simplest way to facet search results is by specifing a <fieldname> to facet on using the facet[fields] url argument:
To facet on a specific filter value you can use the facet[queries] url argument which accepts filters defined using the filter query syntax (see above):
For a guided overview of Octopart APIv3 and Nexart Legacy API REST search interface please see the Search Tutorial.
Universal URL Arguments
Argument
Datatype
Default
callback
string
none
pretty_print
boolean
false
suppress_status_codes
boolean
false
callback
The name of the callback function to wrap the result.
pretty_print
Format the result in a more human-readable way. Default is false.
suppress_status_codes
Return all responses with HTTP 200 OK status code - even errors.
Notes
Asset.metadata
The metadata attribute attached to Asset instances is a JSON object whose schema depends on the value of mimetype. These are the following supported values of mimetype along with their and the associated metadata object:
The subtypes attribute attached to ComplianceDocument instances contains a JSON array of classifications for the document. These are the possible values:
"rohs_statement"
"reach_statement"
"materials_sheet"
"conflict_mineral_statement"
Datasheet.mimetype
The mimetype attribute attached to Datasheet instances can take the following values. If you are only interested in PDF direct download links, be sure to filter by the appropriate mimetype.
"application/pdf": PDF files
"text/html": link to datasheet section of manufacturer product page
Part.specs
The specs attribute attached to Part instances is a JSON object mapping attribute keys (e.g. "voltage_rating_dc") to SpecValue instances.
It's important to note that all value properties of SpecValue objects are JSON arrays. The reason for this is to accomodate multi-valued attributes such as power supplies with multiple output voltages:
Note that prices are decimal types with a precision of 5 and are encoded in JSON as strings. In order to perform a mathematical operation on a price you will have to convert it to a native numeric type in your language.
PartOffer.in_stock_quantity
The in_stock_quantity attribute attached to PartOffer objects indicates the number of parts the seller has in stock ready for shipment. Negative numbers are used to indicate the following conditions:
-1: Non-stocked (seller is not currently stocking the product)
-2: Yes (seller has the product in stock but has not reported the quantity)
-3: Unknown (seller has not indicated whether or not they have parts in stock)
-4: RFQ
PartOffer.order_multiple
The order_multiple attribute attached to PartOffer objects indicates the quantity multiple of the offer. For example, if order_multiple is 100, then the seller will only sell product in quantities of 100, 200, 300, 400, etc.
PartOffer.packaging
The packaging attribute attached to PartOffer objects indicates the physical packaging that the product is offered in. These are the most common values for the packaging attribute:
Value
Description
"Ammo"
Continuous strip of cut tape
"Ammo Pack"
"Bag"
"Box"
"Bulk"
Individual components packaged in a bag
"Cut Tape"
On a tape cut off from a reel
"Custom Reel"
Custom quantity tape in reel format
"Kit
"Magazine"
"Rail"
"Tape & Box"
"Tape & Reel"
On a tape wound around a reel directly from manufacturer
"Tape & Reel (7 in.)"
Standard reel with 7 inch diameter
"Tape & Reel (13 in.)"
Standard reel with 13 inch diameter
"Tray"
Physically separated on a tray
"Tube"
Line of components in plastic tube
"Spool"
"Strip"
"Waffle"
PartOffer.is_authorized
The is_authorized attribute attached to PartOffer objects indicates whether or not the seller is authorized by the manufacturer to sell the product.
If the manufacturer has provided us with a list of authorized sellers we use that list exlusively to indicate the authorized status of the offer. Otherwise, we use the seller's ECIA (Electronic Components Industry Association) membership to indicate whether or not the offer is authorized.
If a seller is not a member of the ECIA they must provide us with evidence of authorization in order for their offers to be listed as authorized.
Part Number Filters
To assist developers trying to do partial part number matches, the mpn, sku, and mpn_or_sku filter arguments to the parts/match endpoint accepts wildcards.
There are two types of wildcards, asterisks ('*') and question marks ('?'). Asterisks will match any number of characters while questions marks will match exactly one character. To escape an asterisk or a question mark in a part number you can use the backslash character (e.g. "\*").
Wildcards can be used anywhere within as well as before and after a part number. There is no limit to the number of wildcards that can be used but there must be at least three characters present in the query e.g. ("S*7*N").