thecolorblue / moltin.node.js

node.js moltin library.
5 stars 3 forks source link

Product modifiers #2

Open molnsys opened 9 years ago

molnsys commented 9 years ago

I have tried to modify products.coffe in the nodejs module so I can add modifiers for a product:

return @m.Request 'products/'+id+'/modifiers', 'POST', modifier, callback, error```


The problem I think is to pass the id in the constructor. I can't add it to the modifier object and add modifier.id, because there should be no id sent to moltin.

I have also tried to hard code the id in the request url. But no luck yet. I have succesfully done a POST  with POSTMAN against api.molt.in. So I know that I have the right URL and variables.

I have also tried to monitor what nodejs is doing but can not see https request. So I do not know exactly what is being sent from node. I have also tried to use console.log but nothing gets back.

This is not working:

// create product modifier 
app.options('/api/modifier', cors(corsOptions));
app.get('/api/modifier', cors(corsOptions), function(req, res) {
    var id = req.query.prodid;
    var title = req.query.title; 
    var instructions = "Select type of fabric";  
    moltin.Authenticate(function() {  
    var themodifier = {"title": title, "type": "variant", "instructions": instructions};
    moltin.Product.CreateModifiers(id, themodifier, function(product) {
    console.log('moltin create modifier!');
   return res.send(product);  
   },  function(error,body) {
        // Something went wrong...
      var errObject = JSON.parse(body);
      return res.status(401).send(errObject.errors);
      console.log(errObject.errors);
    });
  }, function() {
    console.log('auth failed:', arguments);
  });
});
thecolorblue commented 9 years ago

Looking over it quickly the url might be incorrect depending on what version you are using. According to this it should be product/:id/modifiers and not products/....

Try that and see if it helps. If you happen to be on windows you can use fiddler to see what requests are going out. There might be something similar for mac osx and linux. Another option would be to use node-inspector but I have found it to be a little rough around the edges.

If I have some time I will work on getting the errors to be a little more useful. It should really catch something like this a give a meaningful error.