Git Product home page Git Product logo

js-sdk's Introduction

Elastic Path Commerce Cloud JavaScript SDK

npm version License: MIT contributions welcome follow on Twitter

A simple to use API interface to help get you off the ground quickly and efficiently with your Elastic Path Commerce Cloud JavaScript apps.

📚 API reference — 📚 Elastic Path Commerce Cloud

🛠 Installation

Install the package from npm and import in your project.

npm install --save @moltin/sdk

⛽️ Usage

To get started, instantiate a new Moltin client with your store credentials.

Note: This requires an Elastic Path Commerce Cloud account.

// JavaScript
import { gateway as MoltinGateway } from '@moltin/sdk'

const Moltin = MoltinGateway({
  client_id: 'XXX'
})

// Node.js
const MoltinGateway = require('@moltin/sdk').gateway

const Moltin = MoltinGateway({
  client_id: 'XXX',
  client_secret: 'XXX'
})

Alternatively you can include the UMD bundle via UNPKG like so:

<script src="https://unpkg.com/@moltin/sdk"></script>

<script>
  const Moltin = moltin.gateway({
    client_id: 'XXX'
  });
</script>

Note: If you're using webpack, you'll need to add the following to your projects configuration file.

node: {
  fs: 'empty'
}

You can now authenticate with the Moltin service 🎉

Moltin.Authenticate().then(response => {
  console.log('authenticated', response)
})

Check out the API reference to learn more about authenticating and the available endpoints.

Custom Host

If you're an enterprise customer with your own infrastructure, you'll need to specify your API URL when instantiating:

const Moltin = MoltinGateway({
  client_id: 'XXX',
  host: 'api.yourdomain.com'
})

Custom Storage

By default the Elastic Path Commerce Cloud SDK persists data to window.localStorage in the browser and node-localstorage in Node. If this doesn't suit your needs you can override the default storage with a MemoryStorageFactory which will persist data for the life cycle of the JavaScript VM:

import { gateway as MoltinGateway, MemoryStorageFactory } from '@moltin/sdk'

const Moltin = MoltinGateway({
  client_id: 'XXX',
  storage: new MemoryStorageFactory()
})

Or alternatively, create your own storage factory by passing in an object which implements the following interface:

interface StorageFactory {
  set(key: string, value: string): void;
  get(key: string): string | null;
  delete(key: string): void;
}

Multiple Gateways

You can support multiple gateways with a name property when initializing the gateway.

name should be unique to avoid sharing storage keys with the other gateways of the same name.

import { gateway as EPCCGateway } from "@moltin/sdk"

const gatewayOne = EPCCGateway({
    name: "my-first-gateway",
    client_id: 'XXX'
})

const gatewayTwo = EPCCGateway({
    name: "my-second-gateway",
    client_id: 'XXX'
})

Storage keys used for storage solutions are prefixed with the name provided and end with the relevant feature e.g. my-first-gateway_ep_cart, my-first-gateway_ep_credentials and my-first-gateway_ep_currency.

If no name property is provided to the EPCCGateway function, the legacy naming is maintained: mcart, moltinCredentials and mcurrency

Included Headers

There are currently several optional headers you can pass into the configuration, which include application, language and currency.

You can pass them into the config used by the gateway like this:

// JavaScript
import { gateway as MoltinGateway } from '@moltin/sdk'
// const MoltinGateway = require('@moltin/sdk').gateway -> for Node

const Moltin = MoltinGateway({
    client_id: 'XXX',
    client_secret: 'XXX'
    currency: 'YEN',
    language: 'en',
    application: 'my-app'
})

Retries

In case the server responds with status 429 - "Too Many Requests" SDK will wait for some time and retry the same API request up to a given number of times. You can fine tune this logic through following config parameters:

const Moltin = MoltinGateway({
    client_id: 'XXX',
    client_secret: 'XXX',
    retryDelay: 1000,
    retryJitter: 500,
    fetchMaxAttempts: 4
})

In case of a 429 response SDK will wait for retryDelay milliseconds (default 1000) before attempting to make the same call. If the server responds with 429 again it will wait for 2 * retryDelay ms, then 3 * retryDelay ms and so on. On top of that the random value between 0 and retryJitter (default 500) will be added to each wait. This would repeat up to fetchMaxAttempts (default 4) times.

Throttling (Rate Limiting)

SDK supports throttling through use of throttled-queue library. Unlike the throttle functions of popular libraries, throttled-queue will not prevent any executions. Instead, every execution is placed into a queue, which will be drained at the desired rate limit. You can control throttling through following parameters:

const Moltin = MoltinGateway({
    client_id: 'XXX',
    client_secret: 'XXX',
    throttleEnabled: true,
    throttleLimit: 3,
    throttleInterval: 125
})

This feature is disabled by default and to enable it you need to set throttleEnabled to true. Once enabled you can use throttleLimit (default 3) and throttleInterval (default 125) to define what is the maximum number of calls per interval. For example setting throttleLimit = 5, throttleInterval = 1000 means maximum of 5 calls per second.

Handling File Upload

Files can be uploaded to the EPCC file service with the Moltin.Files.Create method. You should pass a FormData object as described in the documentation.

In a Node.js environment, where you may be using an alternative FormData implementation, you can include a second parameter to represent the Content-Type header for the request. This must be multipart/form-data and must include a boundary. For example, using the form-data package:

const FormData = require('form-data')
const formData = new FormData()
formData.append('file', buffer)

const contentType = formData.getHeaders()['content-type']

Moltin.Files.Create(formData, contentType)

Referencing a file stored elsewhere

If you want to create a file by simply referencing a file stored elsewhere, you can use this helper method:

Moltin.Files.Link('https://cdn.external-host.com/files/filename.png')

Just pass the URL to the Link method and creation will be handled for you.

TypeScript Support

The Elastic Path Commerce Cloud JavaScript SDK is fully supported in Typescript.

Imported module will contain all interfaces needed to consume backend services. i.e:

import * as moltin from '@moltin/sdk';

const product: moltin.ProductBase = {...}

If you do not want to use the namespace, you can extend the interfaces and define them yourself, like so:

// You can name the interface anything you like
interface Product extends product.ProductBase {
}

const product: Product = {...}

Here is an example of a simple product creation:

import { Moltin, gateway, ProductBase, Resource } from '@moltin/sdk';

async function main() {
  const g: Moltin = gateway({client_id, client_secret});
  const auth = await g.Authenticate();

  const newProduct: ProductBase = {
    type: "product",
    name: "My Product",
    slug: "my-prod",
    sku: "my-prod",
    manage_stock: false,
    description: "Some description",
    status: "draft",
    commodity_type: "physical",
    price: [
      {
        amount: 5499,
        currency: "USD",
        includes_tax: true
      }
    ]
  };

  const nP: Resource<Product> = await g.Products.Create(newProduct);
}

You can also extend any base interface compatible with flows to create any custom interfaces that you might be using by re-declaring @moltin/sdk module. Following example adds several properties to ProductsBase interface that correspond to flows added to the backend.

In your project add a definition file (with a .d.ts extension) with a following code:

import * as moltin from '@moltin/sdk';

declare module '@moltin/sdk' {

  interface Weight {
    g: number;
    kg: number;
    lb: number;
    oz: number;
  }

  interface ProductBase {
    background_color: string;
    background_colour: string | null;
    bulb: string;
    bulb_qty: string;
    finish: string;
    material: string;
    max_watt: string;
    new: string | null;
    on_sale: string | null;
    weight: Weight;
  }

}

This will affect base interface and all other Product interfaces that inherit from base interface so added properties will be present when creating, updating, fetching products.

❤️ Contributing

We love community contributions. Here's a quick guide if you want to submit a pull request:

  1. Fork the repository
  2. Add a test for your change (it should fail)
  3. Make the tests pass
  4. Commit your changes (see note below)
  5. Submit your PR with a brief description explaining your changes

Note: Commits should adhere to the Angular commit conventions.

Make sure you have Prettier installed for your editor with ESLint integration enabled.

⚡️ Development

The SDK is built with ES6 modules that are bundled using Rollup.

If you want to roll your own bundle, or make changes to any of the modules in src, then you'll need to install the package dependencies and run rollup while watching for changes.

npm install
npm start

To run test

npm test

You can learn more about the Rollup API and configuration here.

