229
Views
8
Comments
Solved
Exposing APIs with validations

Hi,

I am needing to expose APIs from OutSystems but these will need a lot of validations done. I have read on the forum that even if your input structure for a POST API has length set for fields and IsMandatory, that OS does not actually validate these and just accepts all inputs - which is a bit of a problem. So I am hoping there is a way to validate these myself by somehow accessing the structure of the input and comparing it's rules (such as length, data type and IsMandatory) to the input in that structure...

Is there any way to do this perhaps using JavaScript? Is there a way I can access this meta data of this structure using code so that I can compare it?

Thanks in advance!

Nic

2021-04-17 09-53-48
José Gonçalves
Solution

There is no auto validation, you need to do it manually input by input.

2020-09-01 10-42-42
Stefano Valente
Solution

Outsystems works with JSON preferably. In REST/JSON there is no standard validation method as far as i know.

For XML you can implement an XSD and validate content with that XSD. In Outsystems you can do that too ofcourse.


So, i am afraid you will have to create your own validation action.

2021-04-17 09-53-48
José Gonçalves

Hi Nicholas,

if you're using REST APIs you can use callbacks (OnRequest) to perform those validations even before the request reaches your API.

Regards

2020-09-01 10-42-42
Stefano Valente

Yes you can, but i am not sure if this is the best place to do that.

- The OnRequest is the same for all methods.

- The OnRequest will be triggered even before the OnAuthorization.


Why not perform the valiation of the input of the attributes of your structure inside the method itself?

2021-04-17 09-53-48
José Gonçalves

Yes you're right, I was thinking only for 1 API case.

Inside the method should work better.

2022-11-02 07-18-33
Nicholas Campbell

Hi all,

Thanks for the replies. However, I am not concerned about where I validate the inputs but how...

I am wanting to find an easier way to check the mandatory attributes than using an IF statement for each of them, I would like to somehow use the settings I already made within the input structure to test things like IsMandatory, length, DataType etc.

Any ideas?

2021-04-17 09-53-48
José Gonçalves
Solution

There is no auto validation, you need to do it manually input by input.

2022-11-02 07-18-33
Nicholas Campbell

Thanks, that is quite a pity. And is there a possibility to access the meta data of the structure in the browser using JavaScript to see if it should be Mandatory or do I have to pre-program that check manually?

2020-09-01 10-42-42
Stefano Valente
Solution

Outsystems works with JSON preferably. In REST/JSON there is no standard validation method as far as i know.

For XML you can implement an XSD and validate content with that XSD. In Outsystems you can do that too ofcourse.


So, i am afraid you will have to create your own validation action.

2020-09-01 10-42-42
Stefano Valente


With mandatory you would only check if the JSON field exists in the request. But if it exists and someone sends "", it would be valid. 


I don't think you can avoid doing the validation yourself. 

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