56
Views
3
Comments
Use information from request body in response
Question

Hello,

I have a REST API and I get requests, but to trail an error I want to put the ID given in the request body into the reponse, but I'm unable to do so since the OnReponse method doesn't have access to the variables of my REST API method. I have looked at global variables, but other than site properties I don't think there's any and from other posts, it seems that using site properties for this purpose is not advised at all.

TL;DR How am I able to access REST API Method variables in my OnResponse?

Thanks in advance!

2024-05-08 06-29-37
Prince Aadil Khan Panwar

Hi @Anton Engels 

try to share your OML. or try to read my blog. this may help. 

https://medium.com/@prince.panwar/how-to-consume-and-expose-rest-api-in-outsystems-eee1a90ef9af

Regards,

Prince

UserImage.jpg
Anton Engels

Hello,

I'm unable to share the OML since this contains company information. I've read your blog, but it hasn't helped me as it doesn't go over custom REST API responses which is what I was asking for.

In case my question wasn't clear, I need to give a custom response to my API request and I would like to include data from the request body, but I'm unable to access the variables from the API request method in my OnResponse method. I would either need a global variable or some way to share variables between methods.

2021-10-09 07-57-44
Stefan Weber
 
MVP

Hi Anton,

the short answer would be that in the OnResponse you do not have access to the original request.

In an OnRequest you have the full payload in both text and binary representation.

At the endpoint level - your action that processes the request - you can use a structure to deserialize the whole or just a part of the payload. I guess you are already doing that. At the same level you define an output, which is in most cases again a structure.

After your action reached a succesful end that output is now serialized to text and transformed to binary. 

So in the OnResponse you only have the text and binary representation of what was the result of you endpoint action.

In your case and if it is just about ADDING an additional Id field to your response, you would just have to add another property "id" to your output structure. You would then assign the value of your request to that output property.

Stefan


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