# API: enrol user in a course

**URL:** https://discuss.openedx.org/t/api-enrol-user-in-a-course/7840
**Category:** Development
**Created:** [July 17, 2022, 9:48pm UTC](https://discuss.openedx.org/t/api-enrol-user-in-a-course/7840 "2022-07-17T21:48:37Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mslyon](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mslyon](https://discuss.openedx.org/u/mslyon)
#### Post date: [July 17, 2022, 9:48pm UTC](https://discuss.openedx.org/t/api-enrol-user-in-a-course/7840/1 "2022-07-17T21:48:37Z")

</div>

I spent a considerable amount of time trying to use an API that would enrol a user in a course.  
To start with I checked this link [Enrollment API Enrollment Resource — Open edX Platform APIs 0.1 documentation](https://docs.huihoo.com/edx/open-edx-platform-api/enrollment/enrollment.html#view-and-add-to-a-users-course-enrollments) and it seems it is possible to view list of courses only for the authenticated user but NOT for another user - am I wrong?

Also, for many API endpoints I get {  
“detail”: “Authentication credentials were not provided.”  
}

although I followed all the steps to get all working properly - see the image…

Am I doing something wronglY/

 ![image](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/c/c8d78093923e58a0f7f92b1847974a544b4149a7.png)

---

<div class="post-metadata">

### Author: ![Zia\_Fazal](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/zia_fazal/32/2259_2.png) [@Zia\_Fazal](https://discuss.openedx.org/u/Zia_Fazal)
#### Post date: [July 19, 2022, 9:39am UTC](https://discuss.openedx.org/t/api-enrol-user-in-a-course/7840/2 "2022-07-19T09:39:32Z")

</div>

Hi @mslyon

This [thread](https://discuss.openedx.org/t/authentication-credentials-were-not-provided/6519/2) might help you in resolving authentication issue.

---

<div class="post-metadata">

### Author: ![mslyon](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mslyon](https://discuss.openedx.org/u/mslyon)
#### Post date: [July 19, 2022, 9:57am UTC](https://discuss.openedx.org/t/api-enrol-user-in-a-course/7840/3 "2022-07-19T09:57:19Z")

</div>

thanks. Yes I have seent it also before but I’m not sure what exactly is API\_KEY?  
Is it the private key?  
HTTP\_X\_EDX\_API\_KEY: PUT\_YOUR\_API\_KEY\_HERE

---

<div class="post-metadata">

### Author: ![Zia\_Fazal](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/zia_fazal/32/2259_2.png) [@Zia\_Fazal](https://discuss.openedx.org/u/Zia_Fazal)
#### Post date: [July 19, 2022, 10:01am UTC](https://discuss.openedx.org/t/api-enrol-user-in-a-course/7840/4 "2022-07-19T10:01:34Z")

</div>

`EDX_API_KEY` can a be string key should be something like a pass phrase. Check what you have set in settings of your LMS or set it if not set. Then send same value in `HTTP-X-EDX-API-KEY` header when calling API.

---

<div class="post-metadata">

### Author: ![mslyon](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mslyon](https://discuss.openedx.org/u/mslyon)
#### Post date: [July 19, 2022, 10:36am UTC](https://discuss.openedx.org/t/api-enrol-user-in-a-course/7840/5 "2022-07-19T10:36:42Z")

</div>

thanks a lot but I’m still struggling…  
this is what I did:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/9/9bfc8044b65a9994a8ddc0a0c28d883d6cf23694.png)

and this

 ![image](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/b/bbd30fff440171b977964ad68971d6938f20748f.png)

but it still says  
{  
“detail”: “Authentication credentials were not provided.”  
}

I tried also with curl but same…

any idea? what am I doing wrongly?

---

<div class="post-metadata">

### Author: ![mslyon](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mslyon](https://discuss.openedx.org/u/mslyon)
#### Post date: [July 19, 2022, 10:45am UTC](https://discuss.openedx.org/t/api-enrol-user-in-a-course/7840/6 "2022-07-19T10:45:28Z")

</div>

finally I found…posting here the way I managed to make it work…

curl [https://example.com/api/enrollment/v1/enrollment?user=USERNAME](https://example.com/api/enrollment/v1/enrollment?user=USERNAME) -H “X-EDX-API-KEY: key\_goes here”

---

<div class="post-metadata">

### Author: ![mslyon](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mslyon](https://discuss.openedx.org/u/mslyon)
#### Post date: [July 19, 2022, 2:48pm UTC](https://discuss.openedx.org/t/api-enrol-user-in-a-course/7840/7 "2022-07-19T14:48:17Z")

</div>

However, when I do the same with API bulk\_enroll this does not work anymore

curl -d “[auto\_enroll=true&email\_students=true&action=enroll&courses=course-v1:xxxx&identifiers=example@gmail.com](mailto:auto_enroll=true&email_students=true&action=enroll&courses=course-v1:xxxx&identifiers=example@gmail.com)” -X POST [https://example.com/api/bulk\_enroll/v1/bulk\_enroll](https://example.com/api/bulk_enroll/v1/bulk_enroll) -H “X-EDX-API-KEY: cxxxx”

I get {“detail”:“Authentication credentials were not provided.”}

Any idea whis is so?

---

<div class="post-metadata">

### Author: ![mslyon](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mslyon](https://discuss.openedx.org/u/mslyon)
#### Post date: [July 29, 2022, 10:11am UTC](https://discuss.openedx.org/t/api-enrol-user-in-a-course/7840/8 "2022-07-29T10:11:46Z")

</div>

I have finally figured out what the problem was…

it is related to bitnami edx configuration of apache 2 - by adding this  
WSGIPassAuthorization On

to the end of the httpd.conf, it solved the issue of authorization…
