Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Sriram151515
Contributor
Contributor

tREST API Call - Dynamic JSON Message Body

Hi All,

I have an urgent requirement where I would need to use the tREST component for making a API call to a MDM platform.

For this I would need to pass a JSON as a message body to the tREST component. Based on the response I would need to update the initial JSON message body and pass it again to obtain the next response. Like wise, this iteration will go on until all the records are fetched.

Now, updating the JSON message body based on the response obtained is where I am having the difficulty.

Basically the update here is to remove an attribute from the original JSON and add a new attribute to it. and the value of the newly added attribute will vary based on the response obtained for every iteration.

Could you please suggest some ways for JSON updating.

6 Replies
Anonymous
Not applicable

Hi

Can you show us an example to explain the Json message format and where need to be updated?

 

Regards

Shong

Sriram151515
Contributor
Contributor
Author

0695b00000EaEuuAAF.jpg0695b00000EaEukAAF.jpgHi Shong,

Thanks for the response.

Please find attached screenshots,

The initial_json_body.jpg screenshot is the message body to be used for initial rest api call. The response from the api call will contain the scrollId. I have fetched that and stored in a context variable. That value is to be used for the subsequent api calls with the updated json message body.

Sriram151515
Contributor
Contributor
Author

@Shicong Hong​ : Any updates on this would be really helpful. Thanks

Anonymous
Not applicable

Hi

 

I have two ways you can try.

1 Extract all the data from json message in the beginning and rewrite the Json message using tWriteJsonField after extract the scrollId.

2 Hard code to replace the string between "scroll_id" and "query" with new scrollId value.

 

Regards

Shong

Sriram151515
Contributor
Contributor
Author

@Shicong Hong​ : Thanks for the update Shong. The second way hard coding the scroll id might not work out because the number of iterations is expected to go roughly to 70-100. So each time we need to hard code the scroll id obtained from the response.

I will give a try with the first method using twriteJson after extracting the values. Any examples would be helpful.

Alternatively, is there a way we could write some code using tJavaRow or TJava to replace the attribute from original json i.e "scroll" with "scroll_id" as expected in the updated json and then keep updating them inside tjavarow/tjava.

Anonymous
Not applicable

Here is a scenario about tWriteJsonField component, take a look at the documentation and learn it. Let me know if you have any questions.

If you know Java knowledge, you want replace the attribute from original on tJava component.

 

Regards

Shong