Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
feat: get lowest offer listings for sku
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed May 27, 2020
1 parent 5543a91 commit 0b146d4
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/sections/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,28 @@ const GetCompetitivePricingForASINResponse = Codec.interface({
GetCompetitivePricingForASINResponse: GetCompetitivePricingForASINResult,
})

type ItemCondition = 'Any' | 'New' | 'Used' | 'Collectible' | 'Refurbished' | 'Club'

interface GetLowestOfferListingsForSkuParameters {
SellerSKUList: string[]
MarketplaceId: string
ItemCondition?: ItemCondition
}

const GetLowestOfferListingsForSKUResult = ensureArray(
'GetLowestOfferListingsForSKUResult',
Codec.interface({
AllOfferListingsConsidered: boolean,
Product,
}),
)

const GetLowestOfferListingsForSKUResponse = Codec.interface({
GetLowestOfferListingsForSKUResponse: GetLowestOfferListingsForSKUResult,
})

type GetLowestOfferListingsForSKUResult = GetInterface<typeof GetLowestOfferListingsForSKUResult>

export class Products {
constructor(private httpClient: HttpClient) {}

Expand Down Expand Up @@ -370,4 +392,26 @@ export class Products {
},
})
}

async getLowestOfferListingsForSku(
parameters: GetLowestOfferListingsForSkuParameters,
): Promise<[GetLowestOfferListingsForSKUResult, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Products,
version: PRODUCTS_API_VERSION,
action: 'GetLowestOfferListingsForSKU',
parameters: {
MarketplaceId: parameters.MarketplaceId,
'SellerSKUList.SellerSKU': parameters.SellerSKUList,
ItemCondition: parameters.ItemCondition,
},
})

return GetLowestOfferListingsForSKUResponse.decode(response).caseOf({
Right: (x) => [x.GetLowestOfferListingsForSKUResponse, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}
}
123 changes: 122 additions & 1 deletion test/unit/__snapshots__/products.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`products getCompetitivePricingForASIN returns product and competitive prices when response is valid 1`] = `
exports[`products getCompetitivePricingForAsin returns product and competitive prices when response is valid 1`] = `
Array [
Array [
Object {
Expand Down Expand Up @@ -153,6 +153,127 @@ Array [
]
`;

exports[`products getLowestOfferListingsForSku returns product and lowest offer listings when response is valid 1`] = `
Array [
Array [
Object {
"AllOfferListingsConsidered": false,
"Product": Object {
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": 1933890517,
"MarketplaceId": "ATVPDKIKX0DER",
},
"SKUIdentifier": Object {
"MarketplaceId": "ATVPDKIKX0DER",
"SellerId": "A1IMEXAMPLEWRC",
"SellerSKU": "SKU2468",
},
},
"LowestOfferListings": Object {
"LowestOfferListing": Array [
Object {
"MultipleOffersAtLowestPrice": "True",
"NumberOfOfferListingsConsidered": 3,
"Price": Object {
"LandedPrice": Object {
"Amount": 28.68,
"CurrencyCode": "USD",
},
"ListingPrice": Object {
"Amount": 24.69,
"CurrencyCode": "USD",
},
"Shipping": Object {
"Amount": 3.99,
"CurrencyCode": "USD",
},
},
"Qualifiers": Object {
"FulfillmentChannel": "Merchant",
"ItemCondition": "Used",
"ItemSubcondition": "Acceptable",
"SellerPositiveFeedbackRating": "95-97%",
"ShippingTime": Object {
"Max": "0-2 days",
},
"ShipsDomestically": "True",
},
"SellerFeedbackCount": 8900,
},
Object {
"MultipleOffersAtLowestPrice": "False",
"NumberOfOfferListingsConsidered": 1,
"Price": Object {
"LandedPrice": Object {
"Amount": 30.5,
"CurrencyCode": "USD",
},
"ListingPrice": Object {
"Amount": 30.5,
"CurrencyCode": "USD",
},
"Shipping": Object {
"Amount": 0,
"CurrencyCode": "USD",
},
},
"Qualifiers": Object {
"FulfillmentChannel": "Amazon",
"ItemCondition": "Used",
"ItemSubcondition": "Good",
"SellerPositiveFeedbackRating": "90-94%",
"ShippingTime": Object {
"Max": "0-2 days",
},
"ShipsDomestically": "True",
},
"SellerFeedbackCount": 1569694,
},
Object {
"MultipleOffersAtLowestPrice": "False",
"NumberOfOfferListingsConsidered": 3,
"Price": Object {
"LandedPrice": Object {
"Amount": 30.99,
"CurrencyCode": "USD",
},
"ListingPrice": Object {
"Amount": 27,
"CurrencyCode": "USD",
},
"Shipping": Object {
"Amount": 3.99,
"CurrencyCode": "USD",
},
},
"Qualifiers": Object {
"FulfillmentChannel": "Merchant",
"ItemCondition": "Used",
"ItemSubcondition": "Good",
"SellerPositiveFeedbackRating": "95-97%",
"ShippingTime": Object {
"Max": "0-2 days",
},
"ShipsDomestically": "True",
},
"SellerFeedbackCount": 7732,
},
],
},
},
},
],
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": "2020-04-06T10:22:23.582Z",
"requestId": "0",
"timestamp": "2020-05-06T09:22:23.582Z",
},
]
`;

exports[`products getMatchingProduct returns a matching product when the response is valid 1`] = `
Array [
Array [
Expand Down

0 comments on commit 0b146d4

Please sign in to comment.