Consume Rest API x-www-form-urlencoded - Token Authorization - Getting Error 422
Application Type
Reactive, Service

Hello, I'm try consume a customer API.

I am trying to get token.  

In postman and service studio test API, works fine! Getting token, but in runtime is not working. GET Response Error Code 422 Unprocessable Entity.

The Screenshot for the test API.

Input and output parameters
Request send in Body 



Request Runtime


HTTP Error 


Please, ideas to resolve this

Sending test environment OML

Thank you in advance

Solution

Hi Marcelo,

I have made some changes to your OML. I hope this helps you to implement further.

TestPostToken.oml

Hello @Marcelo,

here you have to do  to pass this request on OnBeforeRequest , I am sharing some snapshots that might help

Click On the Rest Api Got to Advance Options there Go to On Before Request on that

Drag and drop a assign and on assign On your request pass your request






Pass Your request here, you can use it after that it will work


You can also refer to this - 

https://www.outsystems.com/forums/discussion/36156/guide-consume-rest-api-with-form-url-encoded-request/


Hope this helps

Thanks

Hi Tousif Khan

Thank you, for the quick answer.

I put it according to your comment and the error 422 still persists.



Request.RequestText = "grant_type=client_credentials" + "&username=" + username + "&password=" + password + "&client_id=" + ClientId


TestPostToken.oml

Hello

there was some issue with your request actually your request was taking input with double quotes 

"", so using some logic of string literals , I have fixed it now you can check it is working

TestPostTokenFixed.oml

Solution

Hi Marcelo,

I have made some changes to your OML. I hope this helps you to implement further.

TestPostToken.oml

Remove preceeding and ending double quotes in your request.

Request body in Outsystems API Editor is not an expression. 

Thank you all for the help
The problem was the quotes on request


Solved

Yes your request is inclosed with double quotes, thats why we are getting error,

and so we have to provide extra "" to inclose it again

best part problem is solved. 

cheers

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