1.4.0 • Published 8 years ago

jj-npm-ocapi v1.4.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

jj-npm-ocapi

Simple product info retrieval via OCAPI

Installation

For Node / Browserify

$ npm install jj-npm-ocapi

API

getInfo (clientID, language, styles, wantImages: false, wantPrices: false, wantLinks: false)

Returns a promise. When resolved, it's data will consist of an object containing the information parsed from an OCAPI request, modeled as in the example below.

  • clientID (String) OCAPI public key for the chosen instance, with appropriate access to /shop/products endpoints
  • language (String) Code of country to ping against (relevant when requesting prices)
  • styles (String[]) Array of style IDs or style option IDs
  • wantImages (Boolean) Optional. Whether or not you want to retrieve image links. Defaults to false
  • wantPrices (Boolean) Optional. Wether or not you want to retrieve prices formatted dor the chosen language. Defaults to false
  • wantLinks (Boolean) Optional. Wether or not you want to retrieve links for all markets, or just the generic one. Defaults to false

getOcapiUrl (clientID, language, stylesString, wantImages: false, wantPrices: false)

Returns a String (the OCAPI URL to request, if you plan on doing yourself more advanced parsing of the response).

  • clientID (String) OCAPI public key for the chosen instance, with appropriate access to /shop/products endpoints
  • language (String) Code of country to ping against (relevant when requesting prices)
  • styles (String) Array of style IDs or style option IDs
  • wantImages (Boolean) Optional. Whether or not you want to retrieve image links. Defaults to false
  • wantPrices (Boolean) Optional. Wether or not you want to retrieve prices formatted dor the chosen language. Defaults to false

Example: Requesting images and prices of a style

var ocapi = require('jj-npm-ocapi');

ocapi.getInfo(
	clientID,
	'DK',								                // locale
	['12103726_Anthracite',12109802,'TSD10066863'],	    // array of style IDs/style option IDs
	true,								                // images
	true								                // prices
).then( function(json) {
	// execute once info is retrieved
	console.log(json)
})

Example of the return object (TSD10066863 is an invalid/out of stock style)

{
    '12109802': {
    	name: 'MONOKROM SWEATSHIRT',
        link: 'http://jackjones.com/12109802.html?',
        price: 179.95,
        formattedPrice: '179,95 DKK',
        images: {
            '12109802_Black_519727': 'http://shop.bestseller.com/on/demandware.static/-/Sites-pim-catalog/default/dw9be8265e/pim-static/large/12109802_Black_519727_001_ProductLarge.jpg',
            '12109802_ForestNight_519727': 'http://shop.bestseller.com/on/demandware.static/-/Sites-pim-catalog/default/dw9be8265e/pim-static/large/12109802_ForestNight_519727_001_ProductLarge.jpg'
        }
    },
    '12103726_Anthracite': {
    	name: 'LET SNEAKERS',
        link: 'http://jackjones.com/12103726.html?dwvar_colorPattern=12103726_Anthracite',
        price: 499.95,
        formattedPrice: '499,95 DKK',
        images: {
            '12103726_Anthracite': 'http://shop.bestseller.com/on/demandware.static/-/Sites-pim-catalog/default/dw9be8265e/pim-static/large/12103726_Anthracite_001_ProductLarge.jpg'
        }
    },
    TSD10066863: false
}

Example: Requesting just the OCAPI URL

var ocapi = require('jj-npm-ocapi');

console.log(
	ocapi.getOcapiUrl(
		clientID,
		'DK',								                // locale
		['12103726_Anthracite',12109802,'TSD10066863'],		// array of style IDs/style option IDs
		true,								                // images
		true								                // prices
	)
)
http://shop.bestseller.com/s/BSE-DK/dw/shop/v15_4/products/(12103726,12109802)?client_id=xxxxxxxxxxxxxxxxxxx&expand=images,prices&currency=DKK

Notes

  • Out of stock styles are not retrievable. Querying them will return a false, like in the example above.
  • If you request a style ID, images for all of its varaitions will be returned, indexed by style option ID.
  • For clientside scripting, install the package via npm install jj-npm-ocapi, require it in your scripts as in the examples above, bundle it among all other dependencies with eg. browserify main.js -o bundle.js

License

MIT

Repo changelog

1.4.0

  • Bingified module

1.3.6

  • Added product links to returned object

1.3.5

  • Turned into isomorphic package

1.2.X

  • We don't speak of 1.2.X

1.2.1

  • Styles not found / out of stock return a false

1.2.0

  • Added product name to return obj
1.4.0

8 years ago

1.3.6

8 years ago

1.3.5

8 years ago

1.3.4

8 years ago

1.3.3

8 years ago

1.3.2

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago