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

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

Closed aravindanve closed 7 years ago

aravindanve commented 7 years ago

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

https://github.com/moltin/js-sdk/blob/6ebcb9985221a3dfc11fdf2b4ed6bae963167594/src/utils/helpers.js#L4-L16

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 []

ynnoj commented 7 years ago

@aravindanve Are you able to share the full request payload built from the library?

ynnoj commented 7 years ago

If you're trying to remove all existing relationships, then UpdateRelationships would be the right method to use.

Moltin.Products.UpdateRelationships(id, 'category')

I suspect the 500 you're seeing is because you're using CreateRelationships with an empty payload. Let me know if this helps 🙃

aravindanve commented 7 years ago

Hi @ynnoj

Sorry, my mistake. I meant Moltin.Products.UpdateRelationships(id, 'category'). I've updated the issue.

ynnoj commented 7 years ago

@aravindanve Can you share the payload in the request body please?

aravindanve commented 7 years ago

I'm using it in the backend. I need to do a quick browser test to get the request payload from the sdk. Hold on.

aravindanve commented 7 years ago

@ynnoj here you go! (https://runkit.com/aravindanve/moltin1)

Screenshot here: (https://pasteboard.co/GJi8oWo.png)

ynnoj commented 7 years ago

Looks like your hypothesis is correct! 😄

aravindanve commented 7 years ago

Hi @ynnoj, any idea on when this will be merged?

ynnoj commented 7 years ago

Hey @aravindanve. Will be merged and published this morning.

ynnoj commented 7 years ago

2.6.2 just published with this fix 🎉

aravindanve commented 7 years ago

@ynnoj Perfect! Thank You!