17
Views
6
Comments
Solved
Consume REST with recursive structure
Question

Hello people!

I am working on implementing a tree that contains a Parent Category and other Subcategories that are children of that parent. Thus creating a recursive structure.

There is a REST service, which returns the attached JSON to me. I created a structure to consume this JSON.

However, it happens to break up after the BeforeRequest.

 

JSON:


{

  "items": [

    {

      "name": "Esportes",

      "definition": {

        "name": "SVod",

        "createdBy": null,

        "modifiedBy": null,

        "createdDate": "0001-01-01T00:00:00+00:00",

        "modifiedDate": null,

        "id": "2"

      },

      "parent": null,

      "children": [

        {

          "name": "Futebol",

          "definition": {

            "name": "SVod",

            "createdBy": null,

            "modifiedBy": null,

            "createdDate": "0001-01-01T00:00:00+00:00",

            "modifiedDate": null,

            "id": "2"

          },

          "parent": null,

          "children": [

            {

              "name": "Futebol Brasileiro",

              "definition": {

                "name": "SVod",

                "createdBy": null,

                "modifiedBy": null,

                "createdDate": "0001-01-01T00:00:00+00:00",

                "modifiedDate": null,

                "id": "2"

              },

              "parent": null,

              "children": [],

              "path": "Esportes/Futebol/Brasileiro",

              "sortOrder": 1,

              "status": 1,

              "isCatchUp": false,

              "isManualOrder": false,

              "isLongTail": false,

              "notes": null,

              "createdBy": "xdlta99",

              "modifiedBy": null,

              "createdDate": "2020-07-29T10:37:55.0406127+01:00",

              "modifiedDate": "2020-07-29T10:37:55.0406127+01:00",

              "id": "4"

            },

            {

              "name": "Futebol Português",

              "definition": {

                "name": "SVod",

                "createdBy": null,

                "modifiedBy": null,

                "createdDate": "0001-01-01T00:00:00+00:00",

                "modifiedDate": null,

                "id": "2"

              },

              "parent": null,

              "children": [],

              "path": "Esportes/Futebol/Português",

              "sortOrder": 1,

              "status": 1,

              "isCatchUp": false,

              "isManualOrder": false,

              "isLongTail": false,

              "notes": null,

              "createdBy": "xdlta99",

              "modifiedBy": null,

              "createdDate": "2020-07-29T11:10:35.5978793+01:00",

              "modifiedDate": "2020-07-29T11:10:35.5978793+01:00",

              "id": "5"

            }

          ],

          "path": "Esportes/Futebol",

          "sortOrder": 1,

          "status": 1,

          "isCatchUp": false,

          "isManualOrder": false,

          "isLongTail": false,

          "notes": null,

          "createdBy": "xdlta99",

          "modifiedBy": null,

          "createdDate": "2020-07-29T10:22:31.2113171+01:00",

          "modifiedDate": "2020-07-29T10:22:31.2113171+01:00",

          "id": "3"

        }

      ],

      "path": "Esportes",

      "sortOrder": 1,

      "status": 1,

      "isCatchUp": false,

      "isManualOrder": false,

      "isLongTail": false,

      "notes": null,

      "createdBy": null,

      "modifiedBy": null,

      "createdDate": "2020-07-29T10:12:25.9380498+01:00",

      "modifiedDate": "2020-07-29T10:12:25.9380498+01:00",

      "id": "1"

    },

    {

      "name": "Desenhos",

      "definition": {

        "name": "TVodBundle",

        "createdBy": null,

        "modifiedBy": null,

        "createdDate": "0001-01-01T00:00:00+00:00",

        "modifiedDate": null,

        "id": "5"

      },

      "parent": null,

      "children": [],

      "path": "Desenhos",

      "sortOrder": 1,

      "status": 1,

      "isCatchUp": false,

      "isManualOrder": false,

      "isLongTail": false,

      "notes": null,

      "createdBy": "xdltb53",

      "modifiedBy": null,

      "createdDate": "2020-09-23T16:37:37.7930165+01:00",

      "modifiedDate": "2020-09-23T16:37:37.7930165+01:00",

      "id": "20"

    },

    {

      "name": "Novelas",

      "definition": {

        "name": "TVodBundle",

        "createdBy": null,

        "modifiedBy": null,

        "createdDate": "0001-01-01T00:00:00+00:00",

        "modifiedDate": null,

        "id": "5"

      },

      "parent": null,

      "children": [],

      "path": "Novelas",

      "sortOrder": 1,

      "status": 1,

      "isCatchUp": false,

      "isManualOrder": false,

      "isLongTail": false,

      "notes": null,

      "createdBy": "xdltb53",

      "modifiedBy": null,

      "createdDate": "2020-09-23T20:32:43.0574884+01:00",

      "modifiedDate": "2020-09-23T20:32:43.0574884+01:00",

      "id": "21"

    },

    {

      "name": "Novidades",

      "definition": {

        "name": "TVodBundle",

        "createdBy": null,

        "modifiedBy": null,

        "createdDate": "0001-01-01T00:00:00+00:00",

        "modifiedDate": null,

        "id": "5"

      },

      "parent": null,

      "children": [],

      "path": "Novidades",

      "sortOrder": 1,

      "status": 1,

      "isCatchUp": false,

      "isManualOrder": false,

      "isLongTail": false,

      "notes": null,

      "createdBy": "xdltb53",

      "modifiedBy": null,

      "createdDate": "2020-09-23T20:54:44.8355712+01:00",

      "modifiedDate": "2020-09-23T20:54:44.8355712+01:00",

      "id": "22"

    },

    {

      "name": "Entretenimento",

      "definition": {

        "name": "SVod",

        "createdBy": null,

        "modifiedBy": null,

        "createdDate": "0001-01-01T00:00:00+00:00",

        "modifiedDate": null,

        "id": "2"

      },

      "parent": null,

      "children": [],

      "path": "Entretenimento",

      "sortOrder": 1,

      "status": 2,

      "isCatchUp": true,

      "isManualOrder": true,

      "isLongTail": true,

      "notes": "notes test",

      "createdBy": "xdlta99",

      "modifiedBy": null,

      "createdDate": "2020-09-28T09:13:01.6709255+01:00",

      "modifiedDate": "2020-09-28T09:13:01.6709255+01:00",

      "id": "23"

    },

    {

      "name": "Destaques",

      "definition": {

        "name": "SVod",

        "createdBy": null,

        "modifiedBy": null,

        "createdDate": "0001-01-01T00:00:00+00:00",

        "modifiedDate": null,

        "id": "2"

      },

      "parent": null,

      "children": [],

      "path": "Destaques",

      "sortOrder": 2,

      "status": 1,

      "isCatchUp": false,

      "isManualOrder": false,

      "isLongTail": false,

      "notes": null,

      "createdBy": "xdlta99",

      "modifiedBy": null,

      "createdDate": "2020-08-04T11:09:41.8243852+01:00",

      "modifiedDate": "2020-08-04T11:09:41.8243852+01:00",

      "id": "19"

    }

  ],

  "itemCount": 6


}

