15
Views
3
Comments
Solved
API 422 error
Question

Hi all. I have a Python code here to do a POST API for getting cookies during login. It works well in the Python code, but when I try to implement this into OutSystems, I get a 422 error instead.

# Create a session to handle cookies
session = requests.Session()

# Prepare the payload
payload = {    "username": username,    "password": password}

# Send the POST request
response = session.post(url, data=payload,verify=False)


Is there anything that I have missed to add? Thanks.


(Even if I add the username and password in the body content, it will still show 422 error.)


UserImage.jpg
Kwan Yat MOK
Solution

The problem is solved.

Have to set the Content-Type as "application/x-www-form-urlencoded", and Accept as "application/json". Then, in the body request, write 'grant_type=&username=nkymok&password=[***]&client_id=&client_secret='


Thanks all for your help


ref: https://github.com/fastapi/full-stack-fastapi-template/issues/431 

2025-04-15 04-00-33
Prakhar Sharma

Hi @Kwan Yat MOK ,

Usually you would get a 422 when there is any invalid data for which you are trying to process the request. 

Try to set the Authentication to "No Authentication" and then pass the username and password only in the body (Please let me know if you are already doing this)

2025-01-31 03-15-38
Irfan Ahamed Abdul Shukoor

Hi @Kwan Yat MOK ,

I believe, the JSON is a valid one, but the content is Unprocessable. Can you recheck what you are trying to achieve?

There is one similar case but in traditional check this also.

https://www.outsystems.com/forums/discussion/67314/error-code-422-unprocessable-entity/


Thanks 

UserImage.jpg
Kwan Yat MOK
Solution

The problem is solved.

Have to set the Content-Type as "application/x-www-form-urlencoded", and Accept as "application/json". Then, in the body request, write 'grant_type=&username=nkymok&password=[***]&client_id=&client_secret='


Thanks all for your help


ref: https://github.com/fastapi/full-stack-fastapi-template/issues/431 

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