Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest API response - unexpected characters in JSON response #49

Open
Lukaaaa opened this issue Oct 8, 2019 · 8 comments
Labels

Comments

@Lukaaaa
Copy link

@Lukaaaa Lukaaaa commented Oct 8, 2019

Calling REST Api for refunds eg: example.com/wp-json/wc/v3/orders/31936/refunds returns a JSON response containing invalid characters.

We did not change anything on our backend that is calling the woocommerce REST api but we did update the woocommerce plugin to the latest version: 3.7.0

See screenshot:
response

@jessepearson

This comment has been minimized.

Copy link

@jessepearson jessepearson commented Oct 9, 2019

@Lukaaaa As mentioned in your ticket (2408699-zen), we can only make sure the API is working correctly. In my testing this is the URL I used on my site: http://local.test/wp-json/wc/v3/orders/121070/refunds

This is what I am getting returned:

[{"id":121075,"date_created":"2019-10-09T09:49:16","date_created_gmt":"2019-10-09T13:49:16","amount":"12.50","reason":"","refunded_by":1,"refunded_payment":true,"meta_data":[],"line_items":[{"id":3832,"name":"FedEx product","product_id":120982,"variation_id":0,"quantity":-1,"tax_class":"","subtotal":"-10.00","subtotal_tax":"-2.50","total":"-10.00","total_tax":"-2.50","taxes":[{"id":25,"total":"-2.5","subtotal":"-2.5"}],"meta_data":[{"id":28133,"key":"_refunded_item_id","value":"3829"}],"sku":"","price":10}],"_links":{"self":[{"href":"https://local.test/wp-json/wc/v3/orders/121070/refunds/121075"}],"collection":[{"href":"https://local.test/wp-json/wc/v3/orders/121070/refunds"}],"up":[{"href":"https://local.test/wp-json/wc/v3/orders/121070"}]}}]

In your response, there are additional items such as the msg. Is this something coming from your system? Are you trying to create a refund and it failed? Need some more backstory here.

@Lukaaaa

This comment has been minimized.

Copy link
Author

@Lukaaaa Lukaaaa commented Oct 9, 2019

I have a rest api (post) on my backend: example.com/cancelOrder/. When calling my rest api (cancelOrder) than the backend makes a rest call to woocommerce: example.com/wp-json/wc/v3/orders/ORDERID/refunds. Than my backend response with my state (ok field and msg field) + the raw response that i get from the woocommerce api (response field). The refund works and also woocommerce refunds the money but i cannot parse the response from woocommerce api anymore because there is some special character in the beginning. I have attached the code snippet of my backend maybe it helps to understand better. (The yellow highlighted part cannot be parsed because of the special character)
backend

@jessepearson

This comment has been minimized.

Copy link

@jessepearson jessepearson commented Oct 9, 2019

@Lukaaaa What do you get if you directly make the GET request to the API with something like Postman?

@Lukaaaa

This comment has been minimized.

Copy link
Author

@Lukaaaa Lukaaaa commented Oct 9, 2019

It works in Postman but the thing is that it also worked with my backend before the woocommerce update. I have also tried to call another 3rd party rest api with the same backend and even this works. So somehow there is an issue with calling the woocommerce api.

@claudiosanches claudiosanches transferred this issue from woocommerce/woocommerce Oct 9, 2019
@issue-label-bot issue-label-bot bot added the type: bug label Oct 9, 2019
@issue-label-bot

This comment has been minimized.

Copy link

@issue-label-bot issue-label-bot bot commented Oct 9, 2019

Issue-Label Bot is automatically applying the label type: bug to this issue, with a confidence of 0.95. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@jessepearson

This comment has been minimized.

Copy link

@jessepearson jessepearson commented Oct 10, 2019

@Lukaaaa I had someone else on this side look at this as well, and we aren't able to reproduce the issue you are seeing. The data should always be returned the same regardless. They did notice your responseType is set to blob and not json, have you tried updating that?

Additionally, have you tried the same code on another server?

@Lukaaaa

This comment has been minimized.

Copy link
Author

@Lukaaaa Lukaaaa commented Oct 12, 2019

@jessepearson yes, i have tried to to change the responseType to json, nothing changes i am still getting the unrecognized character. Yes i have tried the code also on a different server. Somehow strange... Did you change anything regarding the encoding of the woo rest api?

@jessepearson

This comment has been minimized.

Copy link

@jessepearson jessepearson commented Oct 15, 2019

@Lukaaaa Support was not able to reproduce the issue on this end, myself and two others. Perhaps the developers in this repo might be able to add some more assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.