# How to implement Auth0's Direct Password Change feature using Management API in Django?

**URL:** <https://community.auth0.com/t/how-to-implement-auth0s-direct-password-change-feature-using-management-api-in-django/88861>\
**Category:** Get Help\
**Tags:** django, change-password, management-api, auth0\
**Created:** [August 16, 2022, 3:51pm UTC](https://community.auth0.com/t/how-to-implement-auth0s-direct-password-change-feature-using-management-api-in-django/88861 "2022-08-16T15:51:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![khubikhawar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/khubikhawar/32/35672_2.png) [@khubikhawar](https://community.auth0.com/u/khubikhawar)\
**Post date:** [August 16, 2022, 3:51pm UTC](https://community.auth0.com/t/how-to-implement-auth0s-direct-password-change-feature-using-management-api-in-django/88861/1 "2022-08-16T15:51:24Z")

</div>

Hi there,

I have a Django App, and I am trying to use Auth0 for my Django App’s authentication. I have successfully integrated Login and Logout using `social-auth-app-django` library. But I am facing a lot of hurdles in implementing Auth0’s Management API to use direct password change feature in Django? I tried to follow what this [Auth0’s official documentation’s link](https://auth0.com/docs/authenticate/database-connections/password-change#directly-set-the-new-password) says to implement Auth0’s Management API for direct password change feature, but it is throwing Error Code 500, and I am not understanding what I did wrong.

The link shows the following example to implement Auth0 Management API for firect password change feature in Django:

```auto
import http.client

conn = http.client.HTTPSConnection("")

payload = "{\"password\": \"NEW_PASSWORD\",\"connection\": \"CONNECTION_NAME\"}"

headers = { 'content-type': "application/json" }

conn.request("PATCH", "/dev-9fj5kydc.us.auth0.com/api/v2/users/USER_ID", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

```

And my implementation for the same is:

```auto
import http.client

user = self.request.user

NEW_PASSWORD = form.cleaned_data["new_password1"]
CONNECTION_NAME = settings.AUTH0_CONNECTION_NAME
DOMAIN = settings.SOCIAL_AUTH_AUTH0_DOMAIN
USER_ID = user.auth0_id
URL = f"/{DOMAIN}/api/v2/users/{USER_ID}"

conn = http.client.HTTPSConnection("")

payload = f"{{\"password\": \"{NEW_PASSWORD}\",\"connection\": \"{CONNECTION_NAME}\"}}" ### Here I am using 'Username-Password-Authentication' as Connection Name

headers = { 'content-type': "application/json" }

conn.request("PATCH", URL, payload, headers)

res = conn.getresponse()
data = res.read()

```

I have double checked that everything is fine by printing values in console and all variables hold correct values. Can someone help me and tell what wrong I am doing?

---

<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:47pm UTC](https://community.auth0.com/t/how-to-implement-auth0s-direct-password-change-feature-using-management-api-in-django/88861/3 "2022-08-26T21:47:16Z")

</div>

Hi @khubikhawar,

A 500 error may suggest you are hitting the wrong endpoint/domain.

It looks like the format of your request is a bit off, typically you would set the domain in your HTTPSConnection method.

(e.g. `http.client.HTTPSConnection("dev-9fj5kydc.us.auth0.com")`.

Here is a doc on how to make a request with that client: [Python HTTP Client Request - GET, POST | DigitalOcean](https://www.digitalocean.com/community/tutorials/python-http-client-request-get-post)

---

<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:02pm UTC](https://community.auth0.com/t/how-to-implement-auth0s-direct-password-change-feature-using-management-api-in-django/88861/4 "2022-09-30T23:02:29Z")

</div>

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