Hi,

I'm invoking the woocommerce API to import all the orders from my online store to my personal environment. This process will create new or update existing orders. 

Since the woocommerce api only returns 10 records at a time i need to send the page=n parameter in the request parameters. What i'm doing is a cycle that increases the pagenr until the request has no results.

On the first round, all works fine but on the second one I get an error:

Failed to parse response of the method 'GetOrders' of the 'xxxxx' REST API:
Parsing '[1].meta_data[5].value': Unexpected character encountered while parsing value: [. Path '[1].meta_data[5].value', line 1, position 4310.
Parsing '[1].meta_data[5]': JsonToken EndArray is not valid for closing JsonType Object. Path '[1].meta_data[5]', line 1, position 4311.
Parsing '[1].meta_data[5]': Unexpected character encountered while parsing value: }. Path '[1].meta_data[5]', line 1, position 4311.

Anyone has any ideia why this appens?

Regards

Miguel

Solution

Hello Miguel,

What is the full JSON you are receiving the second time?

Cheers.

EDIT

P.S. I would say that when you consumed the rest method, the answer was not a full answer, so you are missing attributes, or most probably the answer has an attribute that sometimes comes as a single value, and sometimes comes as an array.

If it is the second situation, you need to change the attribute in the structure used to receive the data to be a list and pre-process the answer of the method to change the attribute to be an array if it comes as a single value.

Cheers.

Solution

Thanks for your answer Eduardo.

Following your second ideia I found that the JSON has a field that in one situation comes defined as an array but on the rest of the situations is a string... I only dont't know how to handle this.. also I don't need that structure.

Regards

EDIT: I found a solution... since I don't need that structure I removed it from the output ;-) It's working now.

Thanks for your help.

Glad to be of help, :)

Eduardo Jauch wrote:

Hello Miguel,

What is the full JSON you are receiving the second time?

Cheers.

EDIT

P.S. I would say that when you consumed the rest method, the answer was not a full answer, so you are missing attributes, or most probably the answer has an attribute that sometimes comes as a single value, and sometimes comes as an array.

If it is the second situation, you need to change the attribute in the structure used to receive the data to be a list and pre-process the answer of the method to change the attribute to be an array if it comes as a single value.

Cheers.

Hello Eduardo, first of all I'm sorry for my English,
I'm like Miguel's problem, but I do not know how to solve it.
The API returns an attribute as array, but I do not know how to preprocess it.

My error is this: Failed to parse response of the method 'GetDemandAllAbjectsTodos' of the 'RedmineAPI' REST API: Parsing 'issues [0] .custom_fields [5] .value': Unexpected character encountered while parsing value: [. Path 'issues [0] .custom_fields [5] .value', line 1, position 2888. Parsing 'issues [0] .custom_fields [5]':


Hi Gabriel,

If you don't need this attribute, delete it from the structure. This will prevent OutSystems from trying to parse it.

If you need it, but it sometimes comes as a list and sometimes as something else (like a string, or integer), than it is more complex.

Add a new attribute to the structure of the method response that is of same type as the LIST you are receiving, but with a different name (remember to set a different name also for the JSON property of the attribute in the structure).

Than, add a OnAfterResponse method o the API.
You will receive the raw JSON and will have to return it. Just check the raw JSON if the attribute exists, and if it is a list, replace the name by the one you create the attribute.

This way the platform will be able to create the output without errors.

Cheers.