Terms And Conditions

  • Any changes to this project must be reviewed and approved by the repository owner.
  • For more information about the license, see MIT License.

js-sdk's People

Contributors

butikden avatar cheeryfella avatar craigtweedy avatar dr-ep avatar field123 avatar gausie avatar georgebotzakis avatar long-wan-ep avatar mahsaelasticpath avatar mwan-ep avatar notrab avatar outrunthewolf avatar petro97 avatar razkevich avatar renovate-bot avatar renovate[bot] avatar rishi-ayata avatar rostyk-kanafotskyy avatar s-soltys avatar samblacklock avatar sarawasim1 avatar sebin-vincent avatar shaunmaharaj avatar yasamanloghman avatar yasiloghmani avatar ynnoj avatar yulia-dnistrian avatar yurii-khovzun avatar zoltantakacs-born avatar zot24 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-sdk's Issues

Authentication

Hi,
Is there any doc about the authenticate endpoint ?
By default there is no password field in the Customer Flow.
Also i don't understand how the authentification is handled as i don't see when the auth credentials I suppose customers/authenticate returns are stored.
Thanks

@machard Moved to issue rather than on the pr.

There are two types of authentication.

One, is using the access token endpoint to get an access token to enable you to make requests to the API. http://moltin.github.io/documentation/authenticate/

The second is customer authentication. This is not in general release as yet and you will not be able to use it until early january.

Getting Price issue on final checkout amount

Hi I am getting price issue on Moltin checkout

price is adding to cart api correctly but while calling cart complete api for checkout getting price issue

ex. if total is $200 then getting $20 on cart complete checkout (edited)

every amount is divided by 10

can you tell me why I am getting this issue???

Here is the code which I am using

Adding items to cart

moltin.Cart.Insert(cartArrayObj[length-1].obj.id, cartArrayObj[length-1].qty,null,function(obj){
return countdown(length - 1,cartArrayObj);
});

Cart checkout

var order = moltin.Cart.Complete({
gateway: user.role=="-1" && !obj.isTrialOrder ?'paypal-express':'manual',
customer: {
first_name: user.name,
last_name: user.surname,
email: user.email
},
bill_to: {
first_name: user.name,
last_name: user.surname,
address_1: invoiceData.clientCompanyAddress,
city: invoiceData.clientCompanyCity,
county: invoiceData.clientCompanyProvince,
country: invoiceData.clientCompanyCountry,
postcode: invoiceData.clientCompanyPostalCode
},
ship_to: 'bill_to',
shipping: 'free_shipping'
},function(success){
});

Indentation

Any reason why indentation is with 8 spaces instead of the conventional 2?

Grunt fails due to missing coffee files

As there is no builder directory in the src directory, the Gruntfile fails to compile the coffee files it expects to find within.

Immediate fix is to comment out that line (13) in the Gruntfile.

Getting issue when I am adding items to Cart

Using Moltin js sdk.
I am adding Items to cart but when i checkout
I see that the items which are added are not same
sometimes it is from last order
and sometimes in existing order any one of item is randomly missing
this is really strange behaviour
I am also deleting the cart when the payment is successful
can you please tell me why it is happening so?

Here is the code which I am using-

var _addItemToCart = function(product, qty){
moltin.Cart.Insert(product.id, qty, null,function(obj){
console.log("Return of cart item :");
console.log(obj);
});
};

var _processOrder = function(obj,invoiceData){
  var user = obj.user;

  var order = moltin.Cart.Complete({
    gateway: 'paypal-express',
    customer: {
      first_name: user.name,
      last_name:  user.surname,
      email:      user.email
    },
    bill_to: {
      first_name: user.name,
      last_name:  user.surname,
      address_1:  invoiceData.clientCompanyAddress,
      city:       invoiceData.clientCompanyCity,
      county:     invoiceData.clientCompanyProvince,
      country:    invoiceData.clientCompanyCountry,
      postcode:   invoiceData.clientCompanyPostalCode
    },
    ship_to: 'bill_to',
    shipping: 'free_shipping'
  });

   console.log("orderId");
   console.log(order.id);

  var checkout = moltin.Checkout.Payment('purchase', order.id, {
    return_url: siteBasicUrl + FF_CONFIG.call.shopping.paypalSuccessRedirectUrl.path + '?orderId='+order.id,
    cancel_url: siteBasicUrl + FF_CONFIG.call.shopping.paypalCancelRedirectUrl.path + '?orderId='+order.id,
    data: {
      /*number:       '4242424242424242',
      expiry_month: '02',
      expiry_year:  '2017',
      cvv:          '123'*/
    }
  },function(success){
    console.log('success');
    console.log(success);
    moltin.Cart.Delete();
    window.location.href = success.url;
  });
};

Is Node SDK production ready?

Hi, I talked to customer support on moltin.com and I told them we're planning on using Moltin with Node. The response I got back was that the Node SDK might not be production ready yet?

Any input on that response, is it safe to start use it or will we experience bugs? What I can see on this repository it seems it's ready for production? Or are there any known bugs?

Cheers,
Fredrik

Can't add product to cart; Error says "error"

Hi,

I'm trying to follow the tutorial in the Readme. When adding my product to the cart, I get an error callback with the string "error". The authentication and finding of the product work fine. This is my code (credential left out):

