# How do I fix a 400 Client Error: Bad Request for url, when trying to update user?

**URL:** <https://community.auth0.com/t/how-do-i-fix-a-400-client-error-bad-request-for-url-when-trying-to-update-user/88831>\
**Category:** Get Help\
**Tags:** aws, api, aws-lambda, auth0\
**Created:** [August 16, 2022, 7:22am UTC](https://community.auth0.com/t/how-do-i-fix-a-400-client-error-bad-request-for-url-when-trying-to-update-user/88831 "2022-08-16T07:22:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jez\_D](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jez_d/32/33365_2.png) [@Jez\_D](https://community.auth0.com/u/Jez_D)\
**Post date:** [August 16, 2022, 7:22am UTC](https://community.auth0.com/t/how-do-i-fix-a-400-client-error-bad-request-for-url-when-trying-to-update-user/88831/1 "2022-08-16T07:22:22Z")

</div>

When I run this code from command line, it works as expected and the operation is successful:

```bash
curl -H "Authorization: Bearer <management_api_access_token>" -X PATCH -H "Content-Type: application/json" -d '{"blocked":false}' https://<my_domain>.eu.auth0.com/api/v2/users/<user_id-including-auth-provider>

```

When I run the equivalent python script locally, I also get the expected successful response:

```python
def do_this():
    user = "<user_id>"

    url = f"https://<my-domain>.eu.auth0.com/api/v2/users/{user}"

    payload = json.dumps({
      "blocked": True
    })
    headers = {
      "Authorization": "Bearer <management_api_access_token>",
      "Content-Type": "application/json",
      }

    response = requests.request("PATCH", url, headers=headers, data=payload)

    print(response.text)

```

However, when I run the python code in a lambda, I get this error:

> 400 Client Error: Bad Request for url: https://\<my\_domain\>.eu.auth0.com/api/v2/users/\<user\_id\>

I tried changing  
`requests.request("PATCH", url, headers=headers, data=payload)`  
to  
`requests.patch(url, data=payload, headers=headers)`

but still same error in lambda

I have tried switching the `user_id` from  
`auth0|xxxxxx`  
to  
`auth0%7Cxxxxx`  
but still get the same error in lambda

(`%7C` is urlencoding of the pipe “|”)

Other calls I make to other management api endpoints in lambda seem to work fine, such as  
`/api/v2/users-by-email`  
and  
`/api/v2/users`

What do I need to change in my code so that it will work universally?

I am working locally on MacOS, but my lambdas run in Linux.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 26, 2022, 9:34pm UTC](https://community.auth0.com/t/how-do-i-fix-a-400-client-error-bad-request-for-url-when-trying-to-update-user/88831/3 "2022-08-26T21:34:06Z")

</div>

Hi @Jez_D,

Welcome to the Auth0 Community!

Are you seeing any error message along with the Bad Request error? Typically you will see some more detail about why the request is failing. You may also want to check your Auth0 logs and see if there is any detail there.

Let me know,  
Dan

---

<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:** [September 30, 2022, 11:03pm UTC](https://community.auth0.com/t/how-do-i-fix-a-400-client-error-bad-request-for-url-when-trying-to-update-user/88831/4 "2022-09-30T23:03:29Z")

</div>

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