List commerce categories and products
Use the externalItems GraphQL query get a list of Magento Commerce categories and products.
Query syntax
The following code illustrates required format for the GraphQL request, followed by a description of the input values:
{
externalItems([namespace: "NAMESPACE"]
filter: {
[context: {
[namespace: "NAMESPACE",]
id: "IDENTIFIER",
type: "TYPE"
},]
[type: "TYPE"]
},
# Pagination
[first: NUM_ITEMS,]
[after: "[cursor]"]
) {
edges {
node {
... on TYPE {
RESPONSE_FIELD_1
RESPONSE_FIELD_2
RESPONSE_FIELD_n
}
}
}
}
}
Fields and inputs
- namespace
- Sets the overall query scope, where NAMESPACE is the namespace name for query.
- filter
- Defines the values you want to match in the query results, and can include one or more of the following:
- # Pagination
-
The following two parameters work together for data pagination:
- first
- The value for NUM_ITEMS sets the first number of matching items to retrieve.
- after
- For all requests following the initial one, the value for CURSOR defines the starting point of the query.
- edges
- A generic GraphQL term for the connections between nodes, which the externalItems query traverses to get to individual nodes.
Example request and response
The first sample code block illustrates a request to retrieve all the products under a specified category. The second code block illustrates the corresponding response with the requested data for each Magento Commerce product.
| Request | Response |
|---|---|
| |