18
Views
3
Comments
Solved
Use entity data to call Rest api

Hi

I am Outsystems beginner, so sorry for for my questions

I am trying consume a rest API, that should give me the result obout some network situation 

The most of it works, but now i have troubles. To get the uplink situation from all my networks, i need call a rest api where i use two vaiables, that i get in another call. this call is saving all my networks in one entity. Now i want to iterate through all my networks, and get the uplink data. So i will take line by line in the network table, and then use the network id, and serial variable in the api call, to get my uplink

It works, but not right, because it only takes the wan 1 port and not the wan 2 port

if i call the api, with some static, it gives this json output

[

    {

        "interface": "WAN 1",

        "status": "Active",

     

    },

    {

        "interface": "WAN 2",

        "status": "Ready",

        

    }


]


but when i use it in Outsystems, i only get the WAN 1.

So i do something wrong ;-)


My actions is like this


Someone that can help me


Thanks

Rank: #116
Solution

Hello Klaus,

Hope you're doing well.

So, you call firstly an API which returns all of the networks. Then you save this information into Devices entity.

After this, you want to iterate this list with the information of your networks (picking the NetworkID and Serial Number) to call another API DeviceUpLink using this data.

But when you want to save the result of your DeviceUpLink API (which brings a JSON with those 2 interfaces), you are only saving the first element (in this case, for interface WAN 1) in your Device_GetUplinkInfo entity.


Most likely, you are receiving the correct response from the API (the JSON with both interfaces). If the parameters are correct, then the response should be correct as well :)

But when you're saving into your Device_GetUplinkInfo entity, you are just pointing to the first position of the response list in the assign right after the call to the API. You need to iterate over the response list and save both of the elements in your entity. So you'll need an extra loop to do this iteration, and you should have an assign for the current element information and the CreateDevice_GetUplinkInfo action.


This way will allow you to save both of your elements in the database, one iteration for each element.


Let me know if it worked for you!


Kind regards,

Rui Barradas

Hi there,


Since the API call responds with a list, you will need to iterate through the response and do an assignment and crud foreach record in the list.


Sam

Rank: #116
Solution

Hello Klaus,

Hope you're doing well.

So, you call firstly an API which returns all of the networks. Then you save this information into Devices entity.

After this, you want to iterate this list with the information of your networks (picking the NetworkID and Serial Number) to call another API DeviceUpLink using this data.

But when you want to save the result of your DeviceUpLink API (which brings a JSON with those 2 interfaces), you are only saving the first element (in this case, for interface WAN 1) in your Device_GetUplinkInfo entity.


Most likely, you are receiving the correct response from the API (the JSON with both interfaces). If the parameters are correct, then the response should be correct as well :)

But when you're saving into your Device_GetUplinkInfo entity, you are just pointing to the first position of the response list in the assign right after the call to the API. You need to iterate over the response list and save both of the elements in your entity. So you'll need an extra loop to do this iteration, and you should have an assign for the current element information and the CreateDevice_GetUplinkInfo action.


This way will allow you to save both of your elements in the database, one iteration for each element.


Let me know if it worked for you!


Kind regards,

Rui Barradas