# Access token-generation: API endpoint?

**URL:** <https://discuss.openedx.org/t/access-token-generation-api-endpoint/5067>\
**Category:** Development\
**Tags:** api\
**Created:** [June 1, 2021, 7:09pm UTC](https://discuss.openedx.org/t/access-token-generation-api-endpoint/5067 "2021-06-01T19:09:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PatM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/patm/32/2422_2.png) [@PatM](https://discuss.openedx.org/u/PatM)\
**Post date:** [June 1, 2021, 7:09pm UTC](https://discuss.openedx.org/t/access-token-generation-api-endpoint/5067/1 "2021-06-01T19:09:32Z")

</div>

_What is the API endpoint in Open EdX that can generate a new access token or refresh one for a user?_  
A dev colleague says this can be done via the command line easily, but has not found a document API endpoint for this.

---

<div class="post-metadata">

**Author:** ![braden](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/braden/32/46_2.png) [@braden](https://discuss.openedx.org/u/braden)\
**Post date:** [June 1, 2021, 8:11pm UTC](https://discuss.openedx.org/t/access-token-generation-api-endpoint/5067/2 "2021-06-01T20:11:44Z")

</div>

If you send a POST request to `(LMS domain)/oauth2/access_token` with form data consisting of valid credentials (`client_id`, `client_secret`, and `grant_type = client_credentials`) for an OAuth application that you’ve configured in the LMS django admin, you’ll get back an access token for your application’s user.

If you want to retrieve an access token on behalf of some other user, POST to the same endpoint but set `grant_type = refresh_token`, and pass the user’s `refresh_token` as a fourth data parameter.

There are examples of both [in this gist](https://gist.github.com/bradenmacdonald/930c7655dca32dc648af9cb0aed4a7c5#file-openedx_client-py-L217-L246) among other places.

A third way is to use a password instead of a refresh token, which can be helpful for development:

```auto
curl -X POST -d "client_id={client_id}&client_secret={client_secret}&grant_type=password&username=staff&password=edx" http://localhost:18000/oauth2/access_token/

```

---

<div class="post-metadata">

**Author:** ![PatM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/patm/32/2422_2.png) [@PatM](https://discuss.openedx.org/u/PatM)\
**Post date:** [June 1, 2021, 8:23pm UTC](https://discuss.openedx.org/t/access-token-generation-api-endpoint/5067/3 "2021-06-01T20:23:52Z")

</div>

Thanks Braden - I appreciate the prompt response!

---

<div class="post-metadata">

**Author:** ![Andres.Aulasneo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/andres.aulasneo/32/984_2.png) [@Andres.Aulasneo](https://discuss.openedx.org/u/Andres.Aulasneo)\
**Post date:** [June 8, 2021, 7:17pm UTC](https://discuss.openedx.org/t/access-token-generation-api-endpoint/5067/4 "2021-06-08T19:17:57Z")

</div>

Hi @PatM,  
I am working in [this python package](https://github.com/aulasneo/openedx-rest-api-client) to access the Open edX API out of Django. You can install with `pip install open-edx-rest-api-client`. It has only two functions implemented yet (one to list all courses and another to enroll users), but you can use the session object that handles the authentication.

---

<div class="post-metadata">

**Author:** ![PatM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/patm/32/2422_2.png) [@PatM](https://discuss.openedx.org/u/PatM)\
**Post date:** [June 8, 2021, 8:35pm UTC](https://discuss.openedx.org/t/access-token-generation-api-endpoint/5067/5 "2021-06-08T20:35:24Z")

</div>

Hi Andres - thanks for the follow-up!  
The Python link gives me a 404 - can you add the updated link?  
Pat  
@andres

---

<div class="post-metadata">

**Author:** ![Andres.Aulasneo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/andres.aulasneo/32/984_2.png) [@Andres.Aulasneo](https://discuss.openedx.org/u/Andres.Aulasneo)\
**Post date:** [June 9, 2021, 1:48pm UTC](https://discuss.openedx.org/t/access-token-generation-api-endpoint/5067/6 "2021-06-09T13:48:29Z")

</div>

Hi @PatM, try again, I had forgotten to set it to public.
