To get the information you need from your supply query you can use attributes that are listed here on Octopart. You can either sort or filter your query results by these attributes.
Not all parts have every attribute associated with them. Note that you cannot filter by attribute existence.
You can also use these keys to filter:
"distributor_id:<insert distributor id>" "manufacturer_id: <insert manufacturer id>" "category_id: <insert category id>" "cad_models:["symbol_footprint_3d"]" "cad_models:["symbol_footprint"]"
and these keys to sort:
"" "median_price_1000" "num_authsuppliers" "avg_price" "mpn" "manufacturer.displayname"
Sorting:
In the example below using a supSearch the "sort" function is used. You can also use the "sortDIr" function to sort in the order you want (asc/desc).
query SupSearch{ supSearch(sort: "maxoutputvoltage", sortDir: desc) { hits results{ ....
Filtering:
Below is an example using filtering. In this example, there are two filters divided by a comma. The first filter looks for exact matches for the manufacturer_id variable. If a part matches any of the names or IDs listed it will come up in the query. The second filter looks for parts with between 8 and 16 "numberofpins" inclusive. The syntax is:
- numberofpins: ["(8__16)"] == numberofpins in range 8 to 16 inclusive
- numberofpins: ["(__8)"] == numberofpins less than or equal to 8
- numberofpins: ["(16__)"] == numberofpins greater than or equal to 16
Note: it's a double underscore between the numbers.
query{ supSearch( filters: { manufacturer_id: ["Infineon"], numberofpins: ["(8__16)"] }){ hits results{ ....
Here is a full example to copy and try. This query searches for any parts with manufacturer ID "Infineon", with any number of pins between 8 to 16, sorted by number of pins, with a pagination start page of 2.
query filter_test{ supSearch( filters: {manufacturer_id: ["Infineon"], numberofpins:["(8__16)"]} sort: "numberofpins" start: 2 ) { hits results { part { mpn manufacturer { name id } specs{ attribute { shortname } displayValue } } } } }
Note: filtering by sellers will return all offers for parts that are sold by that seller, not just the offers for that seller. This is true even with filters such as requireAuthorizedSellers, which will only return parts with authorized sellers.
Filtering Behaviour
There is some behavior worth noting when filtering. Our API supports lists of individual values as seen in example 1 or a single range, seen in example 2.
Whilst you are able to carry out OR behaviour in a filter, there are caveats when it comes to working with ranges, as seen in examples 3 and 4.
Example 1:
This will return the number of parts that have 8 pins, or that have 16 pins.
numberofpins: ["8", "16"]
numberofpins: ["(8__16)"]
These will return 0 results. In the case where you want to filter for example 8 to 16 pin OR 24 pin components, we would recommend a catch-all on components with 8 to 24 pins, before users can apply post-filtering on the results of the query.
numberofpins: ["(8__16)", "24"] numberofpins:["(__16)", "24"]
Example 4:
This will return components with 16 pins only.
numberofpins: ["(8__16)", "(16__24)"]
Units
Filtering also works with SI Units, following the OR behaviour as above.
capacitance: ["(1.5E-12__1.6E-12)"]
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article