moltin.Authenticate(() => {
  console.info('authenticated with moltin')
  moltin.Product.Find({SKU: 'TOTO10'},(products) => {
    console.info(products)
    moltin.Cart.Insert(products[0].id, 1,null,(item)=>{
      console.info(item)
      moltin.Cart.Contents((items) => {
        console.info(items)
      })
    },(err) =>{
      console.error(err)
    })
  })
;

Here's the output when I run it:

Debugger listening on port 61223
[POST] https://api.molt.in/oauth/access_token
authenticated with moltin
[GET] https://api.molt.in/v1/products?SKU=TOTO10
[ { id: '1146494495798330097',
    order: null,
    created_at: '2015-12-23 17:46:56',
    updated_at: '2015-12-23 17:46:56',
    sku: 'TOTO10',
    title: 'Toto 1.0 Scooter',
    slug: 'toto10',
    sale_price: 0,
    status: { value: 'Live', data: [Object] },
    category: { value: 'Uncategorized', data: [Object] },
    stock_level: 3,
    stock_status: { value: 'In Stock', data: [Object] },
    description: 'ridin',
    requires_shipping: { value: 'Yes', data: [Object] },
    weight: 0,
    height: 0,
    width: 0,
    depth: 0,
    catalog_only: { value: 'No', data: [Object] },
    tax_band: { value: 'Default', data: [Object] },
    collection: null,
    brand: null,
    price: { value: '$839,00', data: [Object] },
    is_variation: false,
    modifiers: 
     { '1146497707267850996': [Object],
       '1146498180821549815': [Object] },
    images: [] } ]
[POST] https://api.molt.in/v1/carts/caec5220ba41018dbf357780ea954083
error

BUG in products endpoint

When requesting product variations, for example: https://api.molt.in/v1/products?status=1&modifier%5B1031496585520874354%5D=1031496636750103412&modifier%5B1031496611072574323%5D=1031496684984599416

It will return all live products, not the requested product variation!

{ "status": true, "result": [ { "id": "1031496575588762481", "order": null, "created_at": "2015-07-18 01:45:05", "updated_at": "2015-07-27 09:36:37", "sku": "d1d7af40-2cee-11e5-bafc-7108f6eaaa9f", "title": "sggfg g ff", "slug": "sggfg-g-ff", "sale_price": 25, "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "category": { "value": "Test", "data": { "1020824221456007355": { "id": "1020824221456007355", "order": null, "created_at": "2015-07-03 08:22:35", "updated_at": "2015-07-28 10:53:37", "parent": null, "slug": "Test", "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "title": "Test", "description": "Test tag" } } }, "stock_level": 4, "stock_status": { "value": "Unlimited", "data": { "key": "0", "value": "Unlimited" } }, "description": "gdfgvgv", "requires_shipping": { "value": "No", "data": { "key": "0", "value": "No" } }, "weight": 0, "height": 0, "width": 0, "depth": 0, "catalog_only": { "value": "No", "data": { "key": "0", "value": "No" } }, "brand": null, "collection": null, "tax_band": { "value": "Default", "data": { "id": "909423295621759411", "title": "Default", "description": null, "rate": 20, "created_at": null, "updated_at": null } }, "user_id": "facebook|10153300780764382", "large_image_url": "http:\\/\\/nodejs-jollyrogers.rhcloud.com\\/files\\/6b94b6e4-4389-463e-9c6f-b4f914ce1560.png", "price": { "value": "£27.60", "data": { "formatted": { "with_tax": "£27.60", "without_tax": "£23.00", "tax": "£4.60" }, "rounded": { "with_tax": 27.6, "without_tax": 23, "tax": 4.6 }, "raw": { "with_tax": 27.6, "without_tax": 23, "tax": 4.6 } } }, "is_variation": false, "modifiers": { "1031496585520874354": { "id": "1031496585520874354", "order": null, "created_at": "2015-07-18 01:45:35", "updated_at": "2015-07-18 01:45:35", "type": { "value": "Variant", "data": { "key": "variant", "value": "Variant" } }, "title": "Size", "instructions": "Select size!", "product": 1031496575588762481, "variations": { "1031496636750103412": { "id": "1031496636750103412", "order": null, "created_at": "2015-07-18 01:45:42", "updated_at": "2015-07-18 01:45:42", "title": "Swatch One", "mod_price": "=5.0", "modifier": 1031496585520874354, "product": 0, "difference": "=£5.00" }, "1031496652805899126": { "id": "1031496652805899126", "order": null, "created_at": "2015-07-18 01:45:43", "updated_at": "2015-07-18 01:45:43", "title": "Swatch Two", "mod_price": "=10.0", "modifier": 1031496585520874354, "product": 0, "difference": "=£10.00" } } }, "1031496611072574323": { "id": "1031496611072574323", "order": null, "created_at": "2015-07-18 01:45:38", "updated_at": "2015-07-18 01:45:38", "type": { "value": "Variant", "data": { "key": "variant", "value": "Variant" } }, "title": "Fabric", "instructions": "Select fabric!", "product": 1031496575588762481, "variations": { "1031496684984599416": { "id": "1031496684984599416", "order": null, "created_at": "2015-07-18 01:45:47", "updated_at": "2015-07-18 01:45:47", "title": "Basic Combed", "mod_price": "=0.0", "modifier": 1031496611072574323, "product": 0, "difference": "=£0.00" }, "1031497210883212155": { "id": "1031497210883212155", "order": null, "created_at": "2015-07-18 01:46:50", "updated_at": "2015-07-18 01:46:50", "title": "Satin", "mod_price": "=0.0", "modifier": 1031496611072574323, "product": 0, "difference": "=£0.00" } } } }, "images": [ { "id": 1031497776896148477, "name": "mod_var_right.png", "url": { "http": "http:\\/\\/commercecdn.com\\/909423294489297855\\/42307c2c-1617-4ae5-8b5c-1f6660406606.png", "https": "https:\\/\\/commercecdn.com\\/909423294489297855\\/42307c2c-1617-4ae5-8b5c-1f6660406606.png" }, "segments": { "domain": "commercecdn.com\\/", "suffix": "909423294489297855\\/42307c2c-1617-4ae5-8b5c-1f6660406606.png" }, "details": { "type": "image", "size": 133365, "width": 1392, "height": 920 } } ] }, { "id": "1028320617998320246", "order": null, "created_at": "2015-07-13 16:36:37", "updated_at": "2015-07-13 16:41:59", "sku": "4ffb2ca0-297d-11e5-be93-831cb00d64b1", "title": "Canvas test", "slug": "canvas-test", "sale_price": 25, "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "category": { "value": "Test", "data": { "1020824221456007355": { "id": "1020824221456007355", "order": null, "created_at": "2015-07-03 08:22:35", "updated_at": "2015-07-28 10:53:37", "parent": null, "slug": "Test", "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "title": "Test", "description": "Test tag" } } }, "stock_level": 4, "stock_status": { "value": "Unlimited", "data": { "key": "0", "value": "Unlimited" } }, "description": "rfrgr gtg tg t gtr t rg gr", "requires_shipping": { "value": "No", "data": { "key": "0", "value": "No" } }, "weight": 0, "height": 0, "width": 0, "depth": 0, "catalog_only": { "value": "No", "data": { "key": "0", "value": "No" } }, "brand": null, "collection": null, "tax_band": { "value": "Default", "data": { "id": "909423295621759411", "title": "Default", "description": null, "rate": 20, "created_at": null, "updated_at": null } }, "user_id": "facebook|10153300780764382", "large_image_url": "http:\\/\\/localhost:8080\\/files\\/1eef833c-f618-4c18-91fb-70a6b02c43f7.jpg", "price": { "value": "£27.60", "data": { "formatted": { "with_tax": "£27.60", "without_tax": "£23.00", "tax": "£4.60" }, "rounded": { "with_tax": 27.6, "without_tax": 23, "tax": 4.6 }, "raw": { "with_tax": 27.6, "without_tax": 23, "tax": 4.6 } } }, "is_variation": false, "modifiers": { "1028320633542410871": { "id": "1028320633542410871", "order": null, "created_at": "2015-07-13 16:36:38", "updated_at": "2015-07-13 16:36:38", "type": { "value": "Variant", "data": { "key": "variant", "value": "Variant" } }, "title": "Size", "instructions": "Select type of fabric", "product": 1028320617998320246, "variations": { "1028320649128444536": { "id": "1028320649128444536", "order": null, "created_at": "2015-07-13 16:36:40", "updated_at": "2015-07-13 16:36:40", "title": "Swatch 1", "mod_price": "=5", "modifier": 1028320633542410871, "product": 0, "difference": "=£5.00" }, "1028320669118497402": { "id": "1028320669118497402", "order": null, "created_at": "2015-07-13 16:36:43", "updated_at": "2015-07-13 16:36:43", "title": "Swatch 2", "mod_price": "=10", "modifier": 1028320633542410871, "product": 0, "difference": "=£10.00" } } }, "1028320688965943932": { "id": "1028320688965943932", "order": null, "created_at": "2015-07-13 16:36:45", "updated_at": "2015-07-13 16:36:45", "type": { "value": "Variant", "data": { "key": "variant", "value": "Variant" } }, "title": "Fabric", "instructions": "Select type of fabric", "product": 1028320617998320246, "variations": [] } }, "images": [ { "id": 1028320793622217698, "name": "myCanvas.png", "url": { "http": "http:\\/\\/commercecdn.com\\/909423294489297855\\/8f9098fd-7025-4c04-b3c6-d657913b5b1e.png", "https": "https:\\/\\/commercecdn.com\\/909423294489297855\\/8f9098fd-7025-4c04-b3c6-d657913b5b1e.png" }, "segments": { "domain": "commercecdn.com\\/", "suffix": "909423294489297855\\/8f9098fd-7025-4c04-b3c6-d657913b5b1e.png" }, "details": { "type": "image", "size": 490642, "width": 1392, "height": 920 } } ] }, { "id": "1021022977812070736", "order": null, "created_at": "2015-07-03 14:57:29", "updated_at": "2015-07-04 10:40:55", "sku": "ce98d5e0-2193-11e5-8fd3-05e85835f7e3", "title": "fvregRWEG trg tg TR h", "slug": "fvregrweg-trg-tg-tr-h", "sale_price": 25, "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "category": { "value": "Test", "data": { "1020824221456007355": { "id": "1020824221456007355", "order": null, "created_at": "2015-07-03 08:22:35", "updated_at": "2015-07-28 10:53:37", "parent": null, "slug": "Test", "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "title": "Test", "description": "Test tag" } } }, "stock_level": 4, "stock_status": { "value": "Unlimited", "data": { "key": "0", "value": "Unlimited" } }, "description": "fgerg egw er rg erew rg", "requires_shipping": { "value": "No", "data": { "key": "0", "value": "No" } }, "weight": 0, "height": 0, "width": 0, "depth": 0, "catalog_only": { "value": "No", "data": { "key": "0", "value": "No" } }, "brand": null, "collection": null, "tax_band": { "value": "Default", "data": { "id": "909423295621759411", "title": "Default", "description": null, "rate": 20, "created_at": null, "updated_at": null } }, "user_id": "auth0|5575fe366cd9f1c929960799", "large_image_url": "http:\\/\\/localhost:8080\\/files\\/6ecf25f5-fb4e-4f25-bd4f-ff3049b37d3b.png", "price": { "value": "£27.60", "data": { "formatted": { "with_tax": "£27.60", "without_tax": "£23.00", "tax": "£4.60" }, "rounded": { "with_tax": 27.6, "without_tax": 23, "tax": 4.6 }, "raw": { "with_tax": 27.6, "without_tax": 23, "tax": 4.6 } } }, "is_variation": false, "modifiers": { "1021023022598848852": { "id": "1021023022598848852", "order": null, "created_at": "2015-07-03 14:57:34", "updated_at": "2015-07-03 14:57:34", "type": { "value": "Variant", "data": { "key": "variant", "value": "Variant" } }, "title": "Basic test 2", "instructions": "Select type of fabric", "product": 1021022977812070736, "variations": { "1021023037094363477": { "id": "1021023037094363477", "order": null, "created_at": "2015-07-03 14:57:36", "updated_at": "2015-07-03 14:57:36", "title": "Basic test 2", "mod_price": "+10", "modifier": 1021023022598848852, "product": 0, "difference": "+£10.00" } } } }, "images": [ { "id": 1021023061572322236, "name": "818aa3b4-d5f2-45a3-b760-717014f00972.png", "url": { "http": "http:\\/\\/commercecdn.com\\/909423294489297855\\/36286dc5-3934-4e0c-9dd6-5c8774c57d08.png", "https": "https:\\/\\/commercecdn.com\\/909423294489297855\\/36286dc5-3934-4e0c-9dd6-5c8774c57d08.png" }, "segments": { "domain": "commercecdn.com\\/", "suffix": "909423294489297855\\/36286dc5-3934-4e0c-9dd6-5c8774c57d08.png" }, "details": { "type": "image", "size": 90712, "width": 1392, "height": 920 } } ] }, { "id": "1020602105989169203", "order": null, "created_at": "2015-07-03 01:01:17", "updated_at": "2015-07-06 21:42:14", "sku": "fae05710-211e-11e5-a089-7bea64f0fcb3", "title": "Testing 123", "slug": "testing-123", "sale_price": 25, "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "category": { "value": "Fabrics", "data": { "915479985974674420": { "id": "915479985974674420", "order": null, "created_at": "2015-02-08 00:02:20", "updated_at": "2015-07-28 10:52:19", "parent": null, "slug": "fabrics", "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "title": "Fabrics", "description": "<p>Fabrics<\\/p>" } } }, "stock_level": 4, "stock_status": { "value": "Unlimited", "data": { "key": "0", "value": "Unlimited" } }, "description": "Testing abc def...", "requires_shipping": { "value": "No", "data": { "key": "0", "value": "No" } }, "weight": 0, "height": 0, "width": 0, "depth": 0, "catalog_only": { "value": "No", "data": { "key": "0", "value": "No" } }, "brand": null, "collection": null, "tax_band": { "value": "Default", "data": { "id": "909423295621759411", "title": "Default", "description": null, "rate": 20, "created_at": null, "updated_at": null } }, "user_id": "auth0|5575fe366cd9f1c929960799", "large_image_url": "http:\\/\\/localhost:8080\\/files\\/38f430eb-726d-4f8c-889a-3bf56e80131d.jpg", "price": { "value": "£27.60", "data": { "formatted": { "with_tax": "£27.60", "without_tax": "£23.00", "tax": "£4.60" }, "rounded": { "with_tax": 27.6, "without_tax": 23, "tax": 4.6 }, "raw": { "with_tax": 27.6, "without_tax": 23, "tax": 4.6 } } }, "is_variation": false, "modifiers": { "1023416364125127490": { "id": "1023416364125127490", "order": null, "created_at": "2015-07-06 22:12:43", "updated_at": "2015-07-06 22:12:43", "type": { "value": "Variant", "data": { "key": "variant", "value": "Variant" } }, "title": "Size", "instructions": "Add size", "product": 1020602105989169203, "variations": { "1023417060899685187": { "id": "1023417060899685187", "order": null, "created_at": "2015-07-06 22:14:06", "updated_at": "2015-07-07 13:50:48", "title": "Test Swatch (8\" x 8\") ", "mod_price": "=5.00", "modifier": 1023416364125127490, "product": 0, "difference": "=£5.00" }, "1023888981839839419": { "id": "1023888981839839419", "order": null, "created_at": "2015-07-07 13:51:44", "updated_at": "2015-07-07 13:51:44", "title": "Fat Quarter (28\" x 18\") ", "mod_price": "=11.00", "modifier": 1023416364125127490, "product": 0, "difference": "=£11.00" }, "1023889395683426493": { "id": "1023889395683426493", "order": null, "created_at": "2015-07-07 13:52:33", "updated_at": "2015-07-07 13:52:33", "title": "Yards (54\" width)", "mod_price": "=18.00", "modifier": 1023416364125127490, "product": 0, "difference": "=£18.00" } } }, "1020602117892603956": { "id": "1020602117892603956", "order": null, "created_at": "2015-07-03 01:01:18", "updated_at": "2015-07-07 13:48:15", "type": { "value": "Variant", "data": { "key": "variant", "value": "Variant" } }, "title": "Fabric", "instructions": "Select type of fabric", "product": 1020602105989169203, "variations": { "1020612521008037952": { "id": "1020612521008037952", "order": null, "created_at": "2015-07-03 01:21:58", "updated_at": "2015-07-07 13:48:53", "title": "Satin ($18\\/yd)", "mod_price": "+0.00", "modifier": 1020602117892603956, "product": 0, "difference": "+£0.00" }, "1023892239429927103": { "id": "1023892239429927103", "order": null, "created_at": "2015-07-07 13:58:12", "updated_at": "2015-07-07 13:58:12", "title": "Basic Combed Cotton ($17.50\\/yd)", "mod_price": "+0.00", "modifier": 1020602117892603956, "product": 0, "difference": "+£0.00" } } } }, "images": [ { "id": 1020602198121251771, "name": "DeathtoStock6_ kopia_2.jpg", "url": { "http": "http:\\/\\/commercecdn.com\\/909423294489297855\\/a2fe06a0-1bc9-4d2e-9e10-763bdfbcdc1e.png", "https": "https:\\/\\/commercecdn.com\\/909423294489297855\\/a2fe06a0-1bc9-4d2e-9e10-763bdfbcdc1e.png" }, "segments": { "domain": "commercecdn.com\\/", "suffix": "909423294489297855\\/a2fe06a0-1bc9-4d2e-9e10-763bdfbcdc1e.png" }, "details": { "type": "image", "size": 421674, "width": 1392, "height": 920 } } ] }, { "id": "1020153260205409011", "order": null, "created_at": "2015-07-02 10:09:30", "updated_at": "2015-07-02 10:09:30", "sku": "69b8aed0-20a2-11e5-ae51-61b8b3ab20e2", "title": "Escheresque2", "slug": "escheresque2", "sale_price": 25, "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "category": null, "stock_level": 4, "stock_status": { "value": "Unlimited", "data": { "key": "0", "value": "Unlimited" } }, "description": "escheresque mönster", "requires_shipping": { "value": "No", "data": { "key": "0", "value": "No" } }, "weight": 0, "height": 0, "width": 0, "depth": 0, "catalog_only": { "value": "No", "data": { "key": "0", "value": "No" } }, "brand": null, "collection": null, "tax_band": null, "user_id": "auth0|5575fe366cd9f1c929960799", "large_image_url": "http:\\/\\/localhost:8080\\/files\\/95642005-b360-4875-be81-accdea9cce6d.png", "price": { "value": "£23.00", "data": { "formatted": { "with_tax": "£23.00", "without_tax": "£23.00", "tax": "£0.00" }, "rounded": { "with_tax": 23, "without_tax": 23, "tax": 0 }, "raw": { "with_tax": 23, "without_tax": 23, "tax": 0 } } }, "is_variation": false, "modifiers": { "1020527340800704516": { "id": "1020527340800704516", "order": null, "created_at": "2015-07-02 22:32:44", "updated_at": "2015-07-02 22:32:44", "type": { "value": "Variant", "data": { "key": "variant", "value": "Variant" } }, "title": "Basic TEST", "instructions": "Select type of fabric", "product": 1020153260205409011, "variations": [] }, "1020305275262862169": { "id": "1020305275262862169", "order": null, "created_at": "2015-07-02 15:11:32", "updated_at": "2015-07-02 15:11:32", "type": { "value": "Variant", "data": { "key": "variant", "value": "Variant" } }, "title": "Basic test", "instructions": "", "product": 1020153260205409011, "variations": [] } }, "images": [ { "id": 1020153286537249718, "name": "escheresque_ste kopia.png", "url": { "http": "http:\\/\\/commercecdn.com\\/909423294489297855\\/5ae9dc26-9f2a-4ff5-b6d7-a630d5969570.png", "https": "https:\\/\\/commercecdn.com\\/909423294489297855\\/5ae9dc26-9f2a-4ff5-b6d7-a630d5969570.png" }, "segments": { "domain": "commercecdn.com\\/", "suffix": "909423294489297855\\/5ae9dc26-9f2a-4ff5-b6d7-a630d5969570.png" }, "details": { "type": "image", "size": 132867, "width": 1392, "height": 920 } } ] }, { "id": "1018355053901120436", "order": null, "created_at": "2015-06-29 22:35:26", "updated_at": "2015-06-29 22:35:26", "sku": "50640370-1eaf-11e5-ab60-657b4fe21bb4", "title": "Sjö", "slug": "sjoe", "sale_price": 25, "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "category": null, "stock_level": 4, "stock_status": { "value": "Unlimited", "data": { "key": "0", "value": "Unlimited" } }, "description": "En sjö", "requires_shipping": { "value": "No", "data": { "key": "0", "value": "No" } }, "weight": 0, "height": 0, "width": 0, "depth": 0, "catalog_only": { "value": "No", "data": { "key": "0", "value": "No" } }, "brand": null, "collection": null, "tax_band": null, "user_id": "auth0|5575fe366cd9f1c929960799", "large_image_url": "http:\\/\\/nodejs-jollyrogers.rhcloud.com\\/files\\/ffa97b3c-7e8f-49c7-9243-43c801a69971.JPG", "price": { "value": "£23.00", "data": { "formatted": { "with_tax": "£23.00", "without_tax": "£23.00", "tax": "£0.00" }, "rounded": { "with_tax": 23, "without_tax": 23, "tax": 0 }, "raw": { "with_tax": 23, "without_tax": 23, "tax": 0 } } }, "is_variation": false, "modifiers": [], "images": [ { "id": 1018355189872067228, "name": "IMG_5636 kopia.JPG", "url": { "http": "http:\\/\\/commercecdn.com\\/909423294489297855\\/2a1307dc-c883-4064-8844-cbf84b0abac5.png", "https": "https:\\/\\/commercecdn.com\\/909423294489297855\\/2a1307dc-c883-4064-8844-cbf84b0abac5.png" }, "segments": { "domain": "commercecdn.com\\/", "suffix": "909423294489297855\\/2a1307dc-c883-4064-8844-cbf84b0abac5.png" }, "details": { "type": "image", "size": 1709739, "width": 1392, "height": 920 } } ] }, { "id": "1014410241128792480", "order": null, "created_at": "2015-06-24 11:59:07", "updated_at": "2015-06-24 11:59:07", "sku": "6967a7f0-1a68-11e5-998f-4709feb131af", "title": "jkblkbkjkjkj kjkj kj", "slug": "jkblkbkjkjkj-kjkj-kj", "sale_price": 25, "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "category": null, "stock_level": 4, "stock_status": { "value": "Unlimited", "data": { "key": "0", "value": "Unlimited" } }, "description": "kbbjkkjkj kj", "requires_shipping": { "value": "No", "data": { "key": "0", "value": "No" } }, "weight": 0, "height": 0, "width": 0, "depth": 0, "catalog_only": { "value": "No", "data": { "key": "0", "value": "No" } }, "brand": null, "collection": null, "tax_band": null, "user_id": "auth0|5575fe366cd9f1c929960799", "large_image_url": "http:\\/\\/localhost:8080\\/files\\/3ab98a29-0c77-4a3f-b1ce-0abf1046d580.png", "price": { "value": "£23.00", "data": { "formatted": { "with_tax": "£23.00", "without_tax": "£23.00", "tax": "£0.00" }, "rounded": { "with_tax": 23, "without_tax": 23, "tax": 0 }, "raw": { "with_tax": 23, "without_tax": 23, "tax": 0 } } }, "is_variation": false, "modifiers": [], "images": [ { "id": 1014410295956734889, "name": "baefec3b-109b-438f-be79-3144af2d879b.png", "url": { "http": "http:\\/\\/commercecdn.com\\/909423294489297855\\/33793877-2b51-4fda-9b61-4c88c7ea6f4e.png", "https": "https:\\/\\/commercecdn.com\\/909423294489297855\\/33793877-2b51-4fda-9b61-4c88c7ea6f4e.png" }, "segments": { "domain": "commercecdn.com\\/", "suffix": "909423294489297855\\/33793877-2b51-4fda-9b61-4c88c7ea6f4e.png" }, "details": { "type": "image", "size": 1101908, "width": 1392, "height": 920 } } ] }, { "id": "1014408793464766879", "order": null, "created_at": "2015-06-24 11:56:14", "updated_at": "2015-06-24 11:56:14", "sku": "0285eb00-1a68-11e5-998f-4709feb131af", "title": "jhnh hjh jk j hjk", "slug": "jhnh-hjh-jk-j-hjk", "sale_price": 25, "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "category": null, "stock_level": 4, "stock_status": { "value": "Unlimited", "data": { "key": "0", "value": "Unlimited" } }, "description": "jhjhhjkhkj jhjkhjk", "requires_shipping": { "value": "No", "data": { "key": "0", "value": "No" } }, "weight": 0, "height": 0, "width": 0, "depth": 0, "catalog_only": { "value": "No", "data": { "key": "0", "value": "No" } }, "brand": null, "collection": null, "tax_band": null, "user_id": "auth0|5575fe366cd9f1c929960799", "large_image_url": "http:\\/\\/localhost:8080\\/files\\/dd63f4c5-a074-400e-85d4-ac12b01b43b4.png", "price": { "value": "£23.00", "data": { "formatted": { "with_tax": "£23.00", "without_tax": "£23.00", "tax": "£0.00" }, "rounded": { "with_tax": 23, "without_tax": 23, "tax": 0 }, "raw": { "with_tax": 23, "without_tax": 23, "tax": 0 } } }, "is_variation": false, "modifiers": [], "images": [ { "id": 1014408899219948456, "name": "molnfrontprotractor.png", "url": { "http": "http:\\/\\/commercecdn.com\\/909423294489297855\\/b959b29e-6d0f-4751-822f-3aa9cbf86f46.png", "https": "https:\\/\\/commercecdn.com\\/909423294489297855\\/b959b29e-6d0f-4751-822f-3aa9cbf86f46.png" }, "segments": { "domain": "commercecdn.com\\/", "suffix": "909423294489297855\\/b959b29e-6d0f-4751-822f-3aa9cbf86f46.png" }, "details": { "type": "image", "size": 1862341, "width": 1392, "height": 920 } } ] }, { "id": "1014396051848692126", "order": null, "created_at": "2015-06-24 11:30:55", "updated_at": "2015-06-24 11:30:55", "sku": "79180fe0-1a64-11e5-91ac-09229c647e72", "title": "hhjjh ghj ghj ghjkhjk", "slug": "hhjjh-ghj-ghj-ghjkhjk", "sale_price": 25, "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "category": null, "stock_level": 4, "stock_status": { "value": "Unlimited", "data": { "key": "0", "value": "Unlimited" } }, "description": "jkh jkhjkhkj hk", "requires_shipping": { "value": "No", "data": { "key": "0", "value": "No" } }, "weight": 0, "height": 0, "width": 0, "depth": 0, "catalog_only": { "value": "No", "data": { "key": "0", "value": "No" } }, "brand": null, "collection": null, "tax_band": null, "user_id": "auth0|5575fe366cd9f1c929960799", "large_image_url": "http:\\/\\/localhost:8080\\/files\\/77003f31-da04-4282-b872-755b3f0219e5.png", "price": { "value": "£23.00", "data": { "formatted": { "with_tax": "£23.00", "without_tax": "£23.00", "tax": "£0.00" }, "rounded": { "with_tax": 23, "without_tax": 23, "tax": 0 }, "raw": { "with_tax": 23, "without_tax": 23, "tax": 0 } } }, "is_variation": false, "modifiers": [], "images": [ { "id": 1014396088045536167, "name": "1c9f6329-ab53-4dc5-9b68-52f50466451c.png", "url": { "http": "http:\\/\\/commercecdn.com\\/909423294489297855\\/0b0f3562-f93c-450d-bb7b-5d3d19942e9b.png", "https": "https:\\/\\/commercecdn.com\\/909423294489297855\\/0b0f3562-f93c-450d-bb7b-5d3d19942e9b.png" }, "segments": { "domain": "commercecdn.com\\/", "suffix": "909423294489297855\\/0b0f3562-f93c-450d-bb7b-5d3d19942e9b.png" }, "details": { "type": "image", "size": 244033, "width": 1392, "height": 920 } } ] }, { "id": "1013360242160828484", "order": null, "created_at": "2015-06-23 01:11:43", "updated_at": "2015-06-23 01:11:43", "sku": "f9c2ec80-1944-11e5-92b1-6591b3121c6c", "title": "fff g rg erg", "slug": "fff-g-rg-erg", "sale_price": 25, "status": { "value": "Live", "data": { "key": "1", "value": "Live" } }, "category": null, "stock_level": 4, "stock_status": { "value": "Unlimited", "data": { "key": "0", "value": "Unlimited" } }, "description": "grgrgr gr", "requires_shipping": { "value": "No", "data": { "key": "0", "value": "No" } }, "weight": 0, "height": 0, "width": 0, "depth": 0, "catalog_only": { "value": "No", "data": { "key": "0", "value": "No" } }, "brand": null, "collection": null, "tax_band": null, "user_id": "auth0|5575fe366cd9f1c929960799", "large_image_url": "http:\\/\\/localhost:8080\\/files\\/a55255a4-7df6-4634-b7d1-8b6dd29a0c4d.jpg", "price": { "value": "£23.00", "data": { "formatted": { "with_tax": "£23.00", "without_tax": "£23.00", "tax": "£0.00" }, "rounded": { "with_tax": 23, "without_tax": 23, "tax": 0 }, "raw": { "with_tax": 23, "without_tax": 23, "tax": 0 } } }, "is_variation": false, "modifiers": [], "images": [ { "id": 1013360318220337788, "name": "Erik%20Hermansson.jpg", "url": { "http": "http:\\/\\/commercecdn.com\\/909423294489297855\\/9c4a24f9-beb1-4173-951a-88829c7d6903.png", "https": "https:\\/\\/commercecdn.com\\/909423294489297855\\/9c4a24f9-beb1-4173-951a-88829c7d6903.png" }, "segments": { "domain": "commercecdn.com\\/", "suffix": "909423294489297855\\/9c4a24f9-beb1-4173-951a-88829c7d6903.png" }, "details": { "type": "image", "size": 442942, "width": 1392, "height": 920 } } ] } ], "pagination": { "total": 144, "current": 10, "limit": 10, "offset": 0, "from": 1, "to": 10, "offsets": { "first": 0, "previous": false, "next": 10, "last": 140 }, "links": { "first": "http:\\/\\/api.molt.in\\/v1\\/products?limit=10&status=1&modifier%5B1031496585520874354%5D=1031496636750103412&modifier%5B1031496611072574323%5D=1031496684984599416", "previous": false, "next": "http:\\/\\/api.molt.in\\/v1\\/products?offset=10&limit=10&status=1&modifier%5B1031496585520874354%5D=1031496636750103412&modifier%5B1031496611072574323%5D=1031496684984599416", "last": "http:\\/\\/api.molt.in\\/v1\\/products?offset=140&limit=10&status=1&modifier%5B1031496585520874354%5D=1031496636750103412&modifier%5B1031496611072574323%5D=1031496684984599416" } } }

A request to the beta API endpoint, for example: https://api.molt.in/beta/product?status=1&modifier%5B1031496585520874354%5D=1031496636750103412&modifier%5B1031496611072574323%5D=1031496684984599416

Will respond with the requested product variation:

`{
"status": true,
"result": {
"id": "1031496688096772985",
"order": null,
"created_at": "2015-07-18 01:45:48",
"updated_at": "2015-07-28 13:38:44",
"sku": "d1d7af40-2cee-11e5-bafc-7108f6eaaa9f_SW_BA",
"title": "sggfg g ff Swatch One Basic Combed",
"slug": "sggfg-g-ff-swatch-one-basic-combed",
"sale_price": 25,
"status": {
"value": "Live",
"data": {
"key": "1",
"value": "Live"
}
},
"category": {
"value": "Test",
"data": {
"1020824221456007355": {
"id": "1020824221456007355",
"order": null,
"created_at": "2015-07-03 08:22:35",
"updated_at": "2015-07-28 10:53:37",
"parent": null,
"slug": "Test",
"status": {
"value": "Live",
"data": {
"key": "1",
"value": "Live"
}
},
"title": "Test",
"description": "Test tag"
}
}
},
"stock_level": 444,
"stock_status": {
"value": "In Stock",
"data": {
"key": "1",
"value": "In Stock"
}
},
"description": "gdfgvgv",
"requires_shipping": {
"value": "No",
"data": {
"key": "0",
"value": "No"
}
},
"weight": 0,
"height": 0,
"width": 0,
"depth": 0,
"catalog_only": {
"value": "No",
"data": {
"key": "0",
"value": "No"
}
},
"brand": null,
"collection": null,
"tax_band": {
"value": "Default",
"data": {
"id": "909423295621759411",
"title": "Default",
"description": null,
"rate": 20,
"created_at": null,
"updated_at": null
}
},
"user_id": "facebook|10153300780764382",
"large_image_url": "http:\/\/nodejs-jollyrogers.rhcloud.com\/files\/6b94b6e4-4389-463e-9c6f-b4f914ce1560.png",
"price": "5",
"pricing": {
"formatted": {
"with_tax": "£6.00",
"without_tax": "£5.00",
"tax": "£1.00"
},
"rounded": {
"with_tax": 6,
"without_tax": 5,
"tax": 1
},
"raw": {
"with_tax": 6,
"without_tax": 5,
"tax": 1
}
},
"is_variation": true,
"modifiers": [
{
"data": {
"type": "variant",
"title": "Size",
"product": "1031496575588762481",
"instructions": "Select size!"
},
"var_title": "Swatch One",
"var_price": null,
"var_id": 1031496636750103412
},
{
"data": {
"type": "variant",
"title": "Fabric",
"product": "1031496575588762481",
"instructions": "Select fabric!"
},
"var_title": "Basic Combed",
"var_price": null,
"var_id": 1031496684984599416
}
],
"images": [
{
"id": 1039100699524202523,
"name": "23f8bcae-6185-44e8-b1da-eed53f9987aa.png",
"url": {
"http": "http:\/\/commercecdn.com\/909423294489297855\/5c3ce147-0c50-484e-9168-fb18aecaa79b.png",
"https": "https:\/\/commercecdn.com\/909423294489297855\/5c3ce147-0c50-484e-9168-fb18aecaa79b.png"
},
"segments": {
"domain": "commercecdn.com\/",
"suffix": "909423294489297855\/5c3ce147-0c50-484e-9168-fb18aecaa79b.png"
}
}
]
}
}``

I have tested with Postman. So this is not a problem with the js-sdk or js-demo code, it is the v1 API endpoint responding with the wrong data.

Calling Moltin.Products.UpdateRelationships(moltinId, 'category', []) fails

Hi!

Calling await Moltin.Products.UpdateRelationships(moltinId, 'category', []) to clear all Product <=> Category relationships fails with the following error:

{
    "message": {
        "errors": [
            {
                "status": 500,
                "title": "Internal Server Error",
                "detail": "There was an internal server error, you can report with your request id.",
                "request_id": "6c8b4050dc4c0eb2"
            }
        ]
    }
}

Although a PUT request directly placed to the endpoint works.

Take a look at the code here on Line: 8

export function buildRelationshipData(type, ids) {
let data = [];
if (ids === null || ids.length === 0) {
return '[]';
}
if (typeof ids === 'string') {
return [{
type,
id: ids,
}];
}

All other return statements return an Array whereas, this line returns a string. Which I suppose is again converted to JSON string with JSON.stringify(body) resulting in "[]" instead of []

Nodejs SDK error

My code:

// test.js
const M = require('moltin')

const m = new M({debug: true, publicId: 'xxx', secretKey: 'xxx'})

m.Authenticate(function(){
    console.log('success')  // log
    createTax()
})

function createTax() {
        m.Product.Create({
            title:             'My First Product',
            slug:              'my-first-product-',
            sku:               'my-sku',
            price:             10.00,
            status:            1,
            category:          1396075875539092372,
            stock_level:       1000,
            stock_status:      1,
            tax_band: 1396202847816647595,
            requires_shipping: 0,
            catalog_only:      0,
            description:       'My very first amazing product!'
        }, function(product) {
            console.log('product', product); 
        }, function(error) {
            console.log(error) // log 'error',just a string 'error', not a object
        }); 

}

Nothing happen. Just log 'success' and 'error'. Could tell me what's wrong here ?

IE11 errors on new CustomEvent

On line 171 of moltin.js, new CustomEvent(...) raises an error in IE11

"Object doesn't support this action"

This occurs when I attempt to authenticate a user before adding a product to the cart. Please let me know if you need additional information.

Can't import moltin using es6

Hi,
I can't be able to import moltin in react using es6. I got the following error:
Uncaught TypeError: (0 , _moltin.gateway) is not a function

 // this doesn't work
import {gateway as MoltinGateway} from 'moltin'; 

It because I think you've not provided any index.js file in src folder.

The only way to make it work using dist folder:

// It worked
import {gateway as MoltinGateway} from 'moltin/dist/moltin.cjs.js';

Please add the index.js file in src folder.

Library disfunctional using Create-React-App

I am currently working on a new project I already started using Moltin and manage to get the Authentication working plus a few commands, however I am running into tons of issues! I have added the node: { fs: 'empty' }to the module webpack config file. Let me talk you through the Code I tried using:

normal import as in the git docs doesn't seem to work

import { gateway as MoltinGateway } from 'moltin';  
      const Moltin = MoltinGateway({}) // is not a function

so I used:

       import {gateway as MoltinGateway} from 'moltin/dist/moltin.cjs.js';

        const Moltin = MoltinGateway({
            grant_type: 'client_credentials',
            clientId: 'XXXX',
            client_secret: 'XXXXX',
       });

// MoltinGateway doesn't set the clientId in the config object ???

      Moltin.config.clientId = 'XXXXXX';

      Moltin.Authenticate().then((response) => {
      console.log('authenticated', response); // getting an implicit connection instead of the client_credentials
      });

Great the connection worked! But now the Cart commands just don't exist, except Cart.Get call ?

// not working commands!

      Moltin.Cart.AddProduct
      Moltin.Cart.Items
      Moltin.Cart.Checkout

From the offical moltin js docs using MoltinClient already seems to fail as it doesn't exist:


      npm install moltin

      import { MoltinClient } from 'moltin';

       const moltin = MoltinClient({
            client_id: 'XXXX'
      }); //MoltinClient doesn't exist. 

I need this library to function correctly! Could anybody tell me one of the following things?
-Why wasn't the clientId set in MoltenGateway?
-how to access the Cart functions?
-Why are both the official docs plus the github docs not leading to a correct import of the Moltin.Gateway module or MoltenClient (official docs)?
-Does this have to do with webpack within Create-react-app?

Thank you in advance!

JS-SDK v2 - Wiki: Authentication; wrong attribute.

The wiki shows the payload as

const Moltin = moltin.gateway({
  client_id: 'XXX'
});

This throws an error of TypeError: Cannot read property 'length' of undefined
After looking further into the codebase, it is apparent that the correct payload should be:

const Moltin = moltin.gateway({
  publicId: 'XXX'
});

401 and CORS issue

Getting a 401 error on /api/v1/products and

XMLHttpRequest cannot load https://api.molt.in/v1/products. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 401.

Building the app using Next.js / react. You don't need moltin.Authenticate() to list the products, correct?

Contrived example below at what I'm trying to do

import Moltin from 'moltin'

// ...

componentDidMount() {
  this.setState({
     moltin: new Moltin({publicId: 'XXX'});
  });
}

_getProducts() {
  console.log(this.state.moltin.Product.List());
}

// ...

localStorage module error on AWS Lambda

Steps to reproduce:

  1. Create a lambda function
  2. Import moltin sdk const MoltinGateway = require('@moltin/sdk').gateway;

And optionally

const Moltin = MoltinGateway({
  client_id:process.env.moltin_client_id,
  client_secret: process.env.moltin_secret
});

// some operations like Authenticate

This gives an error when the function is invoked
START RequestId: 7cb9c41f.... Version: $LATEST
module initialization error: Error
at Error (native)
at Object.fs.mkdirSync (fs.js:923:18)
at LocalStorage._init (/var/task/node_modules/node-localstorage/LocalStorage.js:151:12)
at new LocalStorage (/var/task/node_modules/node-localstorage/LocalStorage.js:121:12)
at new StorageFactory (/var/task/node_modules/@moltin/sdk/dist/moltin.cjs.js:1:854)
at cartIdentifier (/var/task/node_modules/@moltin/sdk/dist/moltin.cjs.js:1:2009)
at new Moltin (/var/task/node_modules/@moltin/sdk/dist/moltin.cjs.js:1:11644)
at gateway (/var/task/node_modules/@moltin/sdk/dist/moltin.cjs.js:1:12252)
at Object. (/var/task/index.js:6:16)
at Module._compile (module.js:570:32)
END RequestId: 7cb9c41f-1e56-11e8-bc01-115ee78d5e05
REPORT RequestId: 7cb9c41f-1e56-11e8-bc01-115ee78d5e05 Duration: 250.42 ms Billed Duration: 300 ms Memory Size: 128 MB Max Memory Used: 25 MB
module initialization error
Error

Can't remove item from current Cart

Hello,

When trying to remove an item from my current cart, I get the error:
Invalid JSON: Unexpected token u in JSON at position 8

I am using the following code with import { gateway as MoltinGateway } from 'moltin' :

removeFromCart(id) {
    const Moltin = MoltinGateway({
        client_id: 'MY_CLIENT_ID'
    })
    Moltin.Cart.RemoveItem(id).then((cart) => {
        this.props.dispatch(updateCart(cart))
    })
}

It seems that a payload is send that shouldn't be here:
{"data":undefined}

Do you know why this payload is send?

Thank you in advance!

Promotion code sticks to cart after deleting it

Try to apply a discount code then delete the cart and add item to the new cart you will see that the discount code works on the new cart as well!

This is because you have to run the Cart.Identifier after deleting the cart to create a new id for it... which I think you should hardcode it in your script after the Cart.Delete promise resolves.

Thanks

Refresh cart identifier method

Would be nice to be able to refresh the cart token (e.g. once an order has been paid) with a new method e.g. moltin.Cart.Refresh

Similar to moltin.Cart.GetIdentifier but overrides the cart identifier instead of checking if it exists first.

Get the main image url for the product?

Hi there,

I just started to use the moltin js-sdk and have read almost everywhere but can't find how to get the main-image url for the product? the Files section of the Wiki is missing for something and I don't want to use the REST API for get the link. How should I retrieve the main-image when I do Moltin.Products.All() ?

Any help would appreciated. Thanks

Entries search endpoint

from
return @m.Request 'flow/'+flow+'/entries', 'GET', terms, callback
to
return @m.Request 'flows/'+flow+'/entries/search', 'GET', terms, callback

(may aswell be done along with pluralisation)

Stock Management

How do I get Product Inventory, create or retrieve Stock Transactions using the sdk?

ERROR in ./node_modules/graceful-fs/graceful-fs.js

I get the following error when trying to import the SDK into a Vue Nuxt.js application

import { gateway as MoltinGateway } from '@moltin/sdk'

The error only persits as soon as I include the import in my store/index.js file. Any idea what might be causing this?

ERROR in ./node_modules/graceful-fs/graceful-fs.js
Module not found: Error: Can't resolve 'fs' in '/Users/XXX/Dropbox/Work in Progress/XXX/08_Github/XXX/node_modules/graceful-fs'
 @ ./node_modules/graceful-fs/graceful-fs.js 1:9-22
 @ ./node_modules/write-file-atomic/index.js
 @ ./node_modules/node-localstorage/LocalStorage.js
 @ ./node_modules/@moltin/sdk/dist/moltin.umd.js
 @ ./store/index.js
 @ ./store ^\.\/(?!-).*\.(js)$
 @ ./.nuxt/store.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js
 @ multi webpack-hot-middleware/client?name=client&reload=true&timeout=30000&path=/__webpack_hmr ./.nuxt/client.js

ERROR in ./node_modules/graceful-fs/fs.js
Module not found: Error: Can't resolve 'fs' in '/Users/XXX/Dropbox/Work in Progress/XXX/08_Github/XXX/node_modules/graceful-fs'
 @ ./node_modules/graceful-fs/fs.js 3:9-22
 @ ./node_modules/graceful-fs/graceful-fs.js
 @ ./node_modules/write-file-atomic/index.js
 @ ./node_modules/node-localstorage/LocalStorage.js
 @ ./node_modules/@moltin/sdk/dist/moltin.umd.js
 @ ./store/index.js
 @ ./store ^\.\/(?!-).*\.(js)$
 @ ./.nuxt/store.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js
 @ multi webpack-hot-middleware/client?name=client&reload=true&timeout=30000&path=/__webpack_hmr ./.nuxt/client.js

ERROR in ./node_modules/node-localstorage/LocalStorage.js
Module not found: Error: Can't resolve 'fs' in '/Users/XXX/Dropbox/Work in Progress/XXX/08_Github/XXX/node_modules/graceful-fs'
 @ ./node_modules/node-localstorage/LocalStorage.js 9:7-20
 @ ./node_modules/@moltin/sdk/dist/moltin.umd.js
 @ ./store/index.js
 @ ./store ^\.\/(?!-).*\.(js)$
 @ ./.nuxt/store.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js
 @ multi webpack-hot-middleware/client?name=client&reload=true&timeout=30000&path=/__webpack_hmr ./.nuxt/client.js

Create Product Example problems

Hey in the products wiki page

Moltin.Products.Create({
  name: 'A new product',
  slug: 'a-new-product',
  sku: '00001',
  manage_stock: true,
  description: 'A fantastic, new product available today!',
  price: [{
    amount: 100,
    currency: 'USD',
    includex_tax: false
  }],
  status: 'live'
}).then((product) => {
  // Do something
});

Didn't work for me with the following errors

errors: 
   [ { title: 'Failed Validation',
       detail: 'The data.price.0.includes_tax field is required.' },
     { title: 'Failed Validation',
       detail: 'The data.type field is required.' },
     { title: 'Failed Validation',
       detail: 'The data.commodity type field is required.' } ] }

ended up resolving it with

Moltin.Products.Create({
    type: 'product',
    title: 'a new product', 
    name: 'A new product',
    slug: 'a-new-product',
    sku: '00001',
    manage_stock: true,
    description: 'A fantastic, new product available today!',
    price: [{
        amount: 100,
        currency: 'USD',
        includes_tax: false
    }],
    commodity_type: "digital",
    status: 'live'
}).then((product) => {
  // Do something
    console.log(product)
});

"includex_tax" should be "includes_tax" and Moltin.Products.Create argument object is missing type and commodity_type.

also, why is "type" a required parameter to provide? based on my understanding of the documentation, its required to be `type: 'product', and that's your only option. Am I misunderstanding that?

Impossible to initialize Moltin as a service in Angular 2

Hi guys!

I've been trying to use the sdk with Angular 2 (actually the 4.1.3 version) initializing the Molltin package as a service, but without success.

The following code, is the typical used to start a new project in Angular 2 very simple, but it seems that the Moltin module is not returning the necessary things to register it as a service. Or maybe the problem is that I'm actually doing something wrong (probably xD)

Every time that I tried, the app throws an error with this message:
Error: No provider for gateway!

So, a little bit of my code:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
// App modules
import { AppComponent } from './app.component';
// Moltin module
import { gateway as MoltinGateway } from '@moltin/sdk';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [
    MoltinGateway
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}```


Anybody with the same problem?

Many thanks in advance!

Cannot filter Products by Category

Previously in V1, you could filter products by Category; it seems you cannot do that now in the SDK.
My current v1 implementation of moltin requires the capability to do this.
I would prefer not to do this manually on my micro-service if possible

Uncaught TypeError: Cannot read property 'options' of undefined

When I pass bad data into Cart.Complete, it spits out a double-error:

uncaught-typeerror

The first one is expected... That's just me getting a slap on the wrist for handing off bad data.

The second one is unexpected. Apparently something in the SDK chokes after that bad data arrives.

Unable to Authenticate CORS request when withCredentials flag true

Am currently integrating with moltin, have had difficulty Authenticating as per official example

var moltin = require('moltin')({
  publicId: config.MOLTIN_CLIENT_ID,
  secretKey: config.MOLTIN_CLIENT_SECRET
})
moltin.Authenticate()

Produces this error:

XMLHttpRequest cannot load https://api.molt.in/oauth/access_token. A wildcard '_' cannot be used in the 'Access-Control-Allow-Origin' header when the _credentials flag is true*. Origin 'http://localhost:8080' is therefore not allowed access.

Temporary Fix

Setting withCredentials: false for XMLHttpRequests (AJAX) requests yields the preferred response.

Ref nodejs/ajax.coffee

Ajax: (options) ->
   ...
    args =
      method:   'GET'
      async:    false
      data:     null
      timeout:  60000
      headers:  {}
      host:     @options.url
      port:     443
      path:     '/'

      // Set withCredentials to false
      withCredentials: false

      success:  (response, status, request) ->
    ...

For further information see this discussion at Stack Overflow http://stackoverflow.com/questions/34078676/access-control-allow-origin-not-allowed-when-credentials-flag-is-true-but#comment57072759_34099399

Since we are using OAuth bearer token security, we pass the client information as a header, and we do not use any type of cookies for security. This means that we do not need to use the withCredentials AJAX parameter.
-- ozkary | 25 Dec 2015

Support for custom Storage

I would like the option to use a custom storage library during configuration (I'm using the sdk in the backend). As of now, node-localstorage creates a directory named localStorage/ on my project root. It would be nice to have the option to use database storage instead, so as to keep the code stateless.

Access token json object format different from API /oauth/access_token

First time it get the access token as the API return it

{  
  expires:1455117677,
  identifier:'client_credentials',
  expires_in:3600,
  access_token:'51af9b38492effcca99d4823b01930864c2e10',
  token_type:'Bearer'
}

However second time is pulling the access token (that haven't expire yet) from the local storage https://github.com/moltin/js-sdk/blob/master/src/moltin.coffee#L112 and it's giving it a different format

{ 
token: '51af9b38492effcca99d4823b01930864c2e10', 
expires: 1455117677000 
}

'@moltin/sdk' is not in the npm registry.

i get this when trying to install this package, already tried a couple solutions that google mentioned but only thing working is doing "@moltin/sdk": "https://github.com/moltin/js-sdk.git" in package.json, not ideal though.

Any thoughts?

Create product with image upload

The images endpoint need assign_to that the ID number of the object to which you want to attach this image. But the problem is when I create product, it's ID automatically populated, So how to attach the upload image to a create product ?

Deleting a product throws UnhandledPromiseRejectionWarning and breaks code.

Hi,

When I call gateway.Products.Delete(UUID), my code breaks with UnhandledPromiseRejectionWarning. I can't seem to catch the error by .catch(e => console.log(e)) either.

I tested the API endpoint directly. That seems to work. Although, it returns an empty response, whereas, according to the docs, its supposed to return {type: 'product', id: UUID}. I think the sdk is trying to parse the empty response as JSON.

I suspect the code at src/utils/helpers.js line 42 is to blame. When I add a .catch() to the line like this: response.json().catch(e => ...).then() directly inside node_modules I'm able to catch this error:

{ Error
    at /Users/aravindanve/Work/temp/node_modules/node-fetch/lib/body.js:48:31
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
  name: 'FetchError',
  message: 'invalid json response body at https://api.moltin.com/v2/products/745468c9-c7a4-436d-aac7-5b4687f674f9 reason: Unexpected end of JSON input',
  type: 'invalid-json' }

Is this repo maintained? Where are the API docs?

Hi,

just evaluating Moltin, but slightly concerned about the lack of docs (I know there are REST api docs, but I mean the JS/NodeJS docs) and the lack of activity. Is this ripe for production?

Not trying to troll.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.