How to get product history
Product price history
Product price history returns the price changes x
days from the last price change.
It is available in the history
field on the Product
and ProductVariant
types, ie. product.history
. See example below.
In order to get product price history on the product endpoint you'd need to provide an articleNumber, id or barcode to the query. Days argument is optional, and defaults to the latest 30 days.
NB: Carries a performance cost, as asking for this will result in a separate API call in the backend.
Example scenario:
- Latest price change: 6 days ago, price reduced to 50 SEK.
- Regular price: Changed 30 days ago to 100 SEK.
- Previous promotion: 4 days before that (34 days ago), price reduced to 10 SEK.
- Price set to 100 SEK: 50 days ago.
Calculated Prices based on scenario [price, -days from today]:
- [50 SEK, -6d] - Latest price change.
- [100 SEK, -30d] - Regular price changed.
- [10 SEK, -34d] - Previous promotional price.
- [100 SEK, -36d] - Adjusted price 36 days ago (originally set 50 days ago).
product history variablesproduct price queryproduct history output
{
"articleNumber": "6Y6CD7L15Y-8566",
"days": 5
}
query GetProductWithHistoryExample($articleNumber: String!, $days: Int!) {
product(articleNumber: $articleNumber) {
id
history(days: $days) {
...ProductHistory
}
variants {
values {
history {
...ProductVariantHistory
}
}
}
}
}
fragment Price on Price {
incVat
exVat
vat
}
fragment ProductHistory on ProductHistory {
previousPrice {
timestamp
price {
...Price
}
}
}
fragment ProductVariantHistory on ProductVariantHistory {
previousPrice {
timestamp
price {
...Price
}
}
}
{
"data": {
"product": {
"id": 134,
"history": {
"previousPrice": [
{
"timestamp": "2022-06-30T00:00:00+02:00",
"price": {
"incVat": 5458.75,
"exVat": 4367,
"vat": 1091.75
}
}
]
},
"variants": {
"values": [
{
"history": {
"previousPrice": [
{
"timestamp": "2022-06-30T00:00:00+02:00",
"price": {
"incVat": 421.25,
"exVat": 337,
"vat": 84.25
}
},
{
"timestamp": "2022-06-29T00:00:00+02:00",
"price": {
"incVat": 592.5,
"exVat": 474,
"vat": 118.5
}
}
]
}
}
]
}
}
}
}