61
Views
8
Comments
Solved
Consumed API gives different Response structures based on Input value how to handle
Question
Application Type
Reactive

Hello,

I am consuming one API which fetched the  table data (Output response) based on the tableName(Input request)

"cmmn_fwdr_lkup table"  and "DEVY_TYPE_lkup" are the table names(request param) being passed and gives response shown below.

Here the response structure is different for these two different input values.


how to manage the response structure is there any way to use this API only once based on changed input I dont want to make different API and respective response structures .


Thanks,

Shivani

2019-01-07 16-04-16
Siya
 
MVP
Solution

You just call the API the way it is normally called. Change to do done in Service Studio -> Consume REST API . Here after you do the Test set the Body -> Response as "" and Click Finish.

Then you create a Sever action where you will invoke your API and post that result should be deserialise to respective structure.

Attached a small video of how this done.

demo.mp4
2024-09-20 14-44-46
Shivani Desai
Solution

I have created one structure with all attributes from the response (combined the attribute in one structure) and kept there json name same as json response 

Then I am able to get the result as expected,


Thanks,

Shivani 

2024-09-20 14-44-46
Shivani Desai
Solution

I have created one structure with all attributes from the response (combined the attribute in one structure) and kept there json name same as json response 

Then I am able to get the result as expected,


Thanks,

Shivani 

2023-09-28 14-21-55
Daryna Kravets

Hi Shivani,

If the possible structures are similar and known in advance, you can create a single structure to cover all the variations. 

Otherwise, I'd suggest to receive the response as a plain text and implement your own logic to parse it.

2024-09-20 14-44-46
Shivani Desai


I am doing something like above please let me know any other possible way or if I missed something


Thanks,

Shivani

2021-08-04 12-19-54
Mayank Dharmpurikar

Hi Shivani,

From the response json, I can understand you have dynamic list of attributes.

Could you check ardoJSON that has JSON_Listify action which can be used to convert the dynamic list of attributes into a list of key-value pairs.

check this article for detail implementation.

2024-09-20 14-44-46
Shivani Desai

Could you please elaborate more How can I implement in my case, quite difficult to understand?

Thanks Mayank!


Regards,

Shivani

2019-01-07 16-04-16
Siya
 
MVP

I recommend separating the API call from the process of converting the result into the respective structure. After invoking the API, you should receive the result as plain text. Then, based on the input provided, for example, "DEVY_TYPE_lkup", deserialize the result into the corresponding structure. 

2024-09-20 14-44-46
Shivani Desai

No I have set response type as text/plain but Its giving error at the API call itself,

do you mean I should consume same API two times with different response structure ? Actually I have such 5 different cases,

please check below o/p if I set type test/plain

Thanks,

Shivani

2019-01-07 16-04-16
Siya
 
MVP
Solution

You just call the API the way it is normally called. Change to do done in Service Studio -> Consume REST API . Here after you do the Test set the Body -> Response as "" and Click Finish.

Then you create a Sever action where you will invoke your API and post that result should be deserialise to respective structure.

Attached a small video of how this done.

demo.mp4
2024-09-20 14-44-46
Shivani Desai
Solution

I have created one structure with all attributes from the response (combined the attribute in one structure) and kept there json name same as json response 

Then I am able to get the result as expected,


Thanks,

Shivani 

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