This is the error that the Service Center returns to me.

Rank: #133
Solution

Hi Danilo,


I made a mock service which returns your JSON output and I managed to consume it in OutSystems.

I will attach the OML so you can see the service and structure to match that output.


Hope it helps.


Cheers,

João


test.oml

Rank: #15060

Rank: #133

Hi Danilo,


By your error, it seems like the answer of the REST you're trying to consume does not fit the Response structure output you define. Given the size of the response and the number of errors you have, it's hard to pinpoint the exact problem.

What I usually do to avoid having mismatches between those is testing the web method (just double click your Web Method GetCategories), fill in the inputs and test the call.

Once you see the result you expect, use OutSystems Copy to Response Body feature. With this OutSystems will automatically arrange the output structure fitting that response, see example below:


Perhaps you wanna try this approach and let OutSystems do the match.


Hope it helps.


Cheers,

João

Rank: #15060

Thanks for the reply João Marques!


I do just that. I believe that OutSystems is not behaving well when recognizing this Childrens recursive structure.

Rank: #133
Solution

Hi Danilo,


I made a mock service which returns your JSON output and I managed to consume it in OutSystems.

I will attach the OML so you can see the service and structure to match that output.


Hope it helps.


Cheers,

João


test.oml

Rank: #15060

João Marques,


Exactly! What I was doing wrong, was that my Children property in Items. It was just like ChildItem. I noticed that in the mock structure you sent, the property was a list, a ChildItem List.


Many thanks for the reply!

Rank: #133

Great!


I'm glad I could help :)


Kind regards,

João