evonove / mkm-sdk

33 stars 14 forks source link

Put Shopping Cart #26

Closed Gugi264 closed 8 years ago

Gugi264 commented 8 years ago

Hi, this is most likely not a bug, just my stupidity. But how can i put articles to the shoppingcart?

i tried: response = mkm.shopping_cart.put_shopping_cart(xml) where xml is the (hopefully correct) xml, but i just get as response: "No Articles provided".

What is the correct way to put items?

P.S.: Sorry when this shouldn't be here

silvanocerza commented 8 years ago

Hi @Gugi264. when you need to POST or PUT some data use the key word data like this: response = mkm.shopping_cart.put_shopping_cart(data=xml)

If the xml is formatted correctly and with the right data you should obtain a positive response.

Let me know if there are any other problems.

Gugi264 commented 8 years ago

Hi @Alien1993 , thanks for the input.

I tried now a few different things, and i am pretty sure my xml is correct, but it just won't work. I even took the example xml from the api website, saved it as an xml file and tried it like this: filename = 'test.xml' response = mkm.shopping_cart.put_shopping_cart(data=open(filename).read()) But not even that worked.

Any ideas of what i could be doing wrong?

silvanocerza commented 8 years ago

I just tested it with the sandbox and this XML and received a 200 response. I open and read the file the same way you do. What status code do you receive?

<?xml version="1.0" encoding="UTF-8" ?>
<request>
    <action>add</action>
    <article>
        <idArticle>142158699</idArticle>
        <amount>1</amount>
    </article>
</request>
Gugi264 commented 8 years ago

I tested it in Sandbox mode, exactly like you.

i receive:

{'error': b'{"error":"No article(s) provided"}'}

with this code: filename = 'test.xml' response = mkm_sandbox.shopping_cart.put_shopping_cart(data=open(filename).read()) print(response) exit()

Edit: @Alien1993 Could you look at my project? I did the xml stuff in the first 14 lines, so if you could look at that and tell me whats wrong i would be very thankful ;)

silvanocerza commented 8 years ago

I tried to make the call with your code and it works for me, I receive a 200 from the backend so the code is correct.

Have you tried using another XML?

Gugi264 commented 8 years ago

I tried different thing, other xml, xml direct as string.... nothing works.... i have absolutely no idea what could be the error. i even tried it on a different pc, some respone :(

I thought maybe i don't have necessary requirement installed, but all 3 requirements are already pre installed...

silvanocerza commented 8 years ago

@Gugi264 I think I found the problem. My guess is you are installing mkm-sdk version 0.3.0, that version has a bug that doesn't permit to POST or PUT any data to the backend, it's already been fixed but will be released on version 0.4.0. And that's why I couldn't reproduce your issue, because I was using the latest unreleased version.

pip show mkm-sdk should show you that the version you have installed is 0.3.0, if you have an older pip version use pip freeze.

Gugi264 commented 8 years ago

@Alien1993 you were right, i use version 0.3.0 Thanks for the help, atleast i know now what the error is when will 0.4.0 be released?

silvanocerza commented 8 years ago

I need to fix some issues and I'll be ready to release a new version. Shouldn't take more than a week.

silvanocerza commented 8 years ago

@Gugi264 I just released 0.4.0, should have solved the issues you were having. Let me know if there is any other problem.