# How do I fix 422 Unprocessable Entity when sending JSON from JavaScript to an API?

**URL:** <https://community.auth0.com/t/how-do-i-fix-422-unprocessable-entity-when-sending-json-from-javascript-to-an-api/185734>\
**Category:** Dev to Dev Hub\
**Tags:** users, management-api\
**Created:** [April 21, 2025, 6:30am UTC](https://community.auth0.com/t/how-do-i-fix-422-unprocessable-entity-when-sending-json-from-javascript-to-an-api/185734 "2025-04-21T06:30:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![davissmith1224307](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/davissmith1224307/32/73401_2.png) [@davissmith1224307](https://community.auth0.com/u/davissmith1224307)\
**Post date:** [April 21, 2025, 6:30am UTC](https://community.auth0.com/t/how-do-i-fix-422-unprocessable-entity-when-sending-json-from-javascript-to-an-api/185734/1 "2025-04-21T06:30:28Z")

</div>

Hi everyone,

I’m trying to send JSON data to an API using JavaScript, but I keep running into a 422 Unprocessable Entity error. I’ve checked the request headers and payload format, and I’m not sure what’s going wrong. From what I understand so far, this error usually points to issues with the data structure or how it’s being interpreted by the API. While reading up on it, I found this [source](https://www.resultfirst.com/blog/http-status-code/422-status-code/) that breaks down the 422 status code and helped me get a better understanding of what might be causing it. Still, I’d like to hear from others—how do you usually approach and fix this?

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [April 22, 2025, 5:23pm UTC](https://community.auth0.com/t/how-do-i-fix-422-unprocessable-entity-when-sending-json-from-javascript-to-an-api/185734/3 "2025-04-22T17:23:18Z")

</div>

Hi @davissmith1224307

As far as my knowledge goes, the 422 error might be caused by not using the HTTP Bearer class available as mentioned in this [Github post](https://github.com/fastapi/fastapi/discussions/6821).

Otherwise, it might also be caused by the fact that you are trying to send a JSON file but the content type for the request headers expect a different format ( "`content-type": "application/x-www-form-urlencoded"`) as such:

```auto
response = client.post("/auth/token", data={"username": "johndoe", "password": "secret", "grant_type": "password"},
                           headers={"content-type": "application/x-www-form-urlencoded"})

```

I would advise to take a look at what type of format does your request headers expect you to be sending.

If you have any other questions, let me know!

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 6, 2025, 5:24pm UTC](https://community.auth0.com/t/how-do-i-fix-422-unprocessable-entity-when-sending-json-from-javascript-to-an-api/185734/4 "2025-05-06T17:24:08Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [September 5, 2025, 8:39pm UTC](https://community.auth0.com/t/how-do-i-fix-422-unprocessable-entity-when-sending-json-from-javascript-to-an-api/185734/5 "2025-09-05T20:39:37Z")

</div>


