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

Create Product Example problems #87

Closed davidlashlee closed 7 years ago

davidlashlee commented 7 years ago

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?

ynnoj commented 7 years ago

@davidlashlee Thanks for noting the issues in the documentation, they've now been fixed.

type is a required field as per the JSON:API spec. However the library can do a better job at including this in the payload rather than being included in the body object by the user. We'll look to address this.