Error Message REST API
Question

Hi everyone,

I am recently trying to consume Woo Commerce REST API for products, It is successfully retrieve the JSON list and structure. However, I am still facing below Error Message to show Product info.

Could someone help to explain what is the error message for?

Thanks

Stan

Hi Stanley,

Is it possible for you to send us the contents of the JSON, or a small example of what you're trying to achieve?

Thank you very much in advance.

Best regards,

Paulo Moreira

Hi Moreira,

Thank you for your reply. I am trying to copy the part of the JSON list and below is one of the products I retrieve from consume REST API. Sorry for looking messy for the code I copied.


[  {    "id": 236,    "name": "6+1",    "slug": "61",    "permalink": "https://koofam.com/product/61/",    "date_created": "2022-02-10T18:35:05",    "date_created_gmt": "2022-02-10T10:35:05",    "date_modified": "2022-02-10T18:35:07",    "date_modified_gmt": "2022-02-10T10:35:07",    "type": "simple",    "status": "publish",    "featured": false,    "catalog_visibility": "visible",    "description": "

買6包香麻蘿蔔乾,送1包琥珀合桃!!!

\n",    "short_description": "",    "sku": "",    "price": "468",    "regular_price": "468",    "sale_price": "",    "date_on_sale_from": null,    "date_on_sale_from_gmt": null,    "date_on_sale_to": null,    "date_on_sale_to_gmt": null,    "on_sale": false,    "purchasable": true,    "total_sales": 0,    "virtual": false,    "downloadable": false,    "downloads": [],    "download_limit": -1,    "download_expiry": -1,    "external_url": "",    "button_text": "",    "tax_status": "taxable",    "tax_class": "",    "manage_stock": false,    "stock_quantity": null,    "backorders": "no",    "backorders_allowed": false,    "backordered": false,    "low_stock_amount": null,    "sold_individually": false,    "weight": "",    "dimensions": {      "length": "",      "width": "",      "height": ""    },    "shipping_required": true,    "shipping_taxable": true,    "shipping_class": "",    "shipping_class_id": 0,    "reviews_allowed": true,    "average_rating": "0.00",    "rating_count": 0,    "upsell_ids": [],    "cross_sell_ids": [],    "parent_id": 0,    "purchase_note": "",    "categories": [      {        "id": 15,        "name": "未分類",        "slug": "uncategorized"      }    ],    "tags": [],    "images": [      {        "id": 234,        "date_created": "2022-02-11T02:27:56",        "date_created_gmt": "2022-02-10T10:27:56",        "date_modified": "2022-02-11T02:33:36",        "date_modified_gmt": "2022-02-10T10:33:36",        "src": "https://koofam.com/wp-content/uploads/2022/02/WhatsApp-Image-2022-02-10-at-6.24.10-PM.jpeg",        "name": "6+1",        "alt": "6+1"      }    ],    "attributes": [],    "default_attributes": [],    "variations": [],    "grouped_products": [],    "menu_order": 0,    "price_html": "$468.00",    "related_ids": [      233    ],    "meta_data": [      {        "id": 1695,        "key": "_wp_page_template",        "value": "default"      },      {        "id": 1696,        "key": "wc_productdata_options",        "value": [          {            "_product_block": "0",            "_top_content": "",            "_bottom_content": "",            "_bubble_new": "",            "_bubble_text": "",            "_custom_tab_title": "",            "_custom_tab": "",            "_product_video": "",            "_product_video_size": "",            "_product_video_placement": ""          }        ]      }    ],    "stock_status": "instock",    "_links": {      "self": [        {          "href": "https://koofam.com/wp-json/wc/v3/products/236"        }      ],      "collection": [        {          "href": "https://koofam.com/wp-json/wc/v3/products"        }      ]    }  },


Thanks

Stan

Hi Stanley,

Can you provide a small OML with an example of what you're trying to achieve?

Thank you very much in advance.

Best regards,

Paulo Moreira

Hi Moreira,

Sorry for reply late due to busy before. I don't know what is OML. Could you provide more info how could I retrieve and provide OML?

Thanks

Stan

mvp_badge
MVP

Hi Stanley,

Very likely, the REST service returns two different structures, one without a list, and one with a list, depending on certain conditions. The parsing error on '[' is the giveaway. These are difficult things to fix, typically needing an OnAfterResponse in which you fix the JSON so OutSystems can parse it. Alternatively, your structures may just be wrong and you need to fix them.

Hi Hekhuis,

Thank you for your reply.

On how to fix the structures, do you have any documents to fix my problem?

Thanks

Stan

mvp_badge
MVP

There's only the general documentation, not on this particular problem. Also, without having a good API description and your OML that consumes the REST, it's impossible to give good advise, other than very generic. Your structure attributes must line up with the REST output, and the types must also be the same. Like I said, you are served a list of things, but your attribute is not a list, that's where the parsing error comes from. But I don't know whether that's because you just defined your attribute wrong, or whether it's a polymorphic output (i.e. one attribute can be returned as both a single item or a list).

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.