How to create course using API?

I have redered /api-docs but seems there is no api for creating course. How can I create course using API via postman?

Hi @bhumi,

There is a simple technique you can use to answer such questions:

  1. Go to the Studio home page and click “New Course”
  2. Right-click anywhere on the page and click “Inspect” or the equivalent in your browser
  3. Go to the “Network” tab. Clear any entries currently there and enable “Preserve Log”
  4. Fill out the New Course form and hit Create.
  5. Check the Network log to see the request:
POST /course/
{org: "OpenCraftX", number: "TEST", display_name: "A Test Course", run: "101"}

^ That is the API you can use to create a course.

1 Like

@braden Api is giving me “CSRF verification failed. Request aborted.” error while calling from postman

I have passed X-CSRFToken:{{csrftoken}} in header and this line in tests section of postman

var xsrfCookie = postman.getResponseCookie(“csrftoken”); postman.setEnvironmentVariable(‘csrftoken’, xsrfCookie.value);

still getting same error

Did you generate the CSRF token using the same credentials (e.g. OAuth bearer token or JWT) that you’re using to authenticate the request? Try using the /csrf/api/v1/token API endpoint to retrieve the CSRF token, then submit it with X-CSRFToken.

I have taken csrf toekn from browser cookie. I have called csrf/api/v1/token and it’s returning token but still getting 403 error

I have called

/csrf/api/v1/token without any payload and it’s returning

“csrfToken”: “”

I am passing this token in /couse api header like


but getting same error

@braden I have tried calling api using csrftoken from cookie and /course api is giving 200 status code but it’s not creating course inside the openedx

Are you checking for the course using the same user that created the course? What happens if you try creating the exact same course twice?

Basically, I suspect that it’s working but you’re not seeing the course due to permissions or something.

I am getting 200 status only so not getting if it is creating course or not. How can I fix the issue? Which permission I need to set? Also, response is html content. It’s not giving created course id

Are you setting the Accept: application/json header? Because that is required. This endpoint is shared by both HTML and JSON responses. See the code here for details.

Yes, I have set application/json in content-type header

Hi @bhumi ,

Did you find the solution, I am facing the same issue in postman.
CSRF verification failed. Request aborted.
can you please share the solution.

I got this api and I tried this in postman
First I was getting csrf token failed
Then I hit csrf api and got csrf token and added in the header section with X-CSRFToken and it’s value
Now getting url not found

Issue has been resolved you can use another openedx studio api api/v1/course_runs/
It will create course for you in studio. All you have to pass authentication access token in oauth2.0

I’m trying to hit the api/v1/course_runs/ endpoint mentioned by [Daniyal_Farman]

I can generate a token using the csrf/api/v1/token but when I try to use it in Postman I get
“detail”: “Authentication credentials were not provided.”

Any clarification would be appreciated.

Any solution ? I am facing the same problem