How to query products
7 minute read
What you’ll learn
- The simplified product data model
- The use-case for querying products
- Factors impacting product state
- The different queries you can use to work with products
- Alternatives to querying products
What are Adverts?
In short, “Adverts” in Marketplacer are Products - it’s that simple!
So whenever we refer to one of the “advert queries” we are simply talking about queries that allow us to return Products. In this article (and elsewhere on the docs site) we may use the terms Product and Advert interchangeably.
Advert will typically be used in relation to technical and API discussions (as that is the term used in these domains), whereas business and process focused conversations will most usually use the term Product.
The Advert Data Model
For the purposes of this conversation, (querying products), the key relationships of an Advert are shown below:
The key takeaways from this model are:
- Adverts belong to a Seller
- Sellers products are unique to them (the Marketplacer product ID will be unique)
- Adverts must have a least 1 variant, but can have more
- Variants have fields such as:
- SKU
- Barcode
- Inventory position (called
countOnHand
in the Marketplacer APIs)
- It is ultimately the Variant that gets purchased by the customer (not the Advert)
You can explore the Marketplacer object model in more depth by taking a look at GraphQL Voyager
Advert State
Before discussing the advert queries, it’s important to cover the following fields on the Advert object as their values can impact both the “state” of the advert, and therefore the queries can be used to retrieve those adverts:
Field Name | Type | Description |
---|---|---|
published | boolean | Describes the intent of the Seller. A Product may be correctly defined and have inventory (at least 1 variant has a positive value for countOnHand ), however the Seller may choose not to Sell this item, e.g. it has been withdrawn because a newer version is available. In this example published would be false .Setting the value of published to false has a cascading effect on the values of the remaining fields outlined in this section, i.e. they too will have the value of false . |
displayable | boolean | System defined value, (unlike published which is set by the Seller), this value represents whether it is possible to Sell this Product in its current state. The value of displayable is determined by Marketplacer and is based on a number of criteria, including but not limited to:1. whether there is positive inventory ( countOnHand ) for at least 1 variant,2. whether all mandatory attributes are configured, 3. if product vetting is enabled, that the vetting process has been successfully completed, 4. whether published is true |
online | boolean | This state is determined by the status of the Seller of the Advert. I.e. if the Seller has been taken offline by the Operator, then the value of online will be false . |
As you will appreciate, the values for these fields can have a number of different combinations, impacting the overall “state” of the Advert. A summary of this is provided below:
Published | Displayable | Online | Description | “State” |
---|---|---|---|---|
true | true | true | Advert is available to sell. The seller has the intent to sell (published is true ), the advert has been successfully constructed, with inventory (displayable is true ), and the Seller account is online (online is true ) | Online / Published |
true | false | false | Advert is not available to sell. While the Seller has the intent to sell (published is true ), for some other reason the advert cannot be displayed, (displayable is false ), e.g. vetting is required. In this scenario the value of online is also impacted by the value of displayable | Offline / Unpublished |
true | true | false | Advert is not available to sell. While the Seller has the intent to sell (published is true ), and the advert is technically valid (displayable is true ), the Operator has taken the Seller offline. | Offline / Unpublished |
false | false | false | Advert is not available to sell. The Seller does not have the intent to sell this item (published is false ). The value of published also impacts the values of displayable and online | Offline / Unpublished |
To summarize the above table, only when all 3 fields are true, can the Advert be said to be available for purchase. Adverts in this “state” are usually referred to as either online or published.
For the remainder of this article we’ll use the terms Published and Unpublished.
Deleted Adverts
In addition to Adverts being published / unpublished, Adverts can of course be deleted. This condition is worth bearing in mind as we move into our discussion on the Advert queries.Adverts are initially “soft-deleted” from Marketplacer, meaning that they still exist in the DB for retrieval. After 30 Days adverts are then “hard-deleted”, meaning that they can no longer be queried.
The Advert Queries
There are 3 Advert queries that can be employed via the Operator API, they each have different characteristics which we will discuss in each section.
advertsWhere
- Object Types Returned:
- Advert States Returned:
[x] Published
[x] Unpublished
[x] Deleted (When executed as an Operator)
advertsWhere
is a good candidate query when you need to return products based on some filter criteria. This query can also return Published, Unpublished and Deleted Adverts. It should be noted that if no filter criteria is supplied to advertsWhere
it will return an empty set. An example query is provided below:
query {
advertsWhere(retailerIds: ["U2VsbGVyLTE2NQ=="])
{
nodes {
id
legacyId
title
published
online
displayable
variants {
nodes {
id
label
buyable
published
displayable
countOnHand
}
}
}
}
}
The
advertsWhere
query returns all Adverts (irrespective of state) asAdvert
objects. While this allows you to distinguish Published Adverts (all 3 status fields aretrue
), you cannot distinguish between Unpublished and Deleted Adverts using this query.
allAdverts
- Object Types Returned:
- Advert States Returned:
[x] Published
[x] Unpublished
[x] Deleted
allAdverts
is another potential choice when you want to return Published, Unpublished and Deleted adverts, however it has reduced set of filter criteria:
updatedSince
: Last time the Adverts were updatedvetted
: whether the Advert has been vettedrequiresVetting
: whether the Advert needs to go through the vetting process
In another difference with advertsWhere
, instead of returning an Advert
object representing Published, Unpublished and Deleted Adverts, allAdverts
returns concrete types representing the different states that an Advert can have:
Advert
- representing Published AdvertsUnpublishedAdverts
- representing Unpublished AdvertsDeletedAdvert
- representing Deleted Adverts
An example query is provided below:
query {
allAdverts(
first: 1000,
updatedSince: "2023-05-29") {
nodes {
__typename
... on Advert {
legacyId
updatedAt
title
seller {
businessName
}
}
... on UnpublishedAdvert {
legacyId
updatedAt
details {
title
seller {
businessName
}
}
}
... on DeletedAdvert {
legacyId
id
updatedAt
}
}
}
}
Unpublished and Deleted Data
To access the product detail of an Unpublished
Advert you will need to query the details
field.
Other than “ID” type information, the DeletedAdvert
type does not allow you to query detailed product data, please refer to the definition for DeletedAdvert
in the reference docs.
advertSearch
Object Types Returned:
Advert States Returned:
[x] Published
[ ] Unpublished
[ ] DeletedThe primary use-case of
advertSearch
to be called directly by a frontend eCommerce web application, in providing Product Search functionality directly to end users. It was not designed for system to system integrations.advertSearch
has the following characteristics:- Optimized for User Interactivity, e.g. someone performing a Product Search
- Returns only Published products (you would not want to return products directly to the user that could not be purchased)
- Has a large set of filter criteria, to support interactive product search
An example query is provided below:
query {
advertSearch(attributes:
{
keywordQuery: "shoes"
brandIds: ["QnJhbmQtNA=="]
}) {
adverts(first: 500) {
totalCount
nodes {
id
featureOptionValues {
nodes {
id
displayName
optionType {
category
}
}
}
productDetails {
key
value
}
variants {
nodes {
administrativeBodyWarning
}
}
}
}
}
}
Alternatives to Querying
In terms of moving Product data from Marketplacer into your domain you can use Webhooks instead. In contrast to an API based approach, where the integration “pulls” data at regular intervals, Webhooks push product (and other types of data) to the integration any time Create, Update or Delete events occur on Products. This allows for the near realtime movement of Product data to your integration.
- You can read more about Marketplacer webhooks here.