moltin / js-sdk

JavaScript & Node.js SDKs for the Elastic Path Commerce Cloud eCommerce API
http://documentation.elasticpath.com/
MIT License
173 stars 77 forks source link

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

Closed tnolet closed 7 years ago

tnolet commented 8 years ago

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
outrunthewolf commented 7 years ago

Hi the second parameter in the error catch will give you more detailed information:


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, errorMessage) =>{
      console.error(errorMessage);
    })
  })